MonoGame/MonoGame

Can't set an effect's parameter with type Vector2[] due to ArgumentException

rds1983 opened this issue · 3 comments

Prerequisites

  • I have verified this issue is not present in the develop branch
  • I have searched open and closed issues to ensure it has not already been reported.

MonoGame Version

MonoGame 3.8.1.303

Which MonoGame platform are you using?

MonoGame Cross-Platform Desktop Application (mgdesktopgl)

Operating System

Windows

Description

Can't set parameter with type Vector2[] due to ArgumentException.
See attached sample.
It has very simple effect that has parameter of type Vector2[23].
The effect was compiled with the following command: mgfxc "TestEffect.fx" "TestEffect.mgogl" /Profile:OpenGL
The application fails when calling _effect.CurrentTechnique.Passes[0].Apply(); with exception:
image

The bug reproduces on both 3.8.1.303 and the develop branch.

Steps to Reproduce

  1. Open attached sample(VFaceTest.MonoGameOGL.sln) in the IDE.
  2. Compile and run.
  3. Observe the exception.

Minimal Example Repo

No response

Expected Behavior

There shouldn't be an exception.

Resulting Behavior

System.ArgumentException: '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.'

Images

VFaceTest3.zip

You cannot pass a parameter larger than a Matrix4x4(16 elements) with the fx compiler.

Your Vector2[23] (46 elements) would need to be split into 4 Matrix4x4 parameters and adapted to accordingly in the shader.


Your other option is to create a texture with the desired values(due to interpolation effects double each pixel horizontally) and use a sampler to get the value, UV = (index * 2 + 1)/23,1

This is how I implement my indexed color shader.

hmm, it would be great then, if mgfx generated an error when trying to compile .fx with a parameter larger than Matrix4x4

I was incorrect in my previous statement.

The produced GL code did split it into 23 single elements:

uniform vec4 ps_uniforms_vec4[23];
//...
#define ps_c0 ps_uniforms_vec4[0]
//...
#define ps_c22 ps_uniforms_vec4[22]

I am sure that you can spot the issue.

Your original type was Vector2 the compiled type is Vector4.

You can change the source data to Vector4, using only the XY components.

Or pack the data into 12 Vector4's and change the source fx shader to match.