Nointerpolation variable syntax for opengl cross platform

Hello game developers,

Hi was trying to make a map with triangles having only one color (image of the effect I want at the end of the post).
I decided to use to use indices to not use a lot of vertices, so I need the triangles to not interpolate the colors in the shader to have flat colors for each triangles.
So I found that in HLSL I can use the nointerpolation syntax on the color at the vertex shader output to create that effect. The problem is it looks like to be ignored because the color is still being interpolated.

Someone on the discord suggest that was because I use monogame cross platform with opengl and the translation between HLSL and GLSL opengl projects are “not fit for advanced rendering and shaders”. Wich is really weird because OpenGL as the “flat” keyword to not interpolate values between the vertex and pixel shader.

So my question: is it really a monogame limitation, or there is something I didn’t saw?

Here is my shader code:

#if OPENGL
	#define SV_POSITION POSITION
	#define VS_SHADERMODEL vs_3_0
	#define PS_SHADERMODEL ps_3_0
#else
	#define VS_SHADERMODEL vs_4_0_level_9_1
	#define PS_SHADERMODEL ps_4_0_level_9_1
#endif

matrix WorldViewProjection;

struct VertexShaderInput
{
	float4 Position : POSITION0;
	float4 Color : COLOR0;
};

struct VertexShaderOutput
{
	float4 Position : SV_POSITION;
	nointerpolation float4 Color : COLOR0;
};

VertexShaderOutput MainVS(in VertexShaderInput input)
{
	VertexShaderOutput output = (VertexShaderOutput)0;
	output.Position = mul(input.Position, WorldViewProjection);
	output.Color = input.Color;
	return output;
}

float4 MainPS(VertexShaderOutput input) : COLOR
{
	float4 output = input.Color;
	return output;
}

technique BasicColorDrawing
{
	pass P0
	{
		VertexShader = compile VS_SHADERMODEL MainVS();
		PixelShader = compile PS_SHADERMODEL MainPS();
	}
};

And the image shows the interpolation despite the nointerpolation keyword

image

And here is the effect I want
image

You would likely have to stick to WindowsDX for this to work as intended. Or rework your shader/pipeline to workaround that.

On DesktopGL, nointerpolation indeed is lost in translation because the shader converter used (mojoshader) doesn’t support it. nointerpolation is a SM 4 feature and mojoshader can’t go past SM 3.

1 Like

Called it… also as I’ve mentioned you can grab Compute fork which is using shaderconductor and it should work just fine (as most of the SM4.0 - 5.0 features).

1 Like

Replacing mojoshader at some point indeed is the way to go.

2 Likes