Game Development Community

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

#1
07/21/2009 (10:39 am)
Take a look at the PostEffect code. There's an easy to spot section where it sets a whole bunch of shader parameters and is a good example.
#2
07/21/2009 (12:24 pm)
Thanks, I'm still struggling as to how these parameters are referenced from within a shader?
#3
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
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.