Skip to content
Snippets Groups Projects
Commit c4630a4b authored by Graham Linden's avatar Graham Linden
Browse files

Work around broken deps on atmospheric vars in the frag-based deferred lighting pipe.

parent aa011505
No related branches found
No related tags found
No related merge requests found
...@@ -86,6 +86,8 @@ vec4 getPosition(vec2 pos_screen) ...@@ -86,6 +86,8 @@ vec4 getPosition(vec2 pos_screen)
return pos; return pos;
} }
#if USE_DEFERRED_SHADER_API
vec4 getPositionWithDepth(vec2 pos_screen, float depth) vec4 getPositionWithDepth(vec2 pos_screen, float depth)
{ {
vec2 sc = getScreenCoordinate(pos_screen); vec2 sc = getScreenCoordinate(pos_screen);
...@@ -285,3 +287,5 @@ float calcAmbientOcclusion(vec4 pos, vec3 norm, vec2 pos_screen) ...@@ -285,3 +287,5 @@ float calcAmbientOcclusion(vec4 pos, vec3 norm, vec2 pos_screen)
return min(ret, 1.0); return min(ret, 1.0);
} }
#endif
...@@ -41,7 +41,7 @@ uniform sampler2DRect normalMap; ...@@ -41,7 +41,7 @@ uniform sampler2DRect normalMap;
uniform sampler2DRect lightMap; uniform sampler2DRect lightMap;
uniform sampler2DRect depthMap; uniform sampler2DRect depthMap;
uniform samplerCube environmentMap; uniform samplerCube environmentMap;
uniform sampler2D lightFunc; uniform sampler2D lightFunc;
uniform float blur_size; uniform float blur_size;
uniform float blur_fidelity; uniform float blur_fidelity;
...@@ -78,114 +78,106 @@ vec3 fullbrightScaleSoftClip(vec3 l); ...@@ -78,114 +78,106 @@ vec3 fullbrightScaleSoftClip(vec3 l);
vec4 getPosition_d(vec2 pos_screen, float depth) vec4 getPosition_d(vec2 pos_screen, float depth)
{ {
vec2 sc = pos_screen.xy*2.0; vec2 sc = pos_screen.xy*2.0;
sc /= screen_res; sc /= screen_res;
sc -= vec2(1.0,1.0); sc -= vec2(1.0,1.0);
vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0);
vec4 pos = inv_proj * ndc; vec4 pos = inv_proj * ndc;
pos /= pos.w; pos /= pos.w;
pos.w = 1.0; pos.w = 1.0;
return pos; return pos;
} }
vec4 getPosition(vec2 pos_screen) vec4 getPosition(vec2 pos_screen)
{ //get position in screen space (world units) given window coordinate and depth map { //get position in screen space (world units) given window coordinate and depth map
float depth = texture2DRect(depthMap, pos_screen.xy).a; float depth = texture2DRect(depthMap, pos_screen.xy).a;
return getPosition_d(pos_screen, depth); return getPosition_d(pos_screen, depth);
} }
void main() void main()
{ {
vec2 tc = vary_fragcoord.xy; vec2 tc = vary_fragcoord.xy;
float depth = texture2DRect(depthMap, tc.xy).r; float depth = texture2DRect(depthMap, tc.xy).r;
vec3 pos = getPosition_d(tc, depth).xyz; vec3 pos = getPosition_d(tc, depth).xyz;
vec4 norm = texture2DRect(normalMap, tc); vec4 norm = texture2DRect(normalMap, tc);
float envIntensity = norm.z; float envIntensity = norm.z;
norm.xyz = decode_normal(norm.xy); // unpack norm norm.xyz = decode_normal(norm.xy); // unpack norm
float da = dot(norm.xyz, sun_dir.xyz); float da = dot(norm.xyz, sun_dir.xyz);
float final_da = max(0.0,da); float final_da = clamp(da, 0.0, 1.0);
final_da = min(final_da, 1.0f); final_da = pow(final_da, 1.0/1.3);
// why an ad hoc gamma boost here? srgb_to_linear instead? vec4 diffuse = texture2DRect(diffuseRect, tc);
final_da = pow(final_da, 1.0/1.3);
//convert to gamma space
vec4 diffuse = texture2DRect(diffuseRect, tc); diffuse.rgb = linear_to_srgb(diffuse.rgb);
//convert to gamma space vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy);
diffuse.rgb = linear_to_srgb(diffuse.rgb); vec3 col;
float bloom = 0.0;
vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); {
vec3 col;
float bloom = 0.0;
{
vec3 sunlit; vec3 sunlit;
vec3 amblit; vec3 amblit;
vec3 additive; vec3 additive;
vec3 atten; vec3 atten;
calcFragAtmospherics(pos.xyz, 1.0, sunlit, amblit, additive, atten); calcFragAtmospherics(pos.xyz, 1.0, sunlit, amblit, additive, atten);
float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0);
ambient *= 0.5; ambient *= 0.5;
ambient *= ambient; ambient *= ambient;
ambient = (1.0 - ambient); ambient = (1.0 - ambient);
col = amblit; col = amblit;
col *= ambient; col *= ambient;
col += (final_da * sunlit); col += (final_da * sunlit);
col *= diffuse.rgb; col *= diffuse.rgb;
vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz));
if (spec.a > 0.0) // specular reflection if (spec.a > 0.0) // specular reflection
{ {
// the old infinite-sky shiny reflection // the old infinite-sky shiny reflection
// //
float sa = dot(refnormpersp, sun_dir.xyz); float sa = dot(refnormpersp, sun_dir.xyz);
vec3 dumbshiny = sunlit*(texture2D(lightFunc, vec2(sa, spec.a)).r); vec3 dumbshiny = sunlit*(texture2D(lightFunc, vec2(sa, spec.a)).r);
// add the two types of shiny together // add the two types of shiny together
vec3 spec_contrib = dumbshiny * spec.rgb; vec3 spec_contrib = dumbshiny * spec.rgb;
bloom = dot(spec_contrib, spec_contrib) / 6; bloom = dot(spec_contrib, spec_contrib) / 6;
col += spec_contrib; col += spec_contrib;
} }
col = mix(col.rgb, diffuse.rgb, diffuse.a);
col = mix(col.rgb, diffuse.rgb, diffuse.a);
if (envIntensity > 0.0)
if (envIntensity > 0.0) { //add environmentmap
{ //add environmentmap vec3 env_vec = env_mat * refnormpersp;
vec3 env_vec = env_mat * refnormpersp; vec3 refcol = textureCube(environmentMap, env_vec).rgb;
col = mix(col.rgb, refcol, envIntensity);
}
vec3 refcol = textureCube(environmentMap, env_vec).rgb;
if (norm.w < 0.5)
col = mix(col.rgb, refcol, {
envIntensity); col = mix(atmosFragLighting(col, additive, atten), fullbrightAtmosTransportFrag(col, additive, atten), diffuse.a);
} col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a);
}
if (norm.w < 0.5)
{ #ifdef WATER_FOG
col = mix(atmosFragLighting(col, additive, atten), fullbrightAtmosTransportFrag(col, additive, atten), diffuse.a); vec4 fogged = applyWaterFogView(pos.xyz,vec4(col, bloom));
col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a); col = fogged.rgb;
} bloom = fogged.a;
#endif
#ifdef WATER_FOG
vec4 fogged = applyWaterFogView(pos.xyz,vec4(col, bloom)); col = srgb_to_linear(col);
col = fogged.rgb;
bloom = fogged.a; //col = vec3(1,0,1);
#endif //col.g = envIntensity;
}
col = srgb_to_linear(col);
frag_color.rgb = col.rgb;
//col = vec3(1,0,1); frag_color.a = bloom;
//col.g = envIntensity;
}
frag_color.rgb = col.rgb;
frag_color.a = bloom;
} }
/** /**
* @file softenLightF.glsl * @file softenLightV.glsl
* *
* $LicenseInfo:firstyear=2007&license=viewerlgpl$ * $LicenseInfo:firstyear=2007&license=viewerlgpl$
* Second Life Viewer Source Code * Second Life Viewer Source Code
......
...@@ -48,11 +48,11 @@ vec3 scaleSoftClip(vec3 light) ...@@ -48,11 +48,11 @@ vec3 scaleSoftClip(vec3 light)
} }
vec3 fullbrightScaleSoftClipFrag(vec3 light) { vec3 fullbrightScaleSoftClipFrag(vec3 light) {
return mix(scaleSoftClip(light.rgb), light.rgb, getAtmosAttenuation()); return scaleSoftClipFrag(light.rgb);
} }
vec3 fullbrightScaleSoftClip(vec3 light) vec3 fullbrightScaleSoftClip(vec3 light)
{ {
return fullbrightScaleSoftClipFrag(light); return scaleSoftClipFrag(light);
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment