diff options
author | Nyx Linden <nyx@lindenlab.com> | 2013-08-16 19:31:16 -0400 |
---|---|---|
committer | Nyx Linden <nyx@lindenlab.com> | 2013-08-16 19:31:16 -0400 |
commit | 5ae117aff6bfbc3c07876146ca270129dd91a047 (patch) | |
tree | 462f491cc055aa296b9da0041a322cd9512c045b /indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl | |
parent | 8abd6ed6b8c294ec6bfca59929dbcc71cd65c3a3 (diff) | |
parent | 32b8d398eca5eaa4ca99aa48839ad64d97954cae (diff) |
merge with viewer-release
Diffstat (limited to 'indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl')
-rwxr-xr-x | indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl | 112 |
1 files changed, 90 insertions, 22 deletions
diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 89448e2167..08583ad0f2 100755 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -60,6 +60,7 @@ uniform float density_multiplier; uniform float distance_multiplier; uniform float max_y; uniform vec4 glow; +uniform float global_gamma; uniform float scene_light_strength; uniform mat3 env_mat; uniform mat3 ssao_effect_mat; @@ -77,6 +78,34 @@ vec3 vary_AtmosAttenuation; uniform mat4 inv_proj; uniform vec2 screen_res; +#ifdef SINGLE_FP_ONLY +vec2 encode_normal(vec3 n) +{ + vec2 sn; + sn.xy = (n.xy * vec2(0.5f,0.5f)) + vec2(0.5f,0.5f); + return sn; +} + +vec3 decode_normal (vec2 enc) +{ + vec3 n; + n.xy = (enc.xy * vec2(2.0f,2.0f)) - vec2(1.0f,1.0f); + n.z = sqrt(1.0f - dot(n.xy,n.xy)); + return n; +} +#else +vec3 decode_normal (vec2 enc) +{ + vec2 fenc = enc*4-2; + float f = dot(fenc,fenc); + float g = sqrt(1-f/4); + vec3 n; + n.xy = fenc*g; + n.z = 1-f/2; + return n; +} +#endif + vec4 getPosition_d(vec2 pos_screen, float depth) { vec2 sc = pos_screen.xy*2.0; @@ -116,7 +145,6 @@ vec3 getAtmosAttenuation() return vary_AtmosAttenuation; } - void setPositionEye(vec3 v) { vary_PositionEye = v; @@ -237,6 +265,15 @@ vec3 atmosTransport(vec3 light) { light += getAdditiveColor() * 2.0; return light; } + +vec3 fullbrightAtmosTransport(vec3 light) { + float brightness = dot(light.rgb, vec3(0.33333)); + + return mix(atmosTransport(light.rgb), light.rgb + getAdditiveColor().rgb, brightness * brightness); +} + + + vec3 atmosGetDiffuseSunlightColor() { return getSunlitColor(); @@ -271,57 +308,88 @@ vec3 scaleSoftClip(vec3 light) return light; } + +vec3 fullbrightScaleSoftClip(vec3 light) +{ + //soft clip effect: + return light; +} + void main() { vec2 tc = vary_fragcoord.xy; float depth = texture2DRect(depthMap, tc.xy).r; vec3 pos = getPosition_d(tc, depth).xyz; - vec3 norm = texture2DRect(normalMap, tc).xyz; - norm = (norm.xyz-0.5)*2.0; // unpack norm + vec4 norm = texture2DRect(normalMap, tc); + float envIntensity = norm.z; + norm.xyz = decode_normal(norm.xy); // unpack norm float da = max(dot(norm.xyz, sun_dir.xyz), 0.0); - + da = pow(da, 1.0/1.3); + vec4 diffuse = texture2DRect(diffuseRect, tc); + + //convert to gamma space + diffuse.rgb = pow(diffuse.rgb, vec3(1.0/2.2)); + vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); - vec3 col; float bloom = 0.0; - if (diffuse.a < 0.9) { calcAtmospherics(pos.xyz, 1.0); col = atmosAmbient(vec3(0)); - col += atmosAffectDirectionalLight(max(min(da, 1.0), diffuse.a)); + float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); + ambient *= 0.5; + ambient *= ambient; + ambient = (1.0-ambient); + + col.rgb *= ambient; + + col += atmosAffectDirectionalLight(max(min(da, 1.0), 0.0)); col *= diffuse.rgb; + vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); + if (spec.a > 0.0) // specular reflection { // the old infinite-sky shiny reflection // - vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); + float sa = dot(refnormpersp, sun_dir.xyz); - vec3 dumbshiny = vary_SunlitColor*(6 * texture2D(lightFunc, vec2(sa, spec.a)).r); + vec3 dumbshiny = vary_SunlitColor*(texture2D(lightFunc, vec2(sa, spec.a)).r); // add the two types of shiny together vec3 spec_contrib = dumbshiny * spec.rgb; - bloom = dot(spec_contrib, spec_contrib) / 4; + bloom = dot(spec_contrib, spec_contrib) / 6; col += spec_contrib; - - //add environmentmap + } + + + col = mix(col.rgb, diffuse.rgb, diffuse.a); + + if (envIntensity > 0.0) + { //add environmentmap vec3 env_vec = env_mat * refnormpersp; - col = mix(col.rgb, textureCube(environmentMap, env_vec).rgb, - max(spec.a-diffuse.a*2.0, 0.0)); + + + vec3 refcol = textureCube(environmentMap, env_vec).rgb; + + col = mix(col.rgb, refcol, + envIntensity); + } + + if (norm.w < 0.5) + { + col = mix(atmosLighting(col), fullbrightAtmosTransport(col), diffuse.a); + col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a); } - - col = atmosLighting(col); - col = scaleSoftClip(col); - col = mix(col.rgb, diffuse.rgb, diffuse.a); - } - else - { - col = diffuse.rgb; + col = pow(col, vec3(2.2)); + + //col = vec3(1,0,1); + //col.g = envIntensity; } frag_color.rgb = col; |