diff options
Diffstat (limited to 'indra')
-rw-r--r-- | indra/newview/app_settings/shaders/class3/deferred/materialF.glsl | 28 | ||||
-rw-r--r-- | indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl | 28 |
2 files changed, 56 insertions, 0 deletions
diff --git a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl index d9e15738ad..62bb09e94b 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl @@ -44,6 +44,7 @@ vec4 applyWaterFogView(vec3 pos, vec4 color); vec3 atmosFragLightingLinear(vec3 l, vec3 additive, vec3 atten); vec3 scaleSoftClipFragLinear(vec3 l); void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 norm, vec3 light_dir, out vec3 sunlit, out vec3 amblit, out vec3 atten, out vec3 additive); +void calcHalfVectors(vec3 lv, vec3 n, vec3 v, out vec3 h, out vec3 l, out float nh, out float nl, out float nv, out float vh, out float lightDist); vec3 srgb_to_linear(vec3 cs); vec3 linear_to_srgb(vec3 cs); @@ -359,6 +360,7 @@ void main() float glare = 0.0; +#if 0 //wrong implementation if (glossiness > 0.0) // specular reflection { float sa = dot(normalize(refnormpersp), light_dir.xyz); @@ -375,6 +377,32 @@ void main() applyGlossEnv(color, glossenv, spec, pos.xyz, norm.xyz); } +#else //right implementation ported from pointLightF.glsl + if (glossiness > 0.0) + { + vec3 lv = light_dir.xyz; + vec3 h, l, v = -normalize(pos.xyz); + float nh, nl, nv, vh, lightDist; + vec3 n = norm.xyz; + calcHalfVectors(lv, n, v, h, l, nh, nl, nv, vh, lightDist); + + if (nl > 0.0 && nh > 0.0) + { + float lit = min(nl*6.0, 1.0); + + float sa = nh; + float fres = pow(1 - vh, 5) * 0.4+0.5; + float gtdenom = 2 * nh; + float gt = max(0,(min(gtdenom * nv / vh, gtdenom * nl / vh))); + + float scol = shadow*fres*texture2D(lightFunc, vec2(nh, glossiness)).r*gt/(nh*nl); + color.rgb += lit*scol*sunlit_linear.rgb*spec.rgb; + } + + // add radiance map + applyGlossEnv(color, glossenv, spec, pos.xyz, norm.xyz); + } +#endif color = mix(color.rgb, diffcol.rgb, emissive); diff --git a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl index 8f5bd6141a..ab83708c7b 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/softenLightF.glsl @@ -95,6 +95,7 @@ vec4 applyWaterFogViewLinear(vec3 pos, vec4 color); uniform float sky_hdr_scale; +void calcHalfVectors(vec3 lv, vec3 n, vec3 v, out vec3 h, out vec3 l, out float nh, out float nl, out float nv, out float vh, out float lightDist); void calcDiffuseSpecular(vec3 baseColor, float metallic, inout vec3 diffuseColor, inout vec3 specularColor); vec3 pbrBaseLight(vec3 diffuseColor, @@ -245,6 +246,7 @@ void main() vec3 refnormpersp = reflect(pos.xyz, norm.xyz); +#if 0 // wrong implementation if (spec.a > 0.0) // specular reflection { float sa = dot(normalize(refnormpersp), light_dir.xyz); @@ -257,6 +259,32 @@ void main() // add radiance map applyGlossEnv(color, glossenv, spec, pos.xyz, norm.xyz); } +#else //right implementation (ported from pointLightF.glsl) + if (spec.a > 0.0) + { + vec3 lv = light_dir.xyz; + vec3 h, l, v = -normalize(pos.xyz); + float nh, nl, nv, vh, lightDist; + vec3 n = norm.xyz; + calcHalfVectors(lv, n, v, h, l, nh, nl, nv, vh, lightDist); + + if (nl > 0.0 && nh > 0.0) + { + float lit = min(nl*6.0, 1.0); + + float sa = nh; + float fres = pow(1 - vh, 5) * 0.4+0.5; + float gtdenom = 2 * nh; + float gt = max(0,(min(gtdenom * nv / vh, gtdenom * nl / vh))); + + scol *= fres*texture2D(lightFunc, vec2(nh, spec.a)).r*gt/(nh*nl); + color.rgb += lit*scol*sunlit_linear.rgb*spec.rgb; + } + + // add radiance map + applyGlossEnv(color, glossenv, spec, pos.xyz, norm.xyz); + } +#endif color.rgb = mix(color.rgb, baseColor.rgb, baseColor.a); |