Simple pixel shader problem (HLSL)

Started by
0 comments, last by timmay314 19 years, 10 months ago
I just started messing with shaders today using HLSL, trying to get it to work in RenderMonkey. I''m having a very strange problem with a very simple pixel shader where I just try to swap the red and green components. It won''t compile, I get the following error message: COMPILE ERROR: API(D3D) /../Default DirectX Effect/Single Pass/Pixel Shader/ (3): error X5036: Read of uninitialized component(*) in r1: r/0 g/1 b/2 *a/3 Here''s my code

float sin_time_0_X;
sampler Texture0;

float4 ps_main( float4 inDiffuse: COLOR0, float2 inTex : TEXCOORD0) : COLOR0
{
   float4 color = tex2D(Texture0, inTex); // this line is the problem
   float red = color.r;
   color.r = color.g;
   color.g = red;

   return color;
}
 
However, if I just do this it works fine, even though the line that is giving me the error is unchanged:

float4 ps_main( float4 inDiffuse: COLOR0, float2 inTex : TEXCOORD0) : COLOR0
{
   float4 color = tex2D(Texture0, inTex);

   return color;
}
 
It seems to think that color.r is fine but color.g, b, or a has not been given a value. What''s wrong with this?
Advertisement
return color.grba; ?


Perl - Made by Idiots, Java - Made for Idiots, C++ - Envied by Idiots
http://sunray.cplusplus.se - http://cplusplus.se
[size="1"]Perl - Made by Idiots, Java - Made for Idiots, C++ - Envied by Idiots | http://sunray.cplusplus.se

This topic is closed to new replies.

Advertisement