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

2D HLSL Shader Screen Rotate Problem

$
0
0

@Michael_Jedd wrote:

Hi there mates, I'm rather new to HLSL and monogame. I'm following this tutorial, but the result isn't quite what I expected and I'm struggling to figure out why.

Game1.cs:
protected override void Draw(GameTime gameTime)
{
// Create a Light Mask to pass to the pixel shader
GraphicsDevice.SetRenderTarget(lightsTarget);
GraphicsDevice.Clear(Color.Black);
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive);
spriteBatch.Draw(lightMask, new Vector2(0, 0), Color.White);
spriteBatch.End();

        // Draw the main scene to the Render Target
        GraphicsDevice.SetRenderTarget(mainTarget);
        GraphicsDevice.Clear(Color.CornflowerBlue);
        spriteBatch.Begin();
        spriteBatch.Draw(surge, new Vector2(0, 0), Color.White);
        spriteBatch.End();

        // Draw the main scene with a pixel
        GraphicsDevice.SetRenderTarget(null);
        GraphicsDevice.Clear(Color.CornflowerBlue);
        spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);
        lightingEffect.Parameters["lightMask"].SetValue(lightsTarget);
        lightingEffect.CurrentTechnique.Passes[0].Apply();
        spriteBatch.Draw(mainTarget, Vector2.Zero, Color.White);
        spriteBatch.End();

        base.Draw(gameTime);
    }

LightEffect.fx:

sampler s0;      
texture lightMask;  
sampler lightSampler = sampler_state{Texture = (lightMask); AddressU = CLAMP; AddressV = CLAMP;};

      
float4 PixelShaderLight(float2 coords: TEXCOORD0) : COLOR0  
{  
    float4 color = tex2D(s0, coords);  
    float4 lightColor = tex2D(lightSampler, coords);  
    return color * lightColor;  
}  
          
technique Technique1  
{  
    pass Pass1  
    {  
        PixelShader = compile ps_4_0_level_9_1 PixelShaderLight();  
    }  
}

Resulting Screen:

Any guidance would be greatly appreciated!

Posts: 2

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 6821

Trending Articles