@GeonBit wrote:
For a simple lighting shader I have the following input and output structs:
// vertex shader input struct VertexShaderInput { float4 Position : POSITION0; float4 Normal : NORMAL0; float2 TextureCoordinate : TEXCOORD0; }; // vertex shader output struct VertexShaderOutput { float4 Position : SV_POSITION; float3 Normal : TEXCOORD0; float2 TextureCoordinate : TEXCOORD1; float3 WorldPos : TEXCOORD2; };
If I do the following in my vertex shader:
// main vertex shader for flat lighting VertexShaderOutput FlatLightingMainVS(in VertexShaderInput input) { VertexShaderOutput output; output.Position = mul(input.Position, WorldViewProjection); output.WorldPos = mul(input.Position, World); output.Normal = input.Normal; output.TextureCoordinate = input.TextureCoordinate; return output; }
I get the following error while calling Draw():
An unhandled exception of type 'System.ArgumentException' occurred in MonoGame.Framework.dll Additional information: Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.
The problem seems to be from
output.WorldPos = mul(input.Position, World);
, and if I do the following instead:// main vertex shader for flat lighting VertexShaderOutput FlatLightingMainVS(in VertexShaderInput input) { VertexShaderOutput output; output.Position = mul(input.Position, WorldViewProjection); output.WorldPos = input.Position; // <-- DIFF HERE output.Normal = input.Normal; output.TextureCoordinate = input.TextureCoordinate; return output; }
and then in pixel shader multiply with world matrix:
float3 position = mul(input.WorldPos, World);
There is no error (although position seems to be wrong, but I will handle it later).
Can anyone explain the error in the first way please, eg calculating in vertex shader? Is this a bug with MonoGame?
Thanks,
Posts: 2
Participants: 1