shader support!!
This commit is contained in:
parent
004a72d5a7
commit
8d35593070
|
@ -1,6 +1,7 @@
|
|||
<ActorFrame InitCommand="%oat._actor.initFrame">
|
||||
<children>
|
||||
<Layer Condition="oat._actor.cond()" Type="@oat._actor.type()" File="@oat._actor.file()" Font="@oat._actor.font()" InitCommand="%oat._actor.init"/>
|
||||
<Layer Condition="oat._actor.noShader()" Type="@oat._actor.type()" File="@oat._actor.file()" Font="@oat._actor.font()" InitCommand="%oat._actor.init"/>
|
||||
<Layer Condition="oat._actor.hasShader()" Type="@oat._actor.type()" File="@oat._actor.file()" Font="@oat._actor.font()" Frag="@oat._actor.frag()" Vert="@oat._actor.vert()" InitCommand="%oat._actor.init"/>
|
||||
<Layer Condition="oat._actor.next()" File="actors.xml" />
|
||||
</children>
|
||||
</ActorFrame>
|
53
main.xml
53
main.xml
|
@ -285,6 +285,14 @@
|
|||
return currentActor ~= nil
|
||||
end
|
||||
|
||||
function oat._actor.hasShader()
|
||||
return oat._actor.cond() and (currentActor.frag ~= nil or currentActor.vert ~= nil)
|
||||
end
|
||||
|
||||
function oat._actor.noShader()
|
||||
return oat._actor.cond() and not oat._actor.hasShader()
|
||||
end
|
||||
|
||||
function oat._actor.type()
|
||||
return currentActor.type
|
||||
end
|
||||
|
@ -293,6 +301,14 @@
|
|||
return currentActor.file
|
||||
end
|
||||
|
||||
function oat._actor.frag()
|
||||
return currentActor.frag or 'nop.frag'
|
||||
end
|
||||
|
||||
function oat._actor.vert()
|
||||
return currentActor.vert or 'nop.vert'
|
||||
end
|
||||
|
||||
function oat._actor.font()
|
||||
return currentActor.font
|
||||
end
|
||||
|
@ -423,6 +439,43 @@
|
|||
return actor
|
||||
end
|
||||
|
||||
local function isShaderCode(str)
|
||||
return string.find(str or '', '\n')
|
||||
end
|
||||
|
||||
function Shader(frag, vert)
|
||||
if actorsInitialized then error('uranium: cannot create an actor during runtime!!', 2) end
|
||||
local actor = createProxyActor('RageShaderProgram')
|
||||
|
||||
local fragFile = frag
|
||||
local vertFile = vert
|
||||
|
||||
local isFragShaderCode = isShaderCode(frag)
|
||||
local isVertShaderCode = isShaderCode(vert)
|
||||
|
||||
if isFragShaderCode then fragFile = nil end
|
||||
if isVertShaderCode then vertFile = nil end
|
||||
|
||||
if (frag and vert) and ((isFragShaderCode and not isVertShaderCode) or (not isFragShaderCode and isVertShaderCode)) then
|
||||
error('uranium: cannot create a shader with 1 shader file and 1 shader code block', 2)
|
||||
end
|
||||
|
||||
table.insert(actorQueue, {
|
||||
type = 'Sprite',
|
||||
frag = fragFile and ('../' .. fragFile) or 'nop.frag',
|
||||
vert = vertFile and ('../' .. vertFile) or 'nop.vert',
|
||||
init = function(a)
|
||||
actor.__lock(a:GetShader())
|
||||
|
||||
-- shader code stuff
|
||||
if isFragShaderCode or isVertShaderCode then
|
||||
a:GetShader():compile(vert or '', frag or '')
|
||||
end
|
||||
end
|
||||
})
|
||||
return actor
|
||||
end
|
||||
|
||||
function Model(file)
|
||||
if actorsInitialized then error('uranium: cannot create an actor during runtime!!', 2) end
|
||||
if not file then error('uranium: cannot create a Model without a file', 2) end
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
#version 120
|
||||
|
||||
uniform sampler2D sampler0;
|
||||
varying vec2 textureCoord;
|
||||
varying vec4 color;
|
||||
|
||||
void main (void) {
|
||||
gl_FragColor = texture2D( sampler0, textureCoord ) * color;
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
#version 120
|
||||
|
||||
attribute vec4 TextureMatrixScale;
|
||||
varying vec3 position;
|
||||
varying vec3 normal;
|
||||
varying vec4 color;
|
||||
varying vec2 textureCoord;
|
||||
varying vec2 imageCoord;
|
||||
uniform vec2 textureSize;
|
||||
uniform vec2 imageSize;
|
||||
uniform mat4 textureMatrix;
|
||||
void main() {
|
||||
normal = gl_NormalMatrix * gl_Normal * vec3(1.0, -1.0, 1.0);
|
||||
gl_Position = (gl_ModelViewProjectionMatrix * gl_Vertex);
|
||||
position = gl_Vertex.xyz;
|
||||
gl_TexCoord[0] = (textureMatrix * gl_MultiTexCoord0 * TextureMatrixScale) + (gl_MultiTexCoord0 * (vec4(1)-TextureMatrixScale));
|
||||
textureCoord = ((textureMatrix * gl_MultiTexCoord0 * TextureMatrixScale) + (gl_MultiTexCoord0 * (vec4(1)-TextureMatrixScale))).xy;
|
||||
imageCoord = textureCoord * textureSize / imageSize;
|
||||
gl_FrontColor = gl_Color;
|
||||
color = gl_Color;
|
||||
}
|
|
@ -41,6 +41,11 @@ function ActorSound(file) end
|
|||
---@return ActorFrameTexture
|
||||
--- Defines an ActorFrameTexture actor.
|
||||
function ActorFrameTexture() end
|
||||
---@param frag string | nil
|
||||
---@param vert string | nil
|
||||
---@return RageShaderProgram
|
||||
--- Defines a shader. `frag` and `vert` can either be filenames or shader code.
|
||||
function Shader(frag, vert) end
|
||||
|
||||
---@param actor Actor
|
||||
--- Resets an actor to its initial state
|
||||
|
|
Loading…
Reference in New Issue