So I managed to animate textures.
Mind you this was a test, but it was successful. I'll be making a set of dynamic functions for animating textures, hopefully similar to AnimateSprite.
For now you can test this and see how it's done. I haven't really commented on anything in the code yet but if there are any questions just ask. I'll be working on the full set of animation-functions instead of perfecting this example.
Please mind that the image I used to animate isn't really set up for it, it's uneven and everything but it works to show this off.
There's a light at the mouse-pointer just to prove that it's a 3d-plane and not a sprite
The entire project is included in a RAR, code is posted here if anyone is just curious.
rem AGK Application
rem by Tobias Sjögren
setDisplayAspect(1.0)
setSyncRate(60, 0)
global myShader = 1
LoadShader(myShader,"shader-animateduv-vertex.vs","shader-animateduv-pixel.ps")
global texture = 1
loadImage(texture, "texture.png")
createlightdirectional(1, 0, 0, 0, 255, 255, 255)
createLightPoint(1, 0, 0, -10, 500, 255, 255, 255)
global obj = 1
createObjectPlane(obj, 35, 50)
setObjectPosition(obj, 0, 0, 0)
setObjectImage(obj, texture, 0)
setObjectLightMode(obj, 1)
setObjectRotation(obj, 0, 0, 0)
setObjectTransparency( obj, 1)
SetObjectShader(obj, myShader)
setCameraPosition(1, 0, 0, -100)
setCameraRotation(1, 0, 0, 0)
global startuvX# = 0.0
global startuvY# = 0.0
global enduvX# = 1.0
global enduvY# = 1.0
// The number of frames of this sprite
global nrOfFrames = 3
global currentFrame = 1
// The coords to be used for each frame
dim frameCoord[nrOfFrames - 1] as float
for n = 0 to nrOfFrames - 1
frameCoord[n] = n * 0.3333
next n
global frameTimer# = 0.0
// init enduv#
enduvX# = 1.0 / nrOfFrames
rem A lilpissywilly Did It!
do
print(startuvX#)
print(enduvX#)
_animateTexture(0.2) // 0.2 seconds interval between frames
setlightPointPosition(1, getPointerX() - 50, 50 - getPointerY(), -10)
sync()
loop
function _animateTexture(frameSpeed# as float)
frameTimer# = frameTimer# + getFrameTime()
if frameTimer# > frameSpeed#
frameTimer# = 0.0000
inc currentFrame
if currentFrame > nrOfFrames then currentFrame = 1
startuvX# = frameCoord[currentFrame-1]
setShaderConstantByName(myShader, "startuv", startuvX#, startuvY#, 0, 0);
setShaderConstantByName(myShader, "enduv", enduvX#, enduvY#, 0, 0);
endif
endFunction
Vertex Shader:
attribute vec3 position;
attribute vec3 normal;
attribute vec2 uv;
varying vec2 uvVarying;
varying vec3 normalVarying;
varying vec3 posVarying;
uniform vec4 uvBounds0;
uniform vec4 enduv;
uniform vec4 startuv;
uniform mat4 agk_World;
uniform mat4 agk_ViewProj;
uniform mat3 agk_WorldNormal;
void main()
{
vec4 pos = agk_World * vec4(position,1);
gl_Position = agk_ViewProj * pos;
vec3 norm = agk_WorldNormal * normal;
posVarying = pos.xyz;
normalVarying = norm;
uvVarying = uv * enduv.xy + vec2(startuv.x, startuv.y);
}
Pixel Shader:
#ifdef GL_ES
#ifdef GL_FRAGMENT_PRECISION_HIGH
precision highp float;
#else
precision mediump float;
#endif
#endif
uniform sampler2D texture0;
varying vec2 uvVarying;
varying vec3 normalVarying;
varying vec3 posVarying;
uniform vec4 agk_PLightPos;
uniform vec4 agk_PLightColor;
uniform vec3 agk_DLightDir;
uniform vec4 agk_DLightColor;
uniform vec4 agk_ObjColor;
void main()
{
vec3 dir = agk_PLightPos.xyz - posVarying;
vec3 norm = normalize(normalVarying);
float atten = dot(dir,dir);
atten = clamp(agk_PLightPos.w/atten,0.0,1.0);
float intensity = dot(normalize(dir),norm);
intensity = clamp(intensity,0.0,1.0);
vec3 color = agk_PLightColor.rgb * intensity * atten;
color = color + clamp(dot(-agk_DLightDir,norm)*agk_DLightColor.rgb,0.2,1.0);
gl_FragColor = texture2D(texture0, uvVarying) * vec4(color,1) * agk_ObjColor;
}
Have fun

My hovercraft is full of eels