diff options
Diffstat (limited to 'indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl')
-rwxr-xr-x[-rw-r--r--] | indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl | 195 |
1 files changed, 170 insertions, 25 deletions
diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index 66e3cf6d13..760d52a9ce 100644..100755 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -24,6 +24,7 @@ */ #extension GL_ARB_texture_rectangle : enable +#extension GL_ARB_shader_texture_lod : enable #ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; @@ -60,6 +61,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 +79,54 @@ vec3 vary_AtmosAttenuation; uniform mat4 inv_proj; uniform vec2 screen_res; +vec3 srgb_to_linear(vec3 cs) +{ + vec3 low_range = cs / vec3(12.92); + vec3 high_range = pow((cs+vec3(0.055))/vec3(1.055), vec3(2.4)); + bvec3 lte = lessThanEqual(cs,vec3(0.04045)); + +#ifdef OLD_SELECT + vec3 result; + result.r = lte.r ? low_range.r : high_range.r; + result.g = lte.g ? low_range.g : high_range.g; + result.b = lte.b ? low_range.b : high_range.b; + return result; +#else + return mix(high_range, low_range, lte); +#endif + +} + +vec3 linear_to_srgb(vec3 cl) +{ + vec3 low_range = cl * 12.92; + vec3 high_range = 1.055 * pow(cl, vec3(0.41666)) - 0.055; + bvec3 lt = lessThan(cl,vec3(0.0031308)); + +#ifdef OLD_SELECT + vec3 result; + result.r = lt.r ? low_range.r : high_range.r; + result.g = lt.g ? low_range.g : high_range.g; + result.b = lt.b ? low_range.b : high_range.b; + return result; +#else + return mix(high_range, low_range, lt); +#endif + +} + + +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; +} + vec4 getPosition_d(vec2 pos_screen, float depth) { vec2 sc = pos_screen.xy*2.0; @@ -116,7 +166,6 @@ vec3 getAtmosAttenuation() return vary_AtmosAttenuation; } - void setPositionEye(vec3 v) { vary_PositionEye = v; @@ -142,6 +191,53 @@ void setAtmosAttenuation(vec3 v) vary_AtmosAttenuation = v; } + +#ifdef WATER_FOG +uniform vec4 waterPlane; +uniform vec4 waterFogColor; +uniform float waterFogDensity; +uniform float waterFogKS; + +vec4 applyWaterFogDeferred(vec3 pos, vec4 color) +{ + //normalize view vector + vec3 view = normalize(pos); + float es = -(dot(view, waterPlane.xyz)); + + //find intersection point with water plane and eye vector + + //get eye depth + float e0 = max(-waterPlane.w, 0.0); + + vec3 int_v = waterPlane.w > 0.0 ? view * waterPlane.w/es : vec3(0.0, 0.0, 0.0); + + //get object depth + float depth = length(pos - int_v); + + //get "thickness" of water + float l = max(depth, 0.1); + + float kd = waterFogDensity; + float ks = waterFogKS; + vec4 kc = waterFogColor; + + float F = 0.98; + + float t1 = -kd * pow(F, ks * e0); + float t2 = kd + ks * es; + float t3 = pow(F, t2*l) - 1.0; + + float L = min(t1/t2*t3, 1.0); + + float D = pow(0.98, l*kd); + + color.rgb = color.rgb * D + kc.rgb * L; + color.a = kc.a + color.a; + + return color; +} +#endif + void calcAtmospherics(vec3 inPositionEye, float ambFactor) { vec3 P = inPositionEye; @@ -237,6 +333,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,60 +376,100 @@ 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 = vec3((norm.xy-0.5)*2.0,norm.z); // 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); - + float da = dot(norm.xyz, sun_dir.xyz); + + float final_da = max(0.0,da); + final_da = min(final_da, 1.0f); + final_da = pow(final_da, 1.0/1.3); + vec4 diffuse = texture2DRect(diffuseRect, tc); + + //convert to gamma space + diffuse.rgb = linear_to_srgb(diffuse.rgb); + 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(final_da); 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; - } + #ifdef WATER_FOG + vec4 fogged = applyWaterFogDeferred(pos,vec4(col, bloom)); + col = fogged.rgb; + bloom = fogged.a; + #endif + + col = srgb_to_linear(col); - frag_color.rgb = col; + //col = vec3(1,0,1); + //col.g = envIntensity; + } + frag_color.rgb = col.rgb; frag_color.a = bloom; } + |