From 4aad62006259c20bcdda1495138f7313b8f35e8d Mon Sep 17 00:00:00 2001 From: Graham Linden Date: Fri, 22 Feb 2019 14:50:03 -0800 Subject: SL-10415, SL-10612, SL-10569 Fix shadow sampling min with caster dp and offset tweaks. Fix moon direction not being transformed as the sun dir is. Fix colorspace issue causing some objects to render grayish instead of blackish. --- .../shaders/class1/deferred/materialF.glsl | 21 ++++++++----- .../shaders/class1/deferred/shadowUtil.glsl | 13 ++++---- .../shaders/class2/deferred/softenLightF.glsl | 35 +++++++++++----------- indra/newview/pipeline.cpp | 5 ++++ 4 files changed, 44 insertions(+), 30 deletions(-) (limited to 'indra/newview') diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl index c8f4d7c570..251e60c59e 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl @@ -202,7 +202,8 @@ void main() #endif #if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND) - vec3 gamma_diff = linear_to_srgb(diffcol.rgb); + vec3 gamma_diff = diffcol.rgb; + diffcol.rgb = srgb_to_linear(diffcol.rgb); #endif #if HAS_SPECULAR_MAP @@ -280,20 +281,17 @@ void main() final_da = min(final_da, 1.0f); final_da = pow(final_da, display_gamma); - col.rgb = (col * 0.5) + amblit; + col.rgb = amblit; float ambient = min(abs(final_da), 1.0); ambient *= 0.5; ambient *= ambient; ambient = (1.0-ambient); - col.rgb *= ambient; - - col.rgb = col.rgb + (final_da * sunlit); - + col.rgb *= min(ambient, max(shadow,0.3)); + col.rgb += (final_da * sunlit); col.rgb *= gamma_diff.rgb; - float glare = 0.0; if (spec.a > 0.0) // specular reflection @@ -315,6 +313,7 @@ void main() col += spec_contrib; } +vec3 post_spec = col.rgb; col = mix(col.rgb, diffcol.rgb, diffuse.a); @@ -337,6 +336,8 @@ void main() col = atmosFragLighting(col, additive, atten); col = scaleSoftClipFrag(col); +vec3 post_atmo= col.rgb; + vec3 npos = normalize(-pos.xyz); vec3 light = vec3(0,0,0); @@ -353,18 +354,24 @@ void main() col.rgb += light.rgb; +vec3 post_lighting = col.rgb; + glare = min(glare, 1.0); float al = max(diffcol.a,glare)*vertex_color.a; //convert to gamma space for display on screen col.rgb = linear_to_srgb(col.rgb); +vec3 post_srgb = col.rgb; + #ifdef WATER_FOG vec4 temp = applyWaterFogView(pos, vec4(col.rgb, al)); col.rgb = temp.rgb; al = temp.a; #endif +//col.rgb = post_lighting; + frag_color.rgb = col.rgb; frag_color.a = al; diff --git a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl index 5cc24475e3..ad96c84de8 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/shadowUtil.glsl @@ -49,8 +49,8 @@ uniform int sun_up_factor; float pcfShadow(sampler2DShadow shadowMap, vec3 norm, vec4 stc, float bias_mul, vec2 pos_screen, vec3 light_dir) { stc.xyz /= stc.w; - stc.z += shadow_bias * bias_mul* 2.0; - stc.x = floor(stc.x*shadow_res.x + fract(stc.y*pos_screen.y*pos_screen.x))/shadow_res.x; // add some chaotic jitter to X sample pos according to Y to disguise the snapping going on here + stc.z += shadow_bias * bias_mul * 2.0; + stc.x = floor(stc.x*shadow_res.x + fract(stc.y*shadow_res.y))/shadow_res.x; // add some chaotic jitter to X sample pos according to Y to disguise the snapping going on here float cs = shadow2D(shadowMap, stc.xyz).x; float shadow = cs * 4.0; @@ -90,7 +90,9 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) dp_directional_light = clamp(dp_directional_light, 0.0, 1.0); vec3 shadow_pos = pos.xyz; - vec3 offset = abs(light_dir.xyz) * (1.0 - dp_directional_light* 0.8); + + vec3 offset = light_dir.xyz * (1.0 - dp_directional_light); + shadow_pos += offset * shadow_offset; vec4 spos = vec4(shadow_pos.xyz, 1.0); @@ -109,7 +111,7 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) float w = 1.0; w -= max(spos.z-far_split.z, 0.0)/transition_domain.z; - shadow += pcfShadow(shadowMap3, norm, lpos, 4.0, pos_screen, light_dir)*w; + shadow += pcfShadow(shadowMap3, norm, lpos, 1.0, pos_screen, light_dir)*w; weight += w; shadow += max((pos.z+shadow_clip.z)/(shadow_clip.z-shadow_clip.w)*2.0-1.0, 0.0); } @@ -121,7 +123,7 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) float w = 1.0; w -= max(spos.z-far_split.y, 0.0)/transition_domain.y; w -= max(near_split.z-spos.z, 0.0)/transition_domain.z; - shadow += pcfShadow(shadowMap2, norm, lpos, 2.0, pos_screen, light_dir)*w; + shadow += pcfShadow(shadowMap2, norm, lpos, 1.0, pos_screen, light_dir)*w; weight += w; } @@ -153,6 +155,7 @@ float sampleDirectionalShadow(vec3 pos, vec3 norm, vec2 pos_screen) { return 1.0f; // lit beyond the far split... } + shadow = min(dp_directional_light,shadow); return shadow; } diff --git a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl index 8bc9add5cf..7fd4d7e248 100644 --- a/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl +++ b/indra/newview/app_settings/shaders/class2/deferred/softenLightF.glsl @@ -90,17 +90,16 @@ void main() vec4 norm = texture2DRect(normalMap, tc); float envIntensity = norm.z; norm.xyz = getNorm(tc); // unpack norm - - float da_sun = dot(norm.xyz, sun_dir.xyz); - float da_moon = dot(norm.xyz, moon_dir.xyz); - float da = (sun_up_factor == 1) ? da_sun : da_moon; - da = clamp(da, 0.0, 1.0); - da = pow(da, global_gamma + 0.3); + vec3 light_dir = (sun_up_factor == 1) ? sun_dir : moon_dir; + + float da = dot(norm.xyz, light_dir.xyz); + da = clamp(da, 0.0, 1.0); vec4 diffuse = texture2DRect(diffuseRect, tc); vec3 col; + float scol = 1.0; float bloom = 0.0; { vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy); @@ -108,9 +107,13 @@ void main() vec2 scol_ambocc = texture2DRect(lightMap, vary_fragcoord.xy).rg; scol_ambocc = pow(scol_ambocc, vec2(global_gamma + 0.3)); - float scol = max(scol_ambocc.r, diffuse.a); + scol = max(scol_ambocc.r, diffuse.a); float ambocc = scol_ambocc.g; + float final_da = da; + final_da = min(final_da, scol); + final_da = pow(final_da, global_gamma + 0.3); + vec3 sunlit; vec3 amblit; vec3 additive; @@ -118,18 +121,17 @@ void main() calcFragAtmospherics(pos.xyz, ambocc, sunlit, amblit, additive, atten); - float ambient = da; - + float ambient = min(da, 1.0); ambient *= 0.5; ambient *= ambient; - ambient = (1.0-ambient); - - col.rgb = amblit; - col.rgb *= min(ambient, max(scol, 0.5)); + ambient = min(1.0 - ambient,max(scol,0.3)); - col += sunlit * da * scol; + vec3 sun_contrib = sunlit * final_da; - col *= diffuse.rgb; + col.rgb = amblit; + col.rgb *= ambient; + col.rgb += sun_contrib; + col.rgb *= diffuse.rgb; vec3 refnormpersp = normalize(reflect(pos.xyz, norm.xyz)); @@ -165,9 +167,6 @@ void main() col = fogged.rgb; bloom = fogged.a; #endif - -//col.rgb = vec3(scol); -//col.rgb = vec3(da * scol); } frag_color.rgb = col; frag_color.a = bloom; diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index 490738d304..b6e35fb6ea 100644 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -8497,8 +8497,12 @@ void LLPipeline::bindDeferredShader(LLGLSLShader& shader, LLRenderTarget* light_ shader.uniform1f(LLShaderMgr::DEFERRED_DEPTH_CUTOFF, RenderEdgeDepthCutoff); shader.uniform1f(LLShaderMgr::DEFERRED_NORM_CUTOFF, RenderEdgeNormCutoff); + shader.uniform4fv(LLShaderMgr::SUNLIGHT_COLOR, 1, mSunDiffuse.mV); + shader.uniform4fv(LLShaderMgr::MOONLIGHT_COLOR, 1, mMoonDiffuse.mV); + LLEnvironment& environment = LLEnvironment::instance(); shader.uniform1i(LLShaderMgr::SUN_UP_FACTOR, environment.getIsSunUp() ? 1 : 0); + shader.uniform1f(LLShaderMgr::SUN_MOON_GLOW_FACTOR, environment.getCurrentSky()->getSunMoonGlowFactor()); if (shader.getUniformLocation(LLShaderMgr::DEFERRED_NORM_MATRIX) >= 0) { @@ -8591,6 +8595,7 @@ void LLPipeline::renderDeferredLighting(LLRenderTarget* screen_target) mTransformedSunDir.set(tc.v); glh::vec4f tc_moon(mMoonDir.mV); + mat.mult_matrix_vec(tc_moon); mTransformedMoonDir.set(tc_moon.v); gGL.pushMatrix(); -- cgit v1.2.3