XNA Shader isn't working with Error X3502 #SOLVED#

Started by
3 comments, last by phil_t 10 years, 9 months ago

This is my first shader ever, so please bear with me if you see something completely off, but firstly I have to ask is what do the : COLOR0 ect do, why are they there. I know the error has something to do with them, but here's the shader. Thank you for any help possible :3

I have a new problem now , nothing appears to anything that's rendered after the apply of either technique, but no errors are displayed.

How I'm using the shader is here and the shader below it


GraphicsDevice.Clear(Color.DarkGray);
spriteBatch.Begin( SpriteSortMode.Immediate,BlendState.AlphaBlend);

textures.ButtonFX.CurrentTechnique = textures.ButtonFX.Techniques["ShimmerTech"];
textures.ButtonFX.CurrentTechnique.Passes[0].Apply();

spriteBatch.Draw(textures.Button, btnPlayPos, Color.White);

textures.ButtonFX.CurrentTechnique = textures.ButtonFX.Techniques["NormalTech"]; 
textures.ButtonFX.CurrentTechnique.Passes[0].Apply();

spriteBatch.Draw(textures.Button, btnUpgradePos, Color.White);
spriteBatch.Draw(textures.Button, btnQuitPos, Color.White);


spriteBatch.End();      


struct VertexShaderInput
{
    float4 Position : POSITION0;
	float4 Color : COLOR0; 
}; 

struct VertexShaderOutput
{
    float4 Position : POSITION0;
	float4 Color : COLOR0;  
};

VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{
    VertexShaderOutput output; 
	output.Position = input.Position;
	output.Color = input.Color;
    return output;
}

float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
{
    return input.Color;
}

float4 PixelShaderFunctionHigh(VertexShaderOutput input) : COLOR0
{
	return normalize(input.Color); 
}

technique NormalTech
{
    pass Pass0
    { 
        VertexShader = compile vs_2_0 VertexShaderFunction();
        PixelShader = compile ps_2_0 PixelShaderFunction();
	}  
} 

technique ShimmerTech
{
	pass Pass0
	{
		VertexShader = compile vs_2_0 VertexShaderFunction();
        PixelShader = compile ps_2_0 PixelShaderFunctionHigh();
	}
}

Advertisement

In future you can help us help you by telling us what the full text of the error is.

As it is, the VertexShaderFunction doesn't initialise the "VertexShaderOutput" structure before returning it, the contents are left undefined. Try:


VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{
    VertexShaderOutput output; 
    output.Position = input.Position;
    output.Color = input.Color;
    return output;
}

Also, COLOR0 has different meanings depending on where you use it. On an input to a vertex shader it means you want the vertex attribute from the vertex tagged with the Color semantic with index 0, this corresponds to your vertex declaration. On a pixel shader output it means "the result I'm returning should write to Render Target 0" (as opposed to any of the other 7 render targets that can also be set).

Adam Miles - Principal Software Development Engineer - Microsoft Xbox Advanced Technology Group

Thank you, that all makes sense.

I have a new problem now , nothing appears to anything that's rendered after the apply of either technique, but no errors are displayed.
I've updated the shader code and the thread.

SpriteBatch.Begin has an override that takes an Effect parameter. Use that instead of calling Apply() on the effect pass.

This topic is closed to new replies.

Advertisement