Painting with pixel shaders
Posted
by
Gustavo Maciel
on Game Development
See other posts from Game Development
or by Gustavo Maciel
Published on 2012-09-26T21:35:56Z
Indexed on
2012/09/26
21:50 UTC
Read the original article
Hit count: 330
I have an almost full understanding of how 2D Lighting works, saw this post and was tempted to try implementing this in HLSL.
I planned to paint each of the layers with shaders, and then, combine them just drawing one on top of another, or just pass the 3 textures to the shader and getting a better way to combine them.
Working almost as planned, but I got a little question in the matter.
I'm drawing each layer this way:
GraphicsDevice.SetRenderTarget(lighting);
GraphicsDevice.Clear(Color.Transparent);
//... Setup shader
SpriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend,
SamplerState.LinearClamp, DepthStencilState.None, RasterizerState.CullNone, lightingShader);
SpriteBatch.Draw(texture, fullscreen, Color.White);
SpriteBatch.End();
GraphicsDevice.SetRenderTarget(darkMask);
GraphicsDevice.Clear(Color.Transparent);
//... Setup shader
SpriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend,
SamplerState.LinearClamp, DepthStencilState.None, RasterizerState.CullNone, darkMaskShader);
SpriteBatch.Draw(texture, fullscreen, Color.White);
SpriteBatch.End();
Where lightingShader
and darkMaskShader
are shaders that, with parameters (view and proj matrices, light pos, color and range, etc) generate a texture meant to be that layer.
It works fine, but I'm not sure if drawing a transparent quad on top of a transparent render target is the best way of doing it. Because I actually just need the position and params.
Concluding: Can I paint a texture with shaders without having to clear it and then draw a transparent texture on top of it?
© Game Development or respective owner