diff options
author | Graham Linden <graham@lindenlab.com> | 2018-12-06 10:59:11 -0800 |
---|---|---|
committer | Graham Linden <graham@lindenlab.com> | 2018-12-06 10:59:11 -0800 |
commit | 7e9033821a96a9d6e80b58fafb4c7da63807b9d4 (patch) | |
tree | d1c267539a601f2b000e1ad9f6f252ad3c5fe77c /indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl | |
parent | 26c1430a04de585c1823569b60dc99abc798231b (diff) |
De-duplicate deferred gbuffer access for getPosition/getNorm.
De-duplicate ambient occlusion shader code and move to new aoUtil.glsl
Split shared shadow tap funcs into shadowUtil.glsl
Diffstat (limited to 'indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl')
-rw-r--r-- | indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl | 125 |
1 files changed, 56 insertions, 69 deletions
diff --git a/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl index b56abb66d1..868eec3926 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/blurLightF.glsl @@ -48,82 +48,69 @@ VARYING vec2 vary_fragcoord; uniform mat4 inv_proj; uniform vec2 screen_res; -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); +vec3 getNorm(vec2 pos_screen); vec3 decode_normal (vec2 enc); void main() { vec2 tc = vary_fragcoord.xy; - vec3 norm = texture2DRect(normalMap, tc).xyz; - norm = decode_normal(norm.xy); // unpack norm - - vec3 pos = getPosition(tc).xyz; - vec4 ccol = texture2DRect(lightMap, tc).rgba; - - vec2 dlt = kern_scale * delta / (1.0+norm.xy*norm.xy); - dlt /= max(-pos.z*dist_factor, 1.0); - - vec2 defined_weight = kern[0].xy; // special case the first (centre) sample's weight in the blur; we have to sample it anyway so we get it for 'free' - vec4 col = defined_weight.xyxx * ccol; - - // relax tolerance according to distance to avoid speckling artifacts, as angles and distances are a lot more abrupt within a small screen area at larger distances - float pointplanedist_tolerance_pow2 = pos.z*pos.z*0.00005; - - // perturb sampling origin slightly in screen-space to hide edge-ghosting artifacts where smoothing radius is quite large - float tc_mod = 0.5*(tc.x + tc.y); // mod(tc.x+tc.y,2) - tc_mod -= floor(tc_mod); - tc_mod *= 2.0; - tc += ( (tc_mod - 0.5) * kern[1].z * dlt * 0.5 ); - - for (int i = 1; i < 4; i++) - { - vec2 samptc = tc + kern[i].z*dlt; - vec3 samppos = getPosition(samptc).xyz; - - float d = dot(norm.xyz, samppos.xyz-pos.xyz);// dist from plane - - if (d*d <= pointplanedist_tolerance_pow2) - { - col += texture2DRect(lightMap, samptc)*kern[i].xyxx; - defined_weight += kern[i].xy; - } - } - - for (int i = 1; i < 4; i++) - { - vec2 samptc = tc - kern[i].z*dlt; - vec3 samppos = getPosition(samptc).xyz; - - float d = dot(norm.xyz, samppos.xyz-pos.xyz);// dist from plane - - if (d*d <= pointplanedist_tolerance_pow2) - { - col += texture2DRect(lightMap, samptc)*kern[i].xyxx; - defined_weight += kern[i].xy; - } - } - - col /= defined_weight.xyxx; - col.y *= col.y; - - frag_color = col; + vec3 norm = getNorm(tc); + vec3 pos = getPosition(tc).xyz; + vec4 ccol = texture2DRect(lightMap, tc).rgba; + + vec2 dlt = kern_scale * delta / (1.0+norm.xy*norm.xy); + dlt /= max(-pos.z*dist_factor, 1.0); + + vec2 defined_weight = kern[0].xy; // special case the first (centre) sample's weight in the blur; we have to sample it anyway so we get it for 'free' + vec4 col = defined_weight.xyxx * ccol; + + // relax tolerance according to distance to avoid speckling artifacts, as angles and distances are a lot more abrupt within a small screen area at larger distances + float pointplanedist_tolerance_pow2 = pos.z*pos.z*0.00005; + + // perturb sampling origin slightly in screen-space to hide edge-ghosting artifacts where smoothing radius is quite large + float tc_mod = 0.5*(tc.x + tc.y); // mod(tc.x+tc.y,2) + tc_mod -= floor(tc_mod); + tc_mod *= 2.0; + tc += ( (tc_mod - 0.5) * kern[1].z * dlt * 0.5 ); + + for (int i = 1; i < 4; i++) + { + vec2 samptc = tc + kern[i].z*dlt; + vec3 samppos = getPosition(samptc).xyz; + + float d = dot(norm.xyz, samppos.xyz-pos.xyz);// dist from plane + + if (d*d <= pointplanedist_tolerance_pow2) + { + col += texture2DRect(lightMap, samptc)*kern[i].xyxx; + defined_weight += kern[i].xy; + } + } + + for (int i = 1; i < 4; i++) + { + vec2 samptc = tc - kern[i].z*dlt; + vec3 samppos = getPosition(samptc).xyz; + + float d = dot(norm.xyz, samppos.xyz-pos.xyz);// dist from plane + + if (d*d <= pointplanedist_tolerance_pow2) + { + col += texture2DRect(lightMap, samptc)*kern[i].xyxx; + defined_weight += kern[i].xy; + } + } + + col /= defined_weight.xyxx; + col.y *= col.y; + + frag_color = col; #ifdef IS_AMD_CARD - // If it's AMD make sure the GLSL compiler sees the arrays referenced once by static index. Otherwise it seems to optimise the storage awawy which leads to unfun crashes and artifacts. - vec3 dummy1 = kern[0]; - vec3 dummy2 = kern[3]; + // If it's AMD make sure the GLSL compiler sees the arrays referenced once by static index. Otherwise it seems to optimise the storage awawy which leads to unfun crashes and artifacts. + vec3 dummy1 = kern[0]; + vec3 dummy2 = kern[3]; #endif } |