Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Don't forget to read Tuesday's email newsletter for your chance to win a free copy of Construct 2!


How to distinguish outdoor and indoor areas in shader


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
9 replies to this topic

#1 Meltac   Members   -  Reputation: 425

Like
0Likes
Like

Posted 29 March 2012 - 02:09 AM

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.

Sponsor:

#2 Hodgman   Moderators   -  Reputation: 31064

Like
0Likes
Like

Posted 29 March 2012 - 02:29 AM

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.

#3 Meltac   Members   -  Reputation: 425

Like
0Likes
Like

Posted 29 March 2012 - 03:11 AM

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.

#4 Hodgman   Moderators   -  Reputation: 31064

Like
0Likes
Like

Posted 29 March 2012 - 03:26 AM

That makes it a bit harder then Posted Image
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?

#5 Ashaman73   Crossbones+   -  Reputation: 7823

Like
0Likes
Like

Posted 29 March 2012 - 03:33 AM

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).

#6 Meltac   Members   -  Reputation: 425

Like
0Likes
Like

Posted 29 March 2012 - 03:40 AM

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?

#7 Meltac   Members   -  Reputation: 425

Like
0Likes
Like

Posted 29 March 2012 - 03:48 AM

This link to a conference presentation (PowerPoint document) sort of describes the mentioned game engine architecture:

http://developer.amd.com/gpu_assets/01GDC09AD3DDStalkerClearSky210309.ppt

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

//////////////////////////////////////////////////////////////////////////////////////////
// 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)

Does that help?

#8 Ashaman73   Crossbones+   -  Reputation: 7823

Like
0Likes
Like

Posted 29 March 2012 - 11:14 PM

Does that help?

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 ?

#9 Hodgman   Moderators   -  Reputation: 31064

Like
0Likes
Like

Posted 30 March 2012 - 12:04 AM

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.

#10 Meltac   Members   -  Reputation: 425

Like
0Likes
Like

Posted 30 March 2012 - 04:25 AM

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 ?


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 Posted Image

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.


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...

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.


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 Posted Image )




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS