diff options
author | Graham Linden <graham@lindenlab.com> | 2018-11-01 20:28:47 +0100 |
---|---|---|
committer | Graham Linden <graham@lindenlab.com> | 2018-11-01 20:28:47 +0100 |
commit | 4f267a5723e7da2de36b9f2295e4942a4c8bf6c5 (patch) | |
tree | c186a8888794732f32bba406b7bb66b4cafd4d11 /indra/newview/app_settings/shaders/class1/deferred | |
parent | a67cf385d763325119f4d2a37beb96c9c6a80282 (diff) |
SL-9994
Make shaders use consistent naming and parameter order for transport and atmospheric helpers.
Share transport and gamma correction code where possible.
Add lots of asserts and other validation for when things don't go as planned.
Engage dumpShaderSource to get more source output with shader compilation fail.
Diffstat (limited to 'indra/newview/app_settings/shaders/class1/deferred')
5 files changed, 35 insertions, 27 deletions
diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl index 7f2c5add16..1cfc19267c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl @@ -88,7 +88,7 @@ vec3 linear_to_srgb(vec3 cl); vec2 encode_normal (vec3 n); vec3 decode_normal (vec2 enc); -vec3 scaleFragSoftClip(vec3 l); +vec3 scaleSoftClipFrag(vec3 l); vec3 atmosFragAmbient(vec3 light, vec3 sunlit); vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten); vec3 atmosFragAffectDirectionalLight(float light, vec3 sunlit); @@ -312,7 +312,7 @@ void main() //color.rgb = mix(diff.rgb, color.rgb, final_alpha); color.rgb = atmosFragLighting(color.rgb, additive, atten); - color.rgb = scaleFragSoftClip(color.rgb); + color.rgb = scaleSoftClipFrag(color.rgb); vec4 light = vec4(0,0,0,0); diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index 6e06453a5b..c001ff9ac8 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -42,8 +42,8 @@ vec3 linear_to_srgb(vec3 cl); vec3 atmosFragAmbient(vec3 l, vec3 ambient); vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); -vec3 scaleFragSoftClip(vec3 l); -vec3 atmosFragAffectDirectionalLight(float intensity, vec3 sunlit); +vec3 scaleSoftClipFrag(vec3 l); + void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten); #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) @@ -406,7 +406,7 @@ void main() col.rgb *= ambient; - col.rgb = col.rgb + atmosFragAffectDirectionalLight(final_da, sunlit); + col.rgb = col.rgb + (final_da * sunlit); col.rgb *= gamma_diff.rgb; @@ -455,7 +455,7 @@ void main() //col = mix(scaleSoftClip(col), fullbrightScaleSoftClip(col), diffuse.a); col = atmosFragLighting(col, additive, atten); - col = scaleFragSoftClip(col); + col = scaleSoftClipFrag(col); //convert to linear space before adding local lights col = srgb_to_linear(col); diff --git a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl index c3827e3a56..5627275df6 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/softenLightF.glsl @@ -69,13 +69,7 @@ vec3 srgb_to_linear(vec3 cs); vec3 linear_to_srgb(vec3 cl); vec3 decode_normal (vec2 enc); -vec3 atmosFragAmbient(vec3 l, vec3 ambient); vec3 atmosFragLighting(vec3 l, vec3 additive, vec3 atten); -vec3 scaleFragSoftClip(vec3 l); -vec3 atmosFragAffectDirectionalLight(float intensity, vec3 sunlit); -vec3 fullbrightFragAtmosTransport(vec3 l, vec3 additive, vec3 atten); -vec3 fullbrightScaleSoftClipFrag(vec3 l, vec3 atten); - void calcFragAtmospherics(vec3 inPositionEye, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten); vec4 getPosition_d(vec2 pos_screen, float depth) @@ -123,22 +117,20 @@ void main() vec3 col; float bloom = 0.0; { - vec3 sunlit; - vec3 amblit; - vec3 additive; - vec3 atten; + vec3 sunlit; + vec3 amblit; + vec3 additive; + vec3 atten; calcFragAtmospherics(pos.xyz, 1.0, sunlit, amblit, additive, atten); - col = atmosFragAmbient(vec3(0), amblit); float ambient = min(abs(dot(norm.xyz, sun_dir.xyz)), 1.0); ambient *= 0.5; ambient *= ambient; - ambient = (1.0-ambient); - - col.rgb *= ambient; + ambient = (1.0 - ambient); - col += atmosFragAffectDirectionalLight(final_da, sunlit); - + col = amblit; + col += (final_da * sunlit); + col *= ambient; col *= diffuse.rgb; vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); @@ -174,9 +166,7 @@ void main() if (norm.w < 0.5) { - vec3 add = additive; - col = mix(atmosFragLighting(col, add, atten), fullbrightFragAtmosTransport(col, atten, add), diffuse.a); - col = mix(scaleFragSoftClip(col), fullbrightScaleSoftClipFrag(col, atten), diffuse.a); + col = atmosFragLighting(col, additive, atten); } #ifdef WATER_FOG @@ -187,7 +177,6 @@ void main() col = srgb_to_linear(col); - //col = vec3(1,0,1); //col.g = envIntensity; } diff --git a/indra/newview/app_settings/shaders/class1/deferred/srgb.glsl b/indra/newview/app_settings/shaders/class1/deferred/srgb.glsl index 587f3d5a94..00ba0e8fad 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/srgb.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/srgb.glsl @@ -23,6 +23,24 @@ * $/LicenseInfo$ */ +vec3 rgb2hsv(vec3 c) +{ + vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0); + vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g)); + vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r)); + + float d = q.x - min(q.w, q.y); + float e = 1.0e-10; + return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x); +} + +vec3 hsv2rgb(vec3 c) +{ + vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); + vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); + return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); +} + vec3 srgb_to_linear(vec3 cs) { vec3 low_range = cs / vec3(12.92); diff --git a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl index a29acb3e7d..73f6d9fec3 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/waterF.glsl @@ -73,6 +73,7 @@ VARYING vec4 vary_position; vec3 srgb_to_linear(vec3 cs); vec2 encode_normal(vec3 n); +vec3 scaleSoftClipFrag(vec3 l); vec3 BlendNormal(vec3 bump1, vec3 bump2) { @@ -175,7 +176,7 @@ void main() color.rgb += spec * specular; color.rgb = atmosTransport(color.rgb); - color.rgb = scaleSoftClip(color.rgb); + color.rgb = scaleSoftClipFrag(color.rgb); color.a = spec * sunAngle2; vec3 screenspacewavef = normalize((norm_mat*vec4(wavef, 1.0)).xyz); |