Skip to main content
GameDev.net gamedev.net
🔒 Locked

Simple pixel shader problem (HLSL)

Started by timmay314 Jun 1, 2004 at 7:53 PM 0 replies 800+ views
Original Post
timmay314
timmay314
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?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.