diff options
Diffstat (limited to 'indra/newview/app_settings')
6 files changed, 99 insertions, 41 deletions
diff --git a/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl index 1c2034de69..2ec859fdae 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl @@ -179,6 +179,13 @@ vec4 getNormalEnvIntensityFlags(vec2 screenpos, out vec3 n, out float envIntensi return packedNormalEnvIntensityFlags; } +// get linear depth value given a depth buffer sample d and znear and zfar values +float linearDepth(float d, float znear, float zfar) +{ + d = d * 2.0 - 1.0; + return znear * 2.0 * zfar / (zfar + znear - d * (zfar - znear)); +} + float getDepth(vec2 pos_screen) { float depth = texture2DRect(depthMap, pos_screen).r; diff --git a/indra/newview/app_settings/shaders/class1/interface/irradianceGenF.glsl b/indra/newview/app_settings/shaders/class1/interface/irradianceGenF.glsl index 63e2fce40f..b633813819 100644 --- a/indra/newview/app_settings/shaders/class1/interface/irradianceGenF.glsl +++ b/indra/newview/app_settings/shaders/class1/interface/irradianceGenF.glsl @@ -177,10 +177,10 @@ float computeLod(float pdf) return lod; } -vec3 filterColor(vec3 N) +vec4 filterColor(vec3 N) { //return textureLod(uCubeMap, N, 3.0).rgb; - vec3 color = vec3(0.f); + vec4 color = vec4(0.f); float weight = 0.0f; for(int i = 0; i < u_sampleCount; ++i) @@ -198,7 +198,7 @@ vec3 filterColor(vec3 N) lod = clamp(lod, 0, 7); // sample lambertian at a lower resolution to avoid fireflies - vec3 lambertian = textureLod(reflectionProbes, vec4(H, sourceIdx), lod).rgb; + vec4 lambertian = textureLod(reflectionProbes, vec4(H, sourceIdx), lod); color += lambertian; } @@ -212,16 +212,16 @@ vec3 filterColor(vec3 N) color /= float(u_sampleCount); } - return color.rgb ; + return color; } // entry point void main() { - vec3 color = vec3(0); + vec4 color = vec4(0); color = filterColor(vary_dir); - frag_color = vec4(color,1.0); + frag_color = color; } diff --git a/indra/newview/app_settings/shaders/class1/interface/radianceGenF.glsl b/indra/newview/app_settings/shaders/class1/interface/radianceGenF.glsl index bb4a79247d..f4879b52de 100644 --- a/indra/newview/app_settings/shaders/class1/interface/radianceGenF.glsl +++ b/indra/newview/app_settings/shaders/class1/interface/radianceGenF.glsl @@ -26,11 +26,7 @@ /*[EXTRA_CODE_HERE]*/ -#ifdef DEFINE_GL_FRAGCOLOR out vec4 frag_color; -#else -#define frag_color gl_FragColor -#endif uniform samplerCubeArray reflectionProbes; uniform int sourceIdx; @@ -122,11 +118,11 @@ float D_GGX(float dotNH, float roughness) return (alpha2)/(PI * denom*denom); } -vec3 prefilterEnvMap(vec3 R) +vec4 prefilterEnvMap(vec3 R) { vec3 N = R; vec3 V = R; - vec3 color = vec3(0.0); + vec4 color = vec4(0.0); float totalWeight = 0.0; float envMapDim = 256.0; int numSamples = 4; @@ -157,7 +153,7 @@ vec3 prefilterEnvMap(vec3 R) // Biased (+1.0) mip level for better result float mip = roughness == 0.0 ? 0.0 : clamp(0.5 * log2(omegaS / omegaP) + 1.0, 0.0f, 7.f); //float mip = clamp(0.5 * log2(omegaS / omegaP) + 1.0, 0.0f, 7.f); - color += textureLod(reflectionProbes, vec4(L,sourceIdx), mip).rgb * dotNL; + color += textureLod(reflectionProbes, vec4(L,sourceIdx), mip) * dotNL; totalWeight += dotNL; } @@ -168,6 +164,6 @@ vec3 prefilterEnvMap(vec3 R) void main() { vec3 N = normalize(vary_dir); - frag_color = vec4(prefilterEnvMap(N), 1.0); + frag_color = prefilterEnvMap(N); } // ============================================================================================================= diff --git a/indra/newview/app_settings/shaders/class1/interface/reflectionmipF.glsl b/indra/newview/app_settings/shaders/class1/interface/reflectionmipF.glsl index e8452a9c14..9dd97a80b2 100644 --- a/indra/newview/app_settings/shaders/class1/interface/reflectionmipF.glsl +++ b/indra/newview/app_settings/shaders/class1/interface/reflectionmipF.glsl @@ -33,10 +33,20 @@ out vec4 frag_color; #define frag_color gl_FragColor #endif -uniform sampler2DRect screenMap; +// NOTE screenMap should always be texture channel 0 and +// depthmap should always be channel 1 +uniform sampler2DRect diffuseRect; +uniform sampler2DRect depthMap; + +uniform float resScale; +uniform float znear; +uniform float zfar; VARYING vec2 vary_texcoord0; +// get linear depth value given a depth buffer sample d and znear and zfar values +float linearDepth(float d, float znear, float zfar); + void main() { #if 0 @@ -74,6 +84,18 @@ void main() frag_color = vec4(color, 1.0); #else - frag_color = vec4(texture2DRect(screenMap, vary_texcoord0.xy).rgb, 1.0); + vec2 depth_tc = vary_texcoord0.xy * resScale; + float depth = texture(depthMap, depth_tc).r; + float dist = linearDepth(depth, znear, zfar); + + // convert linear depth to distance + vec3 v; + v.xy = depth_tc / 512.0 * 2.0 - 1.0; + v.z = 1.0; + v = normalize(v); + dist /= v.z; + + vec3 col = texture2DRect(diffuseRect, vary_texcoord0.xy).rgb; + frag_color = vec4(col, dist/256.0); #endif } diff --git a/indra/newview/app_settings/shaders/class2/environment/waterF.glsl b/indra/newview/app_settings/shaders/class2/environment/waterF.glsl index 59e7e64fbb..b51583de26 100644 --- a/indra/newview/app_settings/shaders/class2/environment/waterF.glsl +++ b/indra/newview/app_settings/shaders/class2/environment/waterF.glsl @@ -163,7 +163,7 @@ void main() float df1 = df.x + df.y + df.z; - wavef = normalize(wavef + vary_normal); + //wavef = normalize(wavef - vary_normal); //wavef = vary_normal; vec3 waver = reflect(viewVec, -wavef)*3; @@ -194,13 +194,13 @@ void main() vec3 additive; vec3 atten; - calcAtmosphericVarsLinear(pos.xyz, wavef, lightDir, sunlit, amblit, additive, atten); - + calcAtmosphericVarsLinear(pos.xyz, wavef, vary_light_dir, sunlit, amblit, additive, atten); + sunlit = vec3(1); // TODO -- figure out why sunlit is breaking at some view angles vec3 v = -viewVec; float NdotV = clamp(abs(dot(wavef.xyz, v)), 0.001, 1.0); float metallic = fresnelOffset * 0.1; // fudge -- use fresnelOffset as metalness - float roughness = 0.08; + float roughness = 0.1; float gloss = 1.0 - roughness; vec3 baseColor = vec3(0.25); @@ -210,8 +210,8 @@ void main() vec3 specularColor = mix(f0, baseColor.rgb, metallic); - //vec3 refnorm = normalize(wavef + vary_normal); - vec3 refnorm = wavef; + vec3 refnorm = normalize(wavef + vary_normal); + //vec3 refnorm = wavef; vec3 irradiance = vec3(0); @@ -221,7 +221,6 @@ void main() irradiance = fb.rgb; color.rgb = pbrIbl(diffuseColor, specularColor, radiance, irradiance, gloss, NdotV, 0.0); - // fudge -- for punctual lighting, pretend water is metallic diffuseColor = vec3(0); @@ -229,7 +228,7 @@ void main() roughness = 0.1; float scol = 1.0; // TODO -- incorporate shadow map - //color.rgb += pbrPunctual(diffuseColor, specularColor, roughness, metallic, wavef, v, vary_light_dir) * sunlit * 2.75 * scol; + color.rgb += pbrPunctual(diffuseColor, specularColor, roughness, metallic, wavef, v, vary_light_dir) * sunlit * 2.75 * scol; color.rgb = atmosFragLightingLinear(color.rgb, additive, atten); color.rgb = scaleSoftClipFragLinear(color.rgb); @@ -239,6 +238,8 @@ void main() //color.rgb = srgb_to_linear(normalize(refPos) * 0.5 + 0.5); //color.rgb = srgb_to_linear(normalize(pos) * 0.5 + 0.5); //color.rgb = srgb_to_linear(wavef * 0.5 + 0.5); + + //color.rgb = radiance; frag_color = color; #if defined(WATER_EDGE) diff --git a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl index 80f9e29123..ec9218f00e 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl @@ -239,7 +239,7 @@ bool intersect(const Ray &ray) const return true; } */ -// adapted -- assume that origin is inside sphere, return distance from origin to edge of sphere +// adapted -- assume that origin is inside sphere, return intersection of ray with edge of sphere vec3 sphereIntersect(vec3 origin, vec3 dir, vec3 center, float radius2) { float t0, t1; // solutions for t if the ray intersects @@ -310,17 +310,19 @@ vec3 boxIntersect(vec3 origin, vec3 dir, int i) // Tap a reflection probe // pos - position of pixel // dir - pixel normal +// vi - return value of intersection point with influence volume +// wi - return value of approximate world space position of sampled pixel // lod - which mip to bias towards (lower is higher res, sharper reflections) // c - center of probe // r2 - radius of probe squared // i - index of probe -// vi - point at which reflection vector struck the influence volume, in clip space -vec3 tapRefMap(vec3 pos, vec3 dir, float lod, vec3 c, float r2, int i) +vec3 tapRefMap(vec3 pos, vec3 dir, out vec3 vi, out vec3 wi, float lod, vec3 c, float r2, int i) { //lod = max(lod, 1); // parallax adjustment vec3 v; + if (refIndex[i].w < 0) { v = boxIntersect(pos, dir, i); @@ -330,11 +332,18 @@ vec3 tapRefMap(vec3 pos, vec3 dir, float lod, vec3 c, float r2, int i) v = sphereIntersect(pos, dir, c, r2); } + vi = v; + v -= c; + vec3 d = normalize(v); + v = env_mat * v; - { - return textureLod(reflectionProbes, vec4(v.xyz, refIndex[i].x), lod).rgb; - } + + vec4 ret = textureLod(reflectionProbes, vec4(v.xyz, refIndex[i].x), lod); + + wi = d * ret.a * 256.0+c; + + return ret.rgb; } // Tap an irradiance map @@ -343,7 +352,6 @@ vec3 tapRefMap(vec3 pos, vec3 dir, float lod, vec3 c, float r2, int i) // c - center of probe // r2 - radius of probe squared // i - index of probe -// vi - point at which reflection vector struck the influence volume, in clip space vec3 tapIrradianceMap(vec3 pos, vec3 dir, vec3 c, float r2, int i) { //lod = max(lod, 1); @@ -383,26 +391,48 @@ vec3 sampleProbes(vec3 pos, vec3 dir, float lod, float minweight) float p = float(abs(refIndex[i].w)); // priority float rr = r*r; // radius squred - float r1 = r * 0.1; // 75% of radius (outer sphere to start interpolating down) + float r1 = r * 0.1; // 90% of radius (outer sphere to start interpolating down) vec3 delta = pos.xyz-refSphere[i].xyz; float d2 = dot(delta,delta); float r2 = r1*r1; { - vec3 refcol = tapRefMap(pos, dir, lod, refSphere[i].xyz, rr, i); - - float w = 1.0/d2; + vec3 vi, wi; + + vec3 refcol = tapRefMap(pos, dir, vi, wi, lod, refSphere[i].xyz, rr, i); float atten = 1.0-max(d2-r2, 0.0)/(rr-r2); + + if (refIndex[i].w >= 0) + { + //adjust lookup by distance result + float d = length(vi - wi); + vi += dir * d; + + vi -= refSphere[i].xyz; + + vi = env_mat * vi; + + refcol = textureLod(reflectionProbes, vec4(vi, refIndex[i].x), lod).rgb; + } + + //float w = 1.0 / max(d3, 1.0); + vec3 pi = normalize(wi - pos); + float w = max(dot(pi, dir), 0.1); + w = pow(w, 32.0); + w *= atten; + + //w *= p; // boost weight based on priority - col += refcol*w; - + col += refcol.rgb*w; + wsum += w; } } - if (probeInfluences <= 1) +#if 1 + if (probeInfluences < 1) { //edge-of-scene probe or no probe influence, mix in with embiggened version of probes closest to camera for (int idx = 0; idx < 8; ++idx) { @@ -415,15 +445,17 @@ vec3 sampleProbes(vec3 pos, vec3 dir, float lod, float minweight) float d2 = dot(delta,delta); { - vec3 refcol = tapRefMap(pos, dir, lod, refSphere[i].xyz, d2, i); - + vec3 vi, wi; + vec3 refcol = tapRefMap(pos, dir, vi, wi, lod, refSphere[i].xyz, d2, i); + float w = 1.0/d2; w *= w; - col += refcol*w; + col += refcol.rgb*w; wsum += w; } } } +#endif if (wsum > 0.0) { |