Hello, I’m joining the Monogame community, and I’m having a problem trying to use the pixel position on the screen to make a rounded cutout.
Sprite Effect template:
#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
Texture2D SpriteTexture;
sampler2D SpriteTextureSampler = sampler_state
{
Texture = <SpriteTexture>;
};
struct VertexShaderOutput
{
float4 Position : SV_POSITION;
float4 Color : COLOR0;
float2 TextureCoordinates : TEXCOORD0;
};
float4 MainPS(VertexShaderOutput input) : COLOR
{
return tex2D(SpriteTextureSampler,input.TextureCoordinates) * input.Color;
}
technique SpriteDrawing
{
pass P0
{
PixelShader = compile PS_SHADERMODEL MainPS();
}
};
this shader compiles without any problem, but if I use input.Position to check the pixel position on the screen, a compilation error is thrown.
float4 MainPS(VertexShaderOutput input) : COLOR
{
if (input.Position.x > 500.0){
discard;
}
return tex2D(SpriteTextureSampler,input.TextureCoordinates) * input.Color;
}
Compilation error using mgwindowsdx:
Error MSB3073, without additional information
Compilation error using mgdesktopgl or mgandroid:
Error X4502 : invalid ps_3_0 input semantic ‘POSITION’
Error X4502 : invalid input semantic ‘POSITION’: Legal indices are in [1,15]
Error X4502 : invalid ps_3_0 input semantic ‘POSITION’
Usage in dotnet 7.0 + mglib
_spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend,null,null,null,_effect);
where _effect
is the Effect imported using Content.mgcb
Any information is welcome, thanks in advance