diff options
author | Ptolemy <ptolemy@lindenlab.com> | 2022-07-14 18:12:19 -0700 |
---|---|---|
committer | Ptolemy <ptolemy@lindenlab.com> | 2022-07-14 18:12:19 -0700 |
commit | 32efb52cd1d7b3f4907efb1b4f8dc151e8a1a5d0 (patch) | |
tree | 2dd72d172e73237d6aea6db88d722ad0d2c2ca29 /indra/newview/app_settings/shaders/class1/deferred | |
parent | 2e1c9046dc48208c5bc86dfec8c7d4f0fc294b48 (diff) |
SL-17764: PBR: Add light shaders to class 3 deferred
Diffstat (limited to 'indra/newview/app_settings/shaders/class1/deferred')
-rw-r--r-- | indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl index e27bbce094..5dfdd2006e 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl @@ -29,6 +29,13 @@ uniform sampler2DRect depthMap; uniform mat4 inv_proj; uniform vec2 screen_res; +void calcHalfVectors(vec3 h, vec3 n, vec3 v, out float nh, out float nv, out float vh) +{ + nh = dot(n, h); + nv = dot(n, v); + vh = dot(v, h); +} + vec2 getScreenCoordinate(vec2 screenpos) { vec2 sc = screenpos.xy * 2.0; @@ -39,6 +46,8 @@ vec2 getScreenCoordinate(vec2 screenpos) return sc - vec2(1.0, 1.0); } +// See: https://aras-p.info/texts/CompactNormalStorage.html +// Method #4: Spheremap Transform, Lambert Azimuthal Equal-Area projection vec3 getNorm(vec2 screenpos) { vec2 enc = texture2DRect(normalMap, screenpos.xy).xy; @@ -51,6 +60,28 @@ vec3 getNorm(vec2 screenpos) return n; } +vec3 getNormalFromPacked(vec4 packedNormalEnvIntensityFlags) +{ + vec2 enc = packedNormalEnvIntensityFlags.xy; + vec2 fenc = enc*4-2; + float f = dot(fenc,fenc); + float g = sqrt(1-f/4); + vec3 n; + n.xy = fenc*g; + n.z = 1-f/2; + return normalize(n); // TODO: Is this normalize redundant? +} + +// return packedNormalEnvIntensityFlags since GBUFFER_FLAG_HAS_PBR needs .w +// See: C++: addDeferredAttachments(), GLSL: softenLightF +vec4 getNormalEnvIntensityFlags(vec2 screenpos, out vec3 n, out float envIntensity) +{ + vec4 packedNormalEnvIntensityFlags = texture2DRect(normalMap, screenpos.xy); + n = getNormalFromPacked( packedNormalEnvIntensityFlags ); + envIntensity = packedNormalEnvIntensityFlags.z; + return packedNormalEnvIntensityFlags; +} + float getDepth(vec2 pos_screen) { float depth = texture2DRect(depthMap, pos_screen).r; @@ -77,3 +108,15 @@ vec4 getPositionWithDepth(vec2 pos_screen, float depth) pos.w = 1.0; return pos; } + +vec2 getScreenXY(vec4 clip) +{ + vec4 ndc = clip; + ndc.xyz /= clip.w; + vec2 screen = vec2( ndc.xy * 0.5 ); + screen += 0.5; + screen *= screen_res; + return screen; +} + +// PBR Utils |