1

I am working on a rendering program and I have several effects I need to combine together. I have shadow mapping, SSS, and wrap lighting as described here: http://http.developer.nvidia.com/GPUGems/gpugems_ch16.html

How do I combine these effects? When computing the shadow I get a float [0,1] to multiply by the overall color, and the SSS computation I get a float [0,1] describing how far the light traveled through the object. I cannot multiply these because then the back face will still be in shadow. I am just generally confused about combining many lighting effects.

I am doing typical VSM shadow mapping where a depth map is rendered from each light, and then one final pass from the camera. In this pass I compute the shadow component using VSM and the SSS component using the same depth map ( exp( -(d_o - d_i) * sigma_t ) ). (the body of the code below happens once per light hence the index)

shadow = shadowsVar[i];
NdotL = dot(n,normalize(lightDir[i]));  
spotEffect = dot(normalize(gl_LightSource[i].spotDirection), normalize(-lightDir[i]));

if (spotEffect > spotOff[i])
{
    spotEffect = smoothstep(spotOff[i], 1.0, spotEffect); 
    spotEffect *= shadow;

// this is where im trying to incorporate my sss component
#ifdef SUBSURFACE_SCATTERING
    spotEffect *= sss_comp;
#endif // SUBSURFACE_SCATTERING

    att = spotEffect;

    diffuse = gl_FrontMaterial.diffuse * gl_LightSource[i].diffuse * NdotL;

    final_color += att * diffuse;

    halfV = normalize(gl_LightSource[i].halfVector).xyz;
    NdotHV = max(dot(n,halfV),0.0);
    specular_color += att * gl_FrontMaterial.specular *  gl_LightSource[i].specular * pow(NdotHV,gl_FrontMaterial.shininess);
}

#ifdef USE_TEXTURE
final_color.rgb *= texture2D(colorTexture,gl_TexCoord[0].st).rgb;
#endif // USE_TEXTURE

final_color.rgb += specular_color.rgb;
gl_FragColor = final_color;
Matsemann
  • 21,083
  • 19
  • 56
  • 89
zumba man
  • 129
  • 1
  • 12
  • This is extremly broad topic! We do not know how you implemented each technique (how many passes, what is input/output of each pass and what it do,etc). Try to specify closer (even if we study the techniques we could obtain very different implementations). Add block diagram sketch of how and what you are rendering. add sample images of outputs and slight description what is/does what. Also specify your scene (size and type of objects and their representation) without this is almost impossible to help. (also some source code would not hurt) There are many ways how to combine lighting effects... – Spektre Nov 04 '15 at 08:59
  • For example see my simplified [GLSL Atmospheric scattering](http://stackoverflow.com/a/19659648/2521214). I use 2 pass rendering and the scattering is done/added in second pass as transparent quad covering the screen. There are other possibilities you can feed the output of any of your technique as input texture for the next one etc ... all depend on your implementation ... – Spektre Nov 04 '15 at 09:41
  • @Spektre I added some details. – zumba man Nov 04 '15 at 18:04
  • 1
    I am not familiar with the techniques but as I see it SSS is source of light (emission) and shadow is sink of light so I would try to Add the SSS to final color of fragment instead of multiplying shadow component with it ... Also you may use the shadow component as input for SSS by modulating input light source with it... – Spektre Nov 05 '15 at 06:53

0 Answers0