Hey, I got a very simple problem.
I want to change a float inside a shader function and send it back to the main program
The shader looks like this
float size; // THE VARIABLE...
float4 PS_COLOR(float2 texCoord: TEXCOORD0) : COLOR
{
size = 3.0f; // AFTER THIS CALL IT SHOULD RETURN 3 IN THE MAIN PROGRAM
return 1.0f;
}
technique LangweiligerShader
{
pass pass0
{
PixelShader = compile ps_2_0 PS_COLOR();
}
}
in my main function, I set the size variable like this:
effect.SetValue(EffectHandle.FromString("size"), 1000f);
Then I call the Draw method, which applies the shader (its loaded correctly and works since the drawn texture is white)
And after that I get the size variable with
effect.GetValueFloat(EffectHandle.FromString("size"))
Here is the problem… The variable is 1000, but it should be 3
any suggestions?
I do not think that what you are trying is possible. The Pixel shader is called for every pixel in the output screen area. So the variable would be set many times each frame. If the variable depends on a calculation within the pixel shader function, many differen results would be written.
If you want to use the GPU for calculations that return values of some kind, I suggest you look into some framwork like CUDA or OpenCL.