Sign in to follow this  
Fighter453

Pixel Shading Help

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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:

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites
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 ;)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 );
}

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this