diff options
Diffstat (limited to 'indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl')
-rw-r--r-- | indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl | 101 |
1 files changed, 17 insertions, 84 deletions
diff --git a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl index f1aec315cc..694b19cdfb 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/spotLightF.glsl @@ -70,64 +70,8 @@ uniform vec2 screen_res; uniform mat4 inv_proj; -vec2 encode_normal(vec3 n) -{ - float f = sqrt(8 * n.z + 8); - return n.xy / f + 0.5; -} - -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; -} - -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) -{ - cl = clamp(cl, vec3(0), vec3(1)); - 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 - -} - -vec4 correctWithGamma(vec4 col) -{ - return vec4(srgb_to_linear(col.rgb), col.a); -} +vec3 getNorm(vec2 pos_screen); +vec3 srgb_to_linear(vec3 c); vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) { @@ -152,7 +96,7 @@ vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod) vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); - ret = correctWithGamma(ret); + ret.rgb = srgb_to_linear(ret.rgb); vec2 dist = vec2(0.5) - abs(tc-vec2(0.5)); @@ -170,7 +114,7 @@ vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod) vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) { vec4 ret = texture2DLod(projectionMap, tc, lod); - ret = correctWithGamma(ret); + ret.rgb = srgb_to_linear(ret.rgb); vec2 dist = tc-vec2(0.5); @@ -181,22 +125,15 @@ vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod) return ret; } - -vec4 getPosition(vec2 pos_screen) -{ - float depth = texture2DRect(depthMap, pos_screen.xy).r; - vec2 sc = pos_screen.xy*2.0; - sc /= screen_res; - sc -= vec2(1.0,1.0); - vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); - vec4 pos = inv_proj * ndc; - pos /= pos.w; - pos.w = 1.0; - return pos; -} +vec4 getPosition(vec2 pos_screen); void main() { + vec3 col = vec3(0,0,0); + +#if defined(LOCAL_LIGHT_KILL) + discard; +#else vec4 frag = vary_fragcoord; frag.xyz /= frag.w; frag.xyz = frag.xyz*0.5+0.5; @@ -210,12 +147,10 @@ void main() { discard; } - vec3 norm = texture2DRect(normalMap, frag.xy).xyz; float envIntensity = norm.z; - norm = decode_normal(norm.xy); - + norm = getNorm(frag.xy); norm = normalize(norm); float l_dist = -dot(lv, proj_n); @@ -241,13 +176,11 @@ void main() lv = normalize(lv); float da = dot(norm, lv); - vec3 col = vec3(0,0,0); - vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb; - - vec4 spec = texture2DRect(specularRect, frag.xy); + //light shaders output linear and are gamma corrected later in postDeferredGammaCorrectF.glsl + diff_tex.rgb = srgb_to_linear(diff_tex.rgb); - + vec4 spec = texture2DRect(specularRect, frag.xy); float noise = texture2D(noiseMap, frag.xy/128.0).b; vec3 dlit = vec3(0, 0, 0); @@ -284,7 +217,6 @@ void main() amb_da = min(amb_da, 1.0-lit); col += amb_da*color.rgb*diff_tex.rgb*amb_plcol.rgb*amb_plcol.a*diff_tex.rgb; } - if (spec.a > 0.0) { @@ -311,7 +243,6 @@ void main() } } - if (envIntensity > 0.0) { vec3 ref = reflect(normalize(pos), norm); @@ -340,7 +271,9 @@ void main() } } } - +#endif + + //col.r = 1.0; frag_color.rgb = col; frag_color.a = 0.0; } |