Passing an extra value to vertex shader

I’m trying to pass an extra float to my vertex shader because I need to divide my UV by some value I calculate in order to do projective correct texturing.

The batcher I am using is a modified version of the nez batcher. However after modifying the struct nothing renders, and no errors are thrown.

This is my struct after modifying.

 [StructLayout(LayoutKind.Sequential, Pack = 1)]
        struct VertexPositionColorTexture4 : IVertexType
            //public const int realStride = 96;
            // public const int realStride = 0;
            public const int realStride = 112;

            VertexDeclaration IVertexType.VertexDeclaration { get { throw new NotImplementedException(); } }

            public Vector3 position0;
            public Color color0;
            public Vector2 textureCoordinate0;
            public float q0;
            public Vector3 position1;
            public Color color1;
            public Vector2 textureCoordinate1;
            public float q1;
            public Vector3 position2;
            public Color color2;
            public Vector2 textureCoordinate2;
            public float q2;
            public Vector3 position3;
            public Color color3;
            public Vector2 textureCoordinate3;
            public float q3;

I don’t actually do anything currently with the extra value so I don’t think the issue is in the shader. Is there anywhere else I need to modify in order to do this?

Why mod the vertex structure when you can just pass a variable to the shader, or do you need to make different changes to the UV per vertex?

That does not look like a full vertex definition either…

Yeah it has a different value per vertex. It’s to correct the UV when the quad is not a parallelogram.

I worked it out in the end. When creating the vertex buffer I was still telling it to expect a float2. Had to create a new structure with float3s and pass that into the constructor.

_vertexBuffer = new DynamicVertexBuffer(graphicsDevice, typeof(P3.VertexPositionColorTexture), MAX_VERTICES, BufferUsage.WriteOnly);

1 Like

Ahh right, bet it was getting confused when Vertex Patching :slight_smile: