From 51bb3c15c8ac6c85ed1a7e8526ba6b60794ac29e Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Thu, 19 May 2011 20:38:39 -0500 Subject: SH-469 WIP -- get rid of LLMultiSampleBuffer and use GL_ARB_texture_multisample instead. --- .../shaders/class1/deferred/pointLightMSF.glsl | 100 +++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 indra/newview/app_settings/shaders/class1/deferred/pointLightMSF.glsl (limited to 'indra/newview/app_settings/shaders/class1/deferred/pointLightMSF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/pointLightMSF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pointLightMSF.glsl new file mode 100644 index 0000000000..22ed9dcd40 --- /dev/null +++ b/indra/newview/app_settings/shaders/class1/deferred/pointLightMSF.glsl @@ -0,0 +1,100 @@ +/** + * @file pointLightF.glsl + * + * $LicenseInfo:firstyear=2007&license=viewerlgpl$ + * $/LicenseInfo$ + */ + + #version 120 + +#extension GL_ARB_texture_rectangle : enable + +uniform sampler2DRect diffuseRect; +uniform sampler2DRect specularRect; +uniform sampler2DRect normalMap; +uniform samplerCube environmentMap; +uniform sampler2D noiseMap; +uniform sampler2D lightFunc; +uniform sampler2DRect depthMap; + +uniform vec3 env_mat[3]; +uniform float sun_wash; + +varying vec4 vary_light; + +varying vec4 vary_fragcoord; +uniform vec2 screen_res; + +uniform mat4 inv_proj; +uniform vec4 viewport; + +vec4 getPosition(vec2 pos_screen) +{ + float depth = texture2DRect(depthMap, pos_screen.xy).a; + vec2 sc = (pos_screen.xy-viewport.xy)*2.0; + sc /= viewport.zw; + 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; +} + +void main() +{ + vec4 frag = vary_fragcoord; + frag.xyz /= frag.w; + frag.xyz = frag.xyz*0.5+0.5; + frag.xy *= screen_res; + + vec3 pos = getPosition(frag.xy).xyz; + vec3 lv = vary_light.xyz-pos; + float dist2 = dot(lv,lv); + dist2 /= vary_light.w; + if (dist2 > 1.0) + { + discard; + } + + vec3 norm = texture2DRect(normalMap, frag.xy).xyz; + norm = vec3((norm.xy-0.5)*2.0,norm.z); // unpack norm + float da = dot(norm, lv); + if (da < 0.0) + { + discard; + } + + norm = normalize(norm); + lv = normalize(lv); + da = dot(norm, lv); + + float noise = texture2D(noiseMap, frag.xy/128.0).b; + + vec3 col = texture2DRect(diffuseRect, frag.xy).rgb; + float fa = gl_Color.a+1.0; + float dist_atten = clamp(1.0-(dist2-1.0*(1.0-fa))/fa, 0.0, 1.0); + float lit = da * dist_atten * noise; + + col = gl_Color.rgb*lit*col; + + vec4 spec = texture2DRect(specularRect, frag.xy); + if (spec.a > 0.0) + { + float sa = dot(normalize(lv-normalize(pos)),norm); + if (sa > 0.0) + { + sa = texture2D(lightFunc, vec2(sa, spec.a)).a * min(dist_atten*4.0, 1.0); + sa *= noise; + col += da*sa*gl_Color.rgb*spec.rgb; + } + } + + if (dot(col, col) <= 0.0) + { + discard; + } + + gl_FragColor.rgb = col; + gl_FragColor.a = 0.0; +} -- cgit v1.2.3 From 4353eeb9288c95b98935e60928ec0b80de4e6145 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 24 May 2011 15:29:33 -0500 Subject: SH-469 GL_ARB_texture_multisample support --- .../shaders/class1/deferred/pointLightMSF.glsl | 96 ++++++++++++---------- 1 file changed, 52 insertions(+), 44 deletions(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/pointLightMSF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/pointLightMSF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pointLightMSF.glsl index 22ed9dcd40..23b5e76735 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pointLightMSF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pointLightMSF.glsl @@ -8,14 +8,15 @@ #version 120 #extension GL_ARB_texture_rectangle : enable +#extension GL_ARB_texture_multisample : enable -uniform sampler2DRect diffuseRect; -uniform sampler2DRect specularRect; -uniform sampler2DRect normalMap; -uniform samplerCube environmentMap; +uniform sampler2DMS depthMap; +uniform sampler2DMS diffuseRect; +uniform sampler2DMS specularRect; +uniform sampler2DMS normalMap; uniform sampler2D noiseMap; uniform sampler2D lightFunc; -uniform sampler2DRect depthMap; + uniform vec3 env_mat[3]; uniform float sun_wash; @@ -28,10 +29,10 @@ uniform vec2 screen_res; uniform mat4 inv_proj; uniform vec4 viewport; -vec4 getPosition(vec2 pos_screen) +vec4 getPosition(ivec2 pos_screen, int sample) { - float depth = texture2DRect(depthMap, pos_screen.xy).a; - vec2 sc = (pos_screen.xy-viewport.xy)*2.0; + float depth = texelFetch(depthMap, pos_screen, sample).r; + vec2 sc = (vec2(pos_screen.xy)-viewport.xy)*2.0; sc /= viewport.zw; sc -= vec2(1.0,1.0); vec4 ndc = vec4(sc.x, sc.y, 2.0*depth-1.0, 1.0); @@ -48,53 +49,60 @@ void main() frag.xyz = frag.xyz*0.5+0.5; frag.xy *= screen_res; - vec3 pos = getPosition(frag.xy).xyz; - vec3 lv = vary_light.xyz-pos; - float dist2 = dot(lv,lv); - dist2 /= vary_light.w; - if (dist2 > 1.0) - { - discard; - } - - vec3 norm = texture2DRect(normalMap, frag.xy).xyz; - norm = vec3((norm.xy-0.5)*2.0,norm.z); // unpack norm - float da = dot(norm, lv); - if (da < 0.0) + ivec2 itc = ivec2(frag.xy); + + int wght = 0; + vec3 fcol = vec3(0,0,0); + + for (int s = 0; s < samples; ++s) { - discard; - } - - norm = normalize(norm); - lv = normalize(lv); - da = dot(norm, lv); + vec3 pos = getPosition(itc, s).xyz; + vec3 lv = vary_light.xyz-pos; + float dist2 = dot(lv,lv); + dist2 /= vary_light.w; + if (dist2 <= 1.0) + { + vec3 norm = texelFetch(normalMap, itc, s).xyz; + norm = vec3((norm.xy-0.5)*2.0,norm.z); // unpack norm + float da = dot(norm, lv); + if (da >= 0.0) + { + norm = normalize(norm); + lv = normalize(lv); + da = dot(norm, lv); - float noise = texture2D(noiseMap, frag.xy/128.0).b; + float noise = texture2D(noiseMap, frag.xy/128.0).b; - vec3 col = texture2DRect(diffuseRect, frag.xy).rgb; - float fa = gl_Color.a+1.0; - float dist_atten = clamp(1.0-(dist2-1.0*(1.0-fa))/fa, 0.0, 1.0); - float lit = da * dist_atten * noise; + vec3 col = texelFetch(diffuseRect, itc, s).rgb; + float fa = gl_Color.a+1.0; + float dist_atten = clamp(1.0-(dist2-1.0*(1.0-fa))/fa, 0.0, 1.0); + float lit = da * dist_atten * noise; - col = gl_Color.rgb*lit*col; + col = gl_Color.rgb*lit*col; - vec4 spec = texture2DRect(specularRect, frag.xy); - if (spec.a > 0.0) - { - float sa = dot(normalize(lv-normalize(pos)),norm); - if (sa > 0.0) - { - sa = texture2D(lightFunc, vec2(sa, spec.a)).a * min(dist_atten*4.0, 1.0); - sa *= noise; - col += da*sa*gl_Color.rgb*spec.rgb; + vec4 spec = texelFetch(specularRect, itc, s); + if (spec.a > 0.0) + { + float sa = dot(normalize(lv-normalize(pos)),norm); + if (sa > 0.0) + { + sa = texture2D(lightFunc, vec2(sa, spec.a)).a * min(dist_atten*4.0, 1.0); + sa *= noise; + col += da*sa*gl_Color.rgb*spec.rgb; + } + } + + fcol += col; + ++wght; + } } } - if (dot(col, col) <= 0.0) + if (wght <= 0) { discard; } - gl_FragColor.rgb = col; + gl_FragColor.rgb = fcol/wght; gl_FragColor.a = 0.0; } -- cgit v1.2.3 From 9eea451a82379a61fa4a6cc2a55274e06cecbd58 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 25 May 2011 15:51:15 -0500 Subject: SH-469 Don't use depth buffers and multisample buffers where not absolutely needed -- make sample counts consistent between shaders and render targets. --- indra/newview/app_settings/shaders/class1/deferred/pointLightMSF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/pointLightMSF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/pointLightMSF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pointLightMSF.glsl index 23b5e76735..7521c3310c 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pointLightMSF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pointLightMSF.glsl @@ -103,6 +103,6 @@ void main() discard; } - gl_FragColor.rgb = fcol/wght; + gl_FragColor.rgb = fcol/samples; gl_FragColor.a = 0.0; } -- cgit v1.2.3 From ece32418e7c1828a65c88e526a5afcb635c5453a Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 31 May 2011 14:35:59 -0500 Subject: SH-1682 Dynamically adjust the number of texture channels to use for indexed texture rendering based on available hardware. --- indra/newview/app_settings/shaders/class1/deferred/pointLightMSF.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/app_settings/shaders/class1/deferred/pointLightMSF.glsl') diff --git a/indra/newview/app_settings/shaders/class1/deferred/pointLightMSF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pointLightMSF.glsl index 7521c3310c..feaf38115d 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/pointLightMSF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/pointLightMSF.glsl @@ -5,7 +5,7 @@ * $/LicenseInfo$ */ - #version 120 + #extension GL_ARB_texture_rectangle : enable #extension GL_ARB_texture_multisample : enable -- cgit v1.2.3