#1 Members - Reputation: 184
Posted 29 March 2012 - 02:09 AM
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.
#2 Moderators - Reputation: 13602
Posted 29 March 2012 - 02:29 AM
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 Members - Reputation: 184
Posted 29 March 2012 - 03:11 AM
#5 Members - Reputation: 4603
Posted 29 March 2012 - 03:33 AM
When you don't have access to the stencil buffer either, try to utilize some other buffer attribute (i.e. alpha channel).
My game: Gnoblins
Developer journal about Gnoblins
Small goodies: Simple alpha transparency in deferred shader
#6 Members - Reputation: 184
Posted 29 March 2012 - 03:40 AM
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 Members - Reputation: 184
Posted 29 March 2012 - 03:48 AM
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 Members - Reputation: 4603
Posted 29 March 2012 - 11:14 PM
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.Does that help?
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 ?
#10 Members - Reputation: 184
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
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






