• 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
Meltac

How to distinguish outdoor and indoor areas in shader

9 posts in this topic

Hi everybody!

I'm working on a shader-based approach for a wet surfaces effect during rain in a PC game (S.T.A.L.K.E.R.). The game uses deferred shading/rendering with DirectX9 / HLSL and provides access to vertex and pixel shaders, but not material definitions or postprocess effects.

I already got a solution for faking wet terrain when it rains, however I have no idea how to apply it only to outdoor areas of the map, so that the effect won't be visible inside buildings, under bridges or large trees etc.

I've thought of something like checking whether an pixel's/vertexes normal line hits other pixel's/vertexes vertically above it, but I'm not sure if and how it would be possible to implement it, or if there would be any better approach for this.

Any ideas would be appreciated.
0

Share this post


Link to post
Share on other sites
You can do this via shadow-mapping techniques. Use any technique that works well for sun-shadows in large scenes (e.g. cascaded shadow maps), but instead of creating a shadow map from the sun's direction, create it from the direction that the rain is coming from.

Then in the shader, determine if you're in/out of the shadow like you would normally, but then use that value as a 'wet surface' value, instead of a shadow value.
0

Share this post


Link to post
Share on other sites
Thanks for the reply. The problem is that I have only access to the shaders themselves, not the host application as it would be the case in a XNA application, for example. So I need a way to do it only with the things that the game engine passes to the shaders, like the vertices / pixels and the default sampler states (position, color, normal map, light map, bump map, bloom etc.). Things like "d3dcreate..." won't work here, so I can't create my own shadow map.
0

Share this post


Link to post
Share on other sites
That makes it a bit harder then [img]http://public.gamedev.net//public/style_emoticons/default/wink.png[/img]
Do you only have access to the shaders that write to the g-buffer, or do you also have the lighting shaders that read from the g-buffer?
0

Share this post


Link to post
Share on other sites
You could try to work with bounding volumes (boxes), i.e. for all indoor area render approximated boxes and set a stencil for indoor pixels or reject the pixel in the shader when the bounding box test failed. Overdraw should be limited when utilizing the stencil buffer.
When you don't have access to the stencil buffer either, try to utilize some other buffer attribute (i.e. alpha channel).
0

Share this post


Link to post
Share on other sites
As far as I understand the game setting (it's quite undocumented), I have and can alter the source code of the shaders of three rendering stages, which they call

1. The G-Stage (geometry stage), also refered to as the deferring stage - These might be the shaders that write to the g-buffer
2. The lighting stage - these shaders seem to read data from the G-Stage, process the lighting, and pass it over to the
3. Combine stage, which are mainly pixel shaders doing stuff like fake AA, motion blur, depth of field, contrast and saturation adjustments, and combine the result with the bloom sample from the buffer.

Does that make sense? Where would I start looking then?
0

Share this post


Link to post
Share on other sites
This link to a conference presentation (PowerPoint document) sort of describes the mentioned game engine architecture:

[url="http://developer.amd.com/gpu_assets/01GDC09AD3DDStalkerClearSky210309.ppt"]http://developer.amd.com/gpu_assets/01GDC09AD3DDStalkerClearSky210309.ppt[/url]

When looking into the shaders code, you see these sampler state definitions referencing the described stages/phases:

[code]//////////////////////////////////////////////////////////////////////////////////////////
// Geometry phase / deferring //
uniform sampler2D s_base; //
uniform sampler2D s_bump; //
uniform sampler2D s_bumpX; //
uniform sampler2D s_detail; //
uniform sampler2D s_bumpD; //
uniform sampler2D s_hemi; //
uniform sampler2D s_mask; //
uniform sampler2D s_dt_r; //
uniform sampler2D s_dt_g; //
uniform sampler2D s_dt_b; //
uniform sampler2D s_dt_a; //
uniform sampler2D s_dn_r; //
uniform sampler2D s_dn_g; //
uniform sampler2D s_dn_b; //
uniform sampler2D s_dn_a; //
//////////////////////////////////////////////////////////////////////////////////////////
// Lighting/shadowing phase //
uniform sampler2D s_depth; //
uniform sampler2D s_position; //
uniform sampler2D s_normal; //
uniform sampler s_lmap; // 2D/cube projector lightmap
uniform sampler3D s_material; //
uniform sampler1D s_attenuate; //
//////////////////////////////////////////////////////////////////////////////////////////
// Combine phase //
uniform sampler2D s_diffuse; // rgb.a = diffuse.gloss
uniform sampler2D s_accumulator; // rgb.a = diffuse.specular
uniform sampler2D s_generic; //
uniform sampler2D s_bloom; //
uniform sampler s_image; // used in various post-processing
uniform sampler2D s_tonemap; // actually MidleGray / exp(Lw + eps)[/code]

Does that help?
0

Share this post


Link to post
Share on other sites
[quote name='Meltac' timestamp='1333014515' post='4926289']
Does that help?
[/quote]
No, to be honest. You try to mod an existing game/engine which is on the other hand not so popular. The most popular engines are unity,udk and cryengine, but nevertheless, it will be always hard to implement a special feature in an existing engine. It depends heavily on the engine and not everything is possible and you need often a hack-solution to approximate your goal. But I fear that you choose an engine not many people know.

Best to take a look at the stalker forums, maybe there's a section about modding their game. With some luck a developer might give you some hints.

Did you consider to change the engine ?
0

Share this post


Link to post
Share on other sites
The PPT that you linked to describes the shadow-mapping technique that I posted earlier -- apparently after the G stage but before the lighting stage, they use this shadow map to modify the G-buffer for wet surfaces.
0

Share this post


Link to post
Share on other sites
[quote name='Ashaman73' timestamp='1333084488' post='4926573']
Best to take a look at the stalker forums, maybe there's a section about modding their game. With some luck a developer might give you some hints.

Did you consider to change the engine ?
[/quote]

The xray engine might not be as popular as unity,udk and cryengine, but since I'm improving shaders on an existing game rather than developing a new one from scratch, changing the engine is not an option. And of course I took a look in the stalker forums, actually I'm a quite active user of the modding section there, but unfortunately there are very few stalker modders doing shader stuff. That's why I landed here after all in hopes of possibly getting better answers to my problems. But apparently it's not that easy [img]http://public.gamedev.net//public/style_emoticons/default/sad.png[/img]

[quote name='Hodgman' timestamp='1333087469' post='4926577']
The PPT that you linked to describes the shadow-mapping technique that I posted earlier -- apparently after the G stage but before the lighting stage, they use this shadow map to modify the G-buffer for wet surfaces.
[/quote]

Uhm, I seem to have overrread that part, sorry. I will try to sort this out, although it's kinda hard for me to figure out how to implement your suggestion with what I got...

[quote name='Hodgman' timestamp='1333009772' post='4926267']
but instead of creating a shadow map from the sun's direction, create it from the direction that the rain is coming from.

Then in the shader, determine if you're in/out of the shadow like you would normally, but then use that value as a 'wet surface' value, instead of a shadow value.
[/quote]

Could you maybe give me some code example showing what you mean exactly? That might be helpful since I'm not a shader guru (yet [img]http://public.gamedev.net//public/style_emoticons/default/cool.png[/img] )
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