@Tim Will Hack
Here's a very simple demo of two ways of using a timer in a shader.
The first shader uses a variable "seconds" declared with the "Time" semantic in the shader:
// simple oscillation between red and blue
float seconds : Time;
float4 red = {1.0, 0.0, 0.0, 1.0};
float4 blue = {0.0, 0.0, 1.0, 1.0};
float4 PShader(float4 Colour : Color) : Color
{ Colour = lerp(red, blue, frac(seconds));
return Colour;
}
technique t0
{ pass p0
{ PixelShader = compile ps_2_0 PShader();
}
}
The second uses DBP to pass the value of "seconds" to the shader. You can use either method - the first is slightly simpler:
// simple oscillation between red and blue
// controlled by the application
float seconds = 0.0;
float4 red = {1.0, 0.0, 0.0, 1.0};
float4 blue = {0.0, 0.0, 1.0, 1.0};
float4 PShader(float4 Colour : Color) : Color
{ Colour = lerp(red, blue, frac(seconds));
return Colour;
}
technique t0
{ pass p0
{ PixelShader = compile ps_2_0 PShader();
}
}
The demo dba code I used was:
load effect "red to blue timed v1.fx", 1, 0
load effect "red to blue timed v2.fx", 2, 0
make object sphere 1, 100
position object 1, -110, 0, 0
set object effect 1, 1
make object sphere 2, 100
position object 2, 110, 0, 0
set object effect 2, 2
autocam off
position camera 0, 0, -300
point camera 0, 0, 0
repeat
set effect constant float 2, "seconds", timer()/1000.0
until spacekey()
end
I don't think you can assume the timer starts from zero in either method.
But you CAN initialise the timer with the second method if you change the loop to:
start = timer()
repeat
set effect constant float 2, "seconds", (timer() - start)/1000.0
until spacekey()
This will force the right hand object to start from red.
Hope this helps.