Jump to content
  • Advertisement
Sign in to follow this  
lonewolff

How do you pass a float to a shader program?

This topic is 2785 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi Guys,

I am new to shader programming (like 1 Hr new :) and I can't work out how to send a float value from C++ to my shader.

The shader itself is working fine. If I set the 'nTest' value manually from within the shader I can make my object lighter of darker. But, I cant seem to get a value over to the shader from my app.

I am trying to send the value over using the following lines.

D3DXHANDLE nTest=mFX->GetParameterByName(0,"nTest");
mFX->SetFloat(nTest,0.5f);


This is my shader;
uniform extern float4x4 gWVP;
uniform extern float fTest;

struct OutputVS
{
float4 posH : POSITION0;
};

OutputVS TransformVS(float3 posL : POSITION0)
{
OutputVS outVS = (OutputVS)0;
outVS.posH = mul(float4(posL, 1.0f), gWVP);
return outVS;
}

float4 TransformPS() : COLOR
{
float4 AmbientColor = float4(1.0f,1.0f,1.0f,1.0f);

return AmbientColor * fTest;
}

technique TransformTech
{
pass P0
{
vertexShader = compile vs_2_0 TransformVS();
pixelShader = compile ps_2_0 TransformPS();
FillMode = Wireframe;
}
}


Be gentle, I am a complete newcomer to shaders :)

Share this post


Link to post
Share on other sites
Advertisement
Oh man, silly mistake.

Thanks for your help, though. That was awesome of you to point that out.

Good to know I am on the right track, anyway :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!