diff --git a/Compositor/HDR/csm-pass.xml b/Compositor/HDR/csm-pass.xml index a76086875..1c1a25a6e 100644 --- a/Compositor/HDR/csm-pass.xml +++ b/Compositor/HDR/csm-pass.xml @@ -6,7 +6,7 @@ hdr-shadow depth - 0x000004 + 0x4 false sun-shadowmap-atlas diff --git a/Compositor/HDR/env-capture-pass.xml b/Compositor/HDR/env-capture-pass.xml index 45c23512e..9a312cd2a 100644 --- a/Compositor/HDR/env-capture-pass.xml +++ b/Compositor/HDR/env-capture-pass.xml @@ -3,10 +3,9 @@ scene hdr-envmap - depth - 0x801 + 0x800 11 sky-view diff --git a/Compositor/HDR/env-prefilter1-pass.xml b/Compositor/HDR/env-prefilter1-pass.xml deleted file mode 100644 index d0678a789..000000000 --- a/Compositor/HDR/env-prefilter1-pass.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - Effects/HDR/envmap-prefilter1 - diff --git a/Compositor/HDR/env-prefilter2-pass.xml b/Compositor/HDR/env-prefilter2-pass.xml deleted file mode 100644 index c2d0425db..000000000 --- a/Compositor/HDR/env-prefilter2-pass.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - Effects/HDR/envmap-prefilter2 - diff --git a/Compositor/HDR/env-prefilter3-pass.xml b/Compositor/HDR/env-prefilter3-pass.xml deleted file mode 100644 index 11bd3b185..000000000 --- a/Compositor/HDR/env-prefilter3-pass.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - Effects/HDR/envmap-prefilter3 - diff --git a/Compositor/HDR/env-prefilter4-pass.xml b/Compositor/HDR/env-prefilter4-pass.xml deleted file mode 100644 index 9e8ad4a4b..000000000 --- a/Compositor/HDR/env-prefilter4-pass.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - Effects/HDR/envmap-prefilter4 - diff --git a/Compositor/HDR/hdr.xml b/Compositor/HDR/hdr.xml index 6acb92a76..badef3b72 100644 --- a/Compositor/HDR/hdr.xml +++ b/Compositor/HDR/hdr.xml @@ -315,244 +315,164 @@ Diffuse lighting is approximated by using the highest mipmap level (roughness=1). --> - - env-prefilter1-0 - 0 + + env-prefilter1 + Effects/HDR/envmap-prefilter1 color0 envmap 0 1 - - - env-prefilter1-1 - 1 - color0 + color1 envmap 1 1 - - - env-prefilter1-2 - 2 - color0 + color2 envmap 2 1 - - - env-prefilter1-3 - 3 - color0 + color3 envmap 3 1 - - - env-prefilter1-4 - 4 - color0 + color4 envmap 4 1 - - - env-prefilter1-5 - 5 - color0 + color5 envmap 5 1 - - env-prefilter2-0 - 0 + + env-prefilter2 + Effects/HDR/envmap-prefilter2 color0 envmap 0 2 - - - env-prefilter2-1 - 1 - color0 + color1 envmap 1 2 - - - env-prefilter2-2 - 2 - color0 + color2 envmap 2 2 - - - env-prefilter2-3 - 3 - color0 + color3 envmap 3 2 - - - env-prefilter2-4 - 4 - color0 + color4 envmap 4 2 - - - env-prefilter2-5 - 5 - color0 + color5 envmap 5 2 - - env-prefilter3-0 - 0 + + env-prefilter3 + Effects/HDR/envmap-prefilter3 color0 envmap 0 3 - - - env-prefilter3-1 - 1 - color0 + color1 envmap 1 3 - - - env-prefilter3-2 - 2 - color0 + color2 envmap 2 3 - - - env-prefilter3-3 - 3 - color0 + color3 envmap 3 3 - - - env-prefilter3-4 - 4 - color0 + color4 envmap 4 3 - - - env-prefilter3-5 - 5 - color0 + color5 envmap 5 3 - - env-prefilter4-0 - 0 + + env-prefilter4 + Effects/HDR/envmap-prefilter4 color0 envmap 0 4 - - - env-prefilter4-1 - 1 - color0 + color1 envmap 1 4 - - - env-prefilter4-2 - 2 - color0 + color2 envmap 2 4 - - - env-prefilter4-3 - 3 - color0 + color3 envmap 3 4 - - - env-prefilter4-4 - 4 - color0 + color4 envmap 4 4 - - - env-prefilter4-5 - 5 - color0 + color5 envmap 5 4 diff --git a/Effects/HDR/envmap-prefilter.eff b/Effects/HDR/envmap-prefilter.eff index 8452081c0..34b7df500 100644 --- a/Effects/HDR/envmap-prefilter.eff +++ b/Effects/HDR/envmap-prefilter.eff @@ -7,7 +7,7 @@ - Shaders/HDR/trivial-cubemap.vert + Shaders/HDR/envmap-prefilter.vert Shaders/HDR/envmap-prefilter.frag diff --git a/Shaders/HDR/envmap-prefilter.frag b/Shaders/HDR/envmap-prefilter.frag index 43fe70364..85183bdbd 100644 --- a/Shaders/HDR/envmap-prefilter.frag +++ b/Shaders/HDR/envmap-prefilter.frag @@ -1,8 +1,18 @@ #version 330 core -out vec3 fragColor; +layout(location = 0) out vec3 fragColor0; +layout(location = 1) out vec3 fragColor1; +layout(location = 2) out vec3 fragColor2; +layout(location = 3) out vec3 fragColor3; +layout(location = 4) out vec3 fragColor4; +layout(location = 5) out vec3 fragColor5; -in vec3 cubemapCoord; +in vec3 cubemapCoord0; +in vec3 cubemapCoord1; +in vec3 cubemapCoord2; +in vec3 cubemapCoord3; +in vec3 cubemapCoord4; +in vec3 cubemapCoord5; uniform samplerCube envmap; uniform float roughness; @@ -10,6 +20,7 @@ uniform float roughness; uniform int fg_CubemapFace; const float PI = 3.14159265359; +const uint NUM_SAMPLES = 64u; float RadicalInverse_VdC(uint bits) { @@ -47,14 +58,13 @@ vec3 ImportanceSampleGGX(vec2 Xi, vec3 n, float r) return normalize(sampleVec); } -void main() +vec3 prefilter(vec3 n) { - vec3 n = normalize(cubemapCoord); + n = normalize(n); vec3 v = n; // n = v simplification vec3 prefilteredColor = vec3(0.0); float totalWeight = 0.0; - const uint NUM_SAMPLES = 1024u; for (uint i = 0u; i < NUM_SAMPLES; ++i) { vec2 Xi = Hammersley(i, NUM_SAMPLES); @@ -69,6 +79,15 @@ void main() } prefilteredColor /= totalWeight; - - fragColor = prefilteredColor; + return prefilteredColor; +} + +void main() +{ + fragColor0 = prefilter(cubemapCoord0); + fragColor1 = prefilter(cubemapCoord1); + fragColor2 = prefilter(cubemapCoord2); + fragColor3 = prefilter(cubemapCoord3); + fragColor4 = prefilter(cubemapCoord4); + fragColor5 = prefilter(cubemapCoord5); } diff --git a/Shaders/HDR/envmap-prefilter.vert b/Shaders/HDR/envmap-prefilter.vert new file mode 100644 index 000000000..039ccba2d --- /dev/null +++ b/Shaders/HDR/envmap-prefilter.vert @@ -0,0 +1,29 @@ +#version 330 core + +layout(location = 0) in vec4 pos; +layout(location = 3) in vec4 multiTexCoord0; + +out vec3 cubemapCoord0; +out vec3 cubemapCoord1; +out vec3 cubemapCoord2; +out vec3 cubemapCoord3; +out vec3 cubemapCoord4; +out vec3 cubemapCoord5; + +uniform mat4 osg_ModelViewProjectionMatrix; + +void main() +{ + gl_Position = osg_ModelViewProjectionMatrix * pos; + vec2 texCoord = multiTexCoord0.xy * 2.0 - 1.0; + // Map the quad texture coordinates to a direction vector to sample + // the cubemap. This assumes that we are using the weird left-handed + // orientations given by the OpenGL spec. + // See https://www.khronos.org/opengl/wiki/Cubemap_Texture#Upload_and_orientation + cubemapCoord0 = vec3(1.0, -texCoord.y, -texCoord.x); + cubemapCoord1 = vec3(-1.0, -texCoord.y, texCoord.x); + cubemapCoord2 = vec3(texCoord.x, 1.0, texCoord.y); + cubemapCoord3 = vec3(texCoord.x, -1.0, -texCoord.y); + cubemapCoord4 = vec3(texCoord.x, -texCoord.y, 1.0); + cubemapCoord5 = vec3(-texCoord.x, -texCoord.y, -1.0); +}