Quantcast
Channel: Community | MonoGame - Latest topics
Viewing all articles
Browse latest Browse all 6821

Monogame effect outputting nothing after adding vertex shader

$
0
0

@NBenassou wrote:

I'm using Monogame 3.6 and dove into shaders today. I can't find much documentation for Monogaeme effects. All the XNA ones don't work. Even slightly older Monogame examples don't do what you'd expect.

This is for a 2d game.

So I started today with trying to follow this tutorial: http://joshuasmyth.maglevstudios.com/post/Introduction-to-Pixel-Shaders-with-XNA-and-Monogame-Part2-Sepia-Desaturation-Scanlines-and-other-Techniques2. I got stuck at the scanline part. After awhile I discovered it was because of the input.position. Because I was using ps_4_0_level_9_1 I couldn't access the position directly for some reason. On the Monogame forum I found that you had to pass the position separately from the vertex shader. So I tried adding the vertex shader. After a while, I found an answer here on this forum. This should be a basic effect with texture coordinates (which you don't get if you just make an effect through Monogame contentPipeline. If you make a new Monogame SpriteEffect you don't get a vertex shader.):

#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;
sampler2D TextureSampler: register(s0); // added

struct VertexShaderInput
{
    float4 Position : SV_POSITION;
    float4 Color : COLOR0;
    float2 TexCoords: TEXCOORD0; // added
};

struct VertexShaderOutput
{
    float4 Position : SV_POSITION;
    float4 Color : COLOR0;
    float2 TexCoords: TEXCOORD0; // added
}; 

VertexShaderOutput MainVS(in VertexShaderInput input)
{
    VertexShaderOutput output = (VertexShaderOutput)0;

    output.Position = mul(input.Position, WorldViewProjection);
    output.Color = input.Color;
    output.TexCoords = input.TexCoords; // added

    return output;
}

float4 MainPS(VertexShaderOutput input) : COLOR
{
    return tex2D(TextureSampler, input.TexCoords);
}

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

This doesn't output anything at all. Even if I replace the return tex2D(TextureSampler, input.TexCoords); with return float4(1.0f,0.0f,0.0f,1.0f); I still get nothing whatsoever.

Questions:

  • What is wrong with my shader?

  • What is the difference between a Sprite Effect and an Effect?

  • Is there anyplace where I can get documentation about modern Monogame effects?

Posts: 4

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 6821

Trending Articles