• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Lleran

Fog as posteffect

5 posts in this topic

How can I make this using depth buffer and color buffer? I understand general idea, but I can't implement this well. Any ideas, glsl, cg, hlsl code?
0

Share this post


Link to post
Share on other sites
If you just want simple linear fog, render a fullscreen quad and sample the depth of each pixel and calculate the amount of fog you want to add. Then sample the color buffer and apply the fog to it.

[CODE]
Texture2D gDepthMap;
Texture2D gColorMap;

float4 PS(PS_IN pIn) : SV_Target
{
float depth = gDepthMap.Sample(gTrilinearSampler, pIn.texC);

float fog = //Calculate fog (between 0-1)

float color = gColorMap.Sample(gTrilinearSampler, pIn.texC);

return lerp(color, gFogColor, fog);
}
[/CODE]

If you want more advanced fog effects you can reconstruct world space position of each pixel using depth
2

Share this post


Link to post
Share on other sites
Thanks for reply. Yes I want to implement simple linear fog first. I know the general idea - I have implemented some posteffects before. My problem is in fog factor calculation. I used this formula f = (fogend – d)/(fogend – fogstart), but it doesn't work properly. My fragment shader code (Cg):

[CODE]
//-----------------------------------------------------------------------------
struct FS_INPUT
{
float4 Position : POSITION;
float2 TexCoord : TEXCOORD0;
};
//-----------------------------------------------------------------------------
float4 main(FS_INPUT IN,
uniform sampler2D ColorMap,
uniform sampler2D DepthMap,
uniform float4 fogColor,
uniform float fogStart,
uniform float fogEnd
) : COLOR
{
float4 fragmentColor = f4tex2D(ColorMap, IN.TexCoord);
float4 fragmentDepth = f4tex2D(DepthMap, IN.TexCoord);

float fogFactor = (fogEnd - length(fragmentDepth)) / (fogEnd - fogStart);
fogFactor = clamp(fogFactor, 0.0, 1.0);

return lerp(fragmentColor, fogColor, fogFactor);
}
[/CODE]
0

Share this post


Link to post
Share on other sites
[quote name='Lleran' timestamp='1329158574' post='4912681']
How can I make this using depth buffer and color buffer? I understand general idea, but I can't implement this well. Any ideas, glsl, cg, hlsl code?
[/quote]

One thing to remember when doing this is potential issues with alpha blended objects / particles / anything that does not write into depth. Plenty of ways of getting round it (alpha doing their own fogging, rendered after the full screen pass, dithered depth buffer (inferred lighting), etc.), but will require some thought of course.
0

Share this post


Link to post
Share on other sites
[quote]One thing to remember when doing this is potential issues with alpha blended objects / particles / anything that does not write into depth. Plenty of ways of getting round it (alpha doing their own fogging, rendered after the full screen pass, dithered depth buffer (inferred lighting), etc.), but will require some thought of course.[/quote]
Yes, you're right. I want to use fog not as weather element - only to cover far objects in fog (e.g. Morrowind). I'm talking about outdoor scenes now. In this case I can to neglect some aspects like particles and other transparent objects - only nearest objects are draw. Well... I think so.
0

Share this post


Link to post
Share on other sites
So basically you want poor man's atmospheric attenuation to hide geometry popping into existence at the far plane. Is there an urgent reason to do this as postprocess, which burns fillrate for nothing and means one extra pipeline stall?

You could as well do this kind of thing by interpolating the diffuse color with your fog color according to vertex z (possible both in forward and deferred shading), and by reducing the lighting intensity of objects.

You could probably even do a believeable approximation without any extra logic at all, simply by reducing saturation and luminosity in diffuse texture mipmaps.
0

Share this post


Link to post
Share on other sites
[quote name='samoth' timestamp='1329304809' post='4913303']
You could probably even do a believeable approximation without any extra logic at all, simply by reducing saturation and luminosity in diffuse texture mipmaps.
[/quote]

Interesting line of thinking, but what about nearby triangles at oblique angles?

EDIT: I know Super Mario Sunshine created an ingenious water rendering hack by doing something like this for the water surface, but there it wasn't so much of a problem-- in fact, the shimmering was probably a desirable artifact.
0

Share this post


Link to post
Share on other sites
[quote name='InvalidPointer' timestamp='1329329973' post='4913418']
Interesting line of thinking, but what about nearby triangles at oblique angles?[/quote]Since you would only do the effect on the rather small mipmaps, it would mostly (only?) affect extremely small triangles at a very tesselated object's silhouette. Other "typically oblique" triangles (house walls, floor) aren't normally so small.
Though I'm not sure if and how pronounced you might see saturation changes on the floor when rotating the camera. Maybe you won't notice at all, and maybe you'll think you should cut down on the LSD. Also, I am not sure in howfar aniso sampling might make the effect more visible e.g. on terrain (or, contrarily, hide it, by pulling in a lot of texels from a higher detail level?). One would really have to try :)

All in all, it would mostly mean that tesselated object silhouettes might appear darker and less saturated. Whether that's disturbing, I can't tell. Again, one would have to try. Darker, pronounced silhouettes might look totally wrong, might be not noticeable unless someone tells you, or might look surreal interesting, or might even give a "somewhat fake AO" impression.
0

Share this post


Link to post
Share on other sites
A few more thoughts: On [url="http://4.bp.blogspot.com/_LCC1PiU1JpY/TCfyV9yb_pI/AAAAAAAABE4/ODYSfsh9c3U/s1600/shen09-42.jpg"]this [/url]landscape photo, which I found via Google, you can see some trees with moderate atmospheric attenuation in the left half, and with some gentle as well as clearly visible attenuation in the right half. Compared to the more-or-less-foreground trees in the middle, these are about 1/12 and 1/30 the size (I'm assuming those trees are more or less the same size in real), which would translate to somewhere between 4 and 5 mip levels (pulling a marquee over some random photo is not a terribly accurate measurement).

So, for the effect to be clearly visible where you [i]don't [/i]want it (oblique nearby triangles), that would be triangles which use 4-5 mip levels above normal. Let's say 4 to be on the conservative side. Out of my belly 4 mip levels over the same object sounds like a lot to me.
0

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  
Followers 0