Sign in to follow this  
JoshuaWaring

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

Recommended Posts

JoshuaWaring    1359

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();
	}
}

 

Edited by Joshhua5

Share this post


Link to post
Share on other sites
ajmiles    3305

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).

Edited by ajmiles

Share this post


Link to post
Share on other sites
JoshuaWaring    1359

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.

Edited by Joshhua5

Share this post


Link to post
Share on other sites
phil_t    8084

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

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