diff options
author | Jonathan "Geenz" Goodman <geenz@geenzo.com> | 2024-02-26 04:02:09 -0800 |
---|---|---|
committer | Jonathan "Geenz" Goodman <geenz@geenzo.com> | 2024-02-26 04:02:09 -0800 |
commit | b3283036af886de56f45c731ab21e2b16383a770 (patch) | |
tree | d3b72ecd079a07e59a317d8340fab40ede98d9ee /indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl | |
parent | 4ed5b59a601cfc58c3d5a5d4c1b56d4cdc73be2c (diff) |
#681 Start adding blending boilerplate.
Diffstat (limited to 'indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl')
-rw-r--r-- | indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl | 71 |
1 files changed, 68 insertions, 3 deletions
diff --git a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl index 4f6e01764a..14d9cf798f 100644 --- a/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl +++ b/indra/newview/app_settings/shaders/class3/deferred/reflectionProbeF.glsl @@ -686,17 +686,82 @@ vec3 sampleProbeAmbient(vec3 pos, vec3 dir, vec3 amblit) #if defined(HERO_PROBES) uniform vec4 clipPlane; -uniform samplerCubeArray heroProbes; + +uniform samplerCubeArray heroProbes; + +layout (std140) uniform HeroProbeData +{ + mat4 heroBox[1]; + vec4 heroSphere[1]; + uint heroShape[1]; + int heroMipCount; + int heroProbeCount; +}; + +vec3 boxIntersectHero(vec3 origin, vec3 dir, int i, out float d, float scale) +{ + // Intersection with OBB convert to unit box space + // Transform in local unit parallax cube space (scaled and rotated) + mat4 clipToLocal = heroBox[i]; + + vec3 RayLS = mat3(clipToLocal) * dir; + vec3 PositionLS = (clipToLocal * vec4(origin, 1.0)).xyz; + + d = 1.0-max(max(abs(PositionLS.x), abs(PositionLS.y)), abs(PositionLS.z)); + + vec3 Unitary = vec3(scale); + vec3 FirstPlaneIntersect = (Unitary - PositionLS) / RayLS; + vec3 SecondPlaneIntersect = (-Unitary - PositionLS) / RayLS; + vec3 FurthestPlane = max(FirstPlaneIntersect, SecondPlaneIntersect); + float Distance = min(FurthestPlane.x, min(FurthestPlane.y, FurthestPlane.z)); + + // Use Distance in CS directly to recover intersection + vec3 IntersectPositionCS = origin + dir * Distance; + + return IntersectPositionCS; +} + +float sphereWeightHero(vec3 pos, vec3 dir, vec3 origin, float r, out float dw) +{ + float r1 = r * 0.5; // 50% of radius (outer sphere to start interpolating down) + vec3 delta = pos.xyz - origin; + float d2 = max(length(delta), 0.001); + + float atten = 1.0 - max(d2 - r1, 0.0) / max((r - r1), 0.001); + float w = 1.0 / d2; + + dw = w * atten * max(r, 1.0)*4; + + w *= atten; + + return w; +} void tapHeroProbe(inout vec3 glossenv, vec3 pos, vec3 norm, float glossiness) { float clipDist = dot(pos.xyz, clipPlane.xyz) + clipPlane.w; - if (clipDist > 0.0 && clipDist < 0.1 && glossiness > 0.8) + float w = 0; + float dw = 0; + if (heroShape[0] < 1) + { + float d = 0; + boxIntersectHero(pos, norm, 0, d, 1.0); + + w = max(d, 0.001); + } + else + { + float r = heroSphere[0].w; + //v = sphereIntersect(pos, norm, heroSphere[0].xyz, 4096.0*4096.0); + + w = sphereWeightHero(pos, norm, heroSphere[0].xyz, r, dw); + } + { vec3 refnormpersp = reflect(pos.xyz, norm.xyz); if (dot(refnormpersp.xyz, clipPlane.xyz) > 0.0) { - glossenv = textureLod(heroProbes, vec4(env_mat * refnormpersp, 0), (1.0-glossiness)*10).xyz; + glossenv = textureLod(heroProbes, vec4(env_mat * refnormpersp, 0), (1.0-glossiness)*heroMipCount).xyz * w; } } } |