Pixel Shading Help

Started by
8 comments, last by SiS-Shadowman 15 years, 8 months ago
Does anyone here know of a good beginner's article on how to use a Pixel Shader to render Fog of War for a 2D tile based game. Thanks in advance.
Advertisement
What kind of effect are you actually trying to achieve? Is this something done in the mini-map? Depending on the effect you're going for, you may be able to simply use transparent textures as overlays. If you go the pixel shader approach, a post-processor effect could be done that simply blends the screen color with black.

If you have a clearer understanding of the effect you want to achieve, it will be easier to answer the question.
This is done in the main map itself. I have player units that I would like to move around the map. When the unit enters a tile, then the tiles within their radius would become visible and the Shader would be used to render the tile visible.
I'd second the post process effect. It's much easier to do what you want.

Imagine a couple of your units. What you want, it that everything in their volume is rendered as normal and everything, that is not in their viewing volume, should be rendered in another way (grayed out, totally black).

All you need to do, is render spheres to another render target (set the background to black, make the spheres white). Then, in another post process pass, you access both this currently rendered texture, and the final scene and multiply both textures:

Is there a tutorial on how to implement the Post Processor effect on a 2D surface? I've seen some online which focus on 3D meshes, but I have no idea what many of the variables do. (ex TEXCOORD and TEXCOORD0)
If you're using D3D, things are very easy. Browse your SDK folder, looking for the PostProcess Sample (DirectX SDK (June 2007)\Samples\C++\Direct3D\PostProcess). If you've still got problems or questions, just ask.

If you're using OpenGL though, I can't help you, maybe you can find something with google ;)
After figuring out most of the stuff needed, I am having trouble figuring out how to pass in multiple textures. For now I'm trying to get everything to become visible within my mouse cursor. All that does is either make everything really black or really white.
So, what do you actually do? You need to render the entire scene into one texture (we'll call it the scenetex). Then you setup another rendertarget, the visibletex. There you render your primitives (spheres) for example toally white.

After this is done, you restore the original backbuffer and pass both textures to the shader, the scenetex and the visibletex. There you just do:
float4 PS( float2 Tex0 ) : COLOR{    return tex2D( SceneSampler, Tex0 ) * tex2D( VisibleSampler, Tex0 );}
Thanks for that line of code. It helped me get the screen dark around the top and light around the bottom. Now I would like it to be light whenever the mouse goes over certain areas of the screen.
Could you please post the code you used to draw the primitives white? And ofcourse the code where you switch render targets etc..
I might be of more help then :)

This topic is closed to new replies.

Advertisement