Sign in to follow this  
lonewolff

How do you pass a float to a shader program?

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this