Setting a timer vertexshader constant?

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
cooljayman
Posts: 22
Joined: Wed Mar 05, 2008 8:25 am

Setting a timer vertexshader constant?

Post by cooljayman »

Im trying to set a Timer value as a vertexShader Constant, OnSetConstants:

Code: Select all

u32 currtime = device->getTimer()->getTime();

	   services->setVertexShaderConstant("Timer", reinterpret_cast<f32*>(&currtime), 1);
But the time going into the shader is not getting updated? What am I doing wrong?
FuzzYspo0N
Posts: 914
Joined: Fri Aug 03, 2007 12:43 pm
Location: South Africa
Contact:

Post by FuzzYspo0N »

My guess is you are passing a u32 into a f32 variable. this is quite interesting becuase a had this problem recently using animations where if i cast it to f32 and it was outside of the environment, it didnt get changed at all, because it kept getting truncated to 0

dont cast variables to and from without casting it before properly
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

I did have similar problems and it was also caused by casting.
Halifax
Posts: 1424
Joined: Sun Apr 29, 2007 10:40 pm
Location: $9D95

Post by Halifax »

Well this is just a simple problem of how you are casting. Here is what you are saying with this:

Code: Select all

reinterpret_cast<f32*>(&currtime)
Reference my pointer, then cast the u32* to an f32* so that it is instead accessed by 9 bytes (I forget how big floats are) instead of 4 bytes. When you cast between pointers it just changes the way in which they are accessed for when you do 'pointer++' etc. So casting u32* to u8* would mean that 'pointer++' would increment through the value 1 byte at a time instead of 4 bytes. So to correct this, you just need to change the order of operations:

Code: Select all

tempFloat = (f32)currtime;
... use &tempFloat ...
TheQuestion = 2B || !2B
Post Reply