Passing a float to a shader
by Ian Omroth Hardingham · in Torque 3D Professional · 07/21/2009 (6:46 am) · 4 replies
Hey guys.
I'm trying to pass a float into a shader. I'm binding the shader in c++ and then drawing a quad. Could anyone just quickly tell me what call I should be looking at, and exactly how to reference it within the shader? I know this is kind of a noob question, but it seems like something which should be very straight forward.
Ian
I'm trying to pass a float into a shader. I'm binding the shader in c++ and then drawing a quad. Could anyone just quickly tell me what call I should be looking at, and exactly how to reference it within the shader? I know this is kind of a noob question, but it seems like something which should be very straight forward.
Ian
About the author
Designer and lead programmer on Frozen Synapse, Frozen Endzone, and Determinance. Co-owner of Mode 7 Games.
#2
07/21/2009 (12:24 pm)
Thanks, I'm still struggling as to how these parameters are referenced from within a shader?
#3
For future reference:
The parameter is passed as at normal parameter to the shader and assigned a register:
This then allows it to return $pixelHeight to a handle. An interesting gotcha is that it won't return a handle until you reference pixelHeight somewhere in the shader function.
07/22/2009 (4:18 am)
Ok, figured it out.For future reference:
The parameter is passed as at normal parameter to the shader and assigned a register:
uniform float pixelHeight : register(C15)
This then allows it to return $pixelHeight to a handle. An interesting gotcha is that it won't return a handle until you reference pixelHeight somewhere in the shader function.
#4
And yea if the constant isn't used in the shader... the HLSL compiler will optimize it out... and it will not be a valid constant you can set.
07/23/2009 (2:26 pm)
First note you don't have to use the 'register' stuff anymore. The shader constant will automatically be assigned a register by the compiler, so all you do by specifiying your own is possibly cause a bug.And yea if the constant isn't used in the shader... the HLSL compiler will optimize it out... and it will not be a valid constant you can set.
Associate Manoel Neto
Default Studio Name