This project is read-only.

Error in shader during run time

Aug 7, 2009 at 4:13 PM


Every time i try to bind this shader to a sphere of mine, it generates an error:

Cannot use shader of type 'Shaders.TestShader.RenderWithPixelShader' with Vertices object as it does not include element 'Color0'

On init:

shader = new Shaders.TestShader.RenderWithPixelShader();
shader.LightPosition = Vector3.Zero;
shader.TextureDiffuse0 = textureMap;

In draw phase:

var provider = new ModelInstanceShaderProvider(shader);

Here is the shader:

I just cannot figure out what im doing wrong here :S.

Many thanks in advance!

Aug 7, 2009 at 6:39 PM

Do you use your own model or the Xen.Ex.Geometry.Sphere class?

Aug 7, 2009 at 7:07 PM

I am using my own model to render the sphere (ModelInstance) as i have no idea how to do this using the internal sphere class.

Aug 7, 2009 at 10:57 PM

What if you try using:

struct VsOutput
        float4 Color: COLOR0;
        float4 Position: POSITION;
        float2 TexCoord0: TEXCOORD0;
        float3 Light: TEXCOORD1;
        float3 View: TEXCOORD2;
        float3 DirToPosition: TEXCOORD3;


in your shader code instead of what you currently have (notice that I simply added a 0 to your Color variable ;) )

Aug 7, 2009 at 11:34 PM

Thank you for the replies "philippedasilva".

I have tried what you have said, but nothing seems to work. I even tried to modify the output structure of RenderSceneAdvancedPS, but that also didn't work.

I just keep getting the same error over and over again :P.

Aug 8, 2009 at 1:48 AM

I don't know if that is the case but I noticed that none of my shaders that used a structure inside the shader code wasn't taken into account with Xen ShaderTool.

Maybe if you put your structure variables directly in the vertex method using the out keyword it will work better so that it looks more like:

void RenderSceneAdvancedVS(
        float4 inputColor0:COLOR,
        float3 inputPosition:POSITION,
        float3 inputNormal:NORMAL,
        float2 inputTexCoord:TEXCOORD0
        out float4 Color: COLOR0;
        out float4 Position: POSITION;
        out float2 TexCoord0: TEXCOORD0;
        out float3 Light: TEXCOORD1;
        out float3 View: TEXCOORD2;
        out float3 DirToPosition: TEXCOORD3 )
        Position = mul( float4( inputPosition, 1.0f ), viewProjection );
        TexCoord0 = inputTexCoord;    
        Light = normalize( lightPosition - inputPosition );
        View = normalize( -inputPosition );
        Color = inputColor0;
        DirToPosition = normalize( inputPosition - float3( world._m30, world._m31, world._m32 ) );

Aug 10, 2009 at 4:35 AM
Edited Aug 10, 2009 at 4:36 AM

The error you are getting is saying 'the vertex shader is accessing Color0 - which it is, but the vertex data doesn't have Color0.' It's nothing to do with the layout of the shader, it simply means your model doesn't have any colour information stored in it's vertices. So no mater what you do to the shader, you won't be able to read information that isn't there.
Also, there is no difference between Color and Color0, as the default index is zero.