Question

I think I am very stupid because I can't figure out what causes the issue in this simplest case.

Project type is Windows OpenGL (on Android the issue also persists).

Here is the shader:

//----------------------------------------------------------------------------
float4 PSTest (float2 TexCoords : TEXCOORD0) : COLOR0
{
    float4 color =  float4 (1, 0, 0, 1);

    return color;
}

//----------------------------------------------------------------------------
Technique Test
{
    pass Test
    {
        PixelShader = compile ps_2_0 PSTest();
    }
}   

It works fine if I draw it to the screen with the Texture (128x128):

        Shader.CurrentTechnique = Shader.Techniques["Test"];
        GraphicsDevice.SetRenderTarget (null);
        GraphicsDevice.Clear (Color.White);

            Batch.Begin (SpriteSortMode.Immediate, BlendState.Opaque,   
               SamplerState.PointClamp, DepthStencilState.None, null, Shader);
            Batch.Draw (Texture, Vector2.Zero, Color.White);
            Batch.End();

Image

Now I decide to draw it into render target Output created by code:

new RenderTarget2D (GraphicsDevice, 256, 256, false, 
   SurfaceFormat.Color, DepthFormat.None);

Draw code:

        // Render into Output
        Shader.CurrentTechnique = Shader.Techniques["Test"];
        GraphicsDevice.SetRenderTarget (Output);
        GraphicsDevice.Clear (Color.DimGray);

        Batch.Begin (SpriteSortMode.Immediate, BlendState.Opaque,
           SamplerState.PointClamp, DepthStencilState.None, null, Shader);
        Batch.Draw (Texture, Vector2.Zero, Color.White);
        Batch.End();

        // Draw Output
        GraphicsDevice.SetRenderTarget (null);
        GraphicsDevice.Clear (Color.White);

        Batch.Begin();
        Batch.Draw (Output, Vector2.Zero, Color.White);
        Batch.End();

But the result is totally absurd:

Image

I have tried different simplest shaders, SurfaceFormat.HdrBlendable, texture sizes - but nothing helps.

Also I have tried to draw Texture (filled with violet) into render target without shader (then to the screen) and it works fine.

Image

It seems like I have missed some basics thing about shaders in XNA but I can't figure out what it is.

Was it helpful?

Solution

Here is the solution: https://monogame.codeplex.com/discussions/530086. The reason is in the shader's input parameters.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top