diff options
| author | Tim Foley <tfoley@nvidia.com> | 2017-06-09 11:34:21 -0700 |
|---|---|---|
| committer | Tim Foley <tfoley@nvidia.com> | 2017-06-09 13:44:59 -0700 |
| commit | fcf83dbf9effab3bd98bad2b83b2468b7eb05cfd (patch) | |
| tree | 41047c94883b86ec085a81597391ce3ef557cd43 /tests/glsl/sascha-willems/shadowmapping | |
| parent | 52e8d4b9a27ab0060f874c3a63ab531847be35c0 (diff) | |
Initial import of code.
Diffstat (limited to 'tests/glsl/sascha-willems/shadowmapping')
| -rw-r--r-- | tests/glsl/sascha-willems/shadowmapping/offscreen.frag | 14 | ||||
| -rw-r--r-- | tests/glsl/sascha-willems/shadowmapping/offscreen.vert | 23 | ||||
| -rw-r--r-- | tests/glsl/sascha-willems/shadowmapping/quad.frag | 25 | ||||
| -rw-r--r-- | tests/glsl/sascha-willems/shadowmapping/quad.vert | 28 | ||||
| -rw-r--r-- | tests/glsl/sascha-willems/shadowmapping/scene.frag | 72 | ||||
| -rw-r--r-- | tests/glsl/sascha-willems/shadowmapping/scene.vert | 52 |
6 files changed, 214 insertions, 0 deletions
diff --git a/tests/glsl/sascha-willems/shadowmapping/offscreen.frag b/tests/glsl/sascha-willems/shadowmapping/offscreen.frag new file mode 100644 index 000000000..81c8f55a3 --- /dev/null +++ b/tests/glsl/sascha-willems/shadowmapping/offscreen.frag @@ -0,0 +1,14 @@ +//TEST:COMPARE_GLSL: +#version 450 + +#extension GL_ARB_separate_shader_objects : enable +#extension GL_ARB_shading_language_420pack : enable + +layout(location = 0) out vec4 color; +//layout(location = 0) out float fragmentdepth; + +void main() +{ +// fragmentdepth = gl_FragCoord.z; + color = vec4(1.0, 0.0, 0.0, 1.0); +}
\ No newline at end of file diff --git a/tests/glsl/sascha-willems/shadowmapping/offscreen.vert b/tests/glsl/sascha-willems/shadowmapping/offscreen.vert new file mode 100644 index 000000000..e5d18fc88 --- /dev/null +++ b/tests/glsl/sascha-willems/shadowmapping/offscreen.vert @@ -0,0 +1,23 @@ +//TEST:COMPARE_GLSL: +#version 450 + +#extension GL_ARB_separate_shader_objects : enable +#extension GL_ARB_shading_language_420pack : enable + +layout (location = 0) in vec3 inPos; + +layout (binding = 0) uniform UBO +{ + mat4 depthMVP; +} ubo; + +out gl_PerVertex +{ + vec4 gl_Position; +}; + + +void main() +{ + gl_Position = ubo.depthMVP * vec4(inPos, 1.0); +}
\ No newline at end of file diff --git a/tests/glsl/sascha-willems/shadowmapping/quad.frag b/tests/glsl/sascha-willems/shadowmapping/quad.frag new file mode 100644 index 000000000..3074bd5ee --- /dev/null +++ b/tests/glsl/sascha-willems/shadowmapping/quad.frag @@ -0,0 +1,25 @@ +//TEST:COMPARE_GLSL: +#version 450 + +#extension GL_ARB_separate_shader_objects : enable +#extension GL_ARB_shading_language_420pack : enable + +layout (binding = 1) uniform sampler2D samplerColor; + +layout (location = 0) in vec2 inUV; + +layout (location = 0) out vec4 outFragColor; + +float LinearizeDepth(float depth) +{ + float n = 1.0; // camera z near + float f = 128.0; // camera z far + float z = depth; + return (2.0 * n) / (f + n - z * (f - n)); +} + +void main() +{ + float depth = texture(samplerColor, inUV).r; + outFragColor = vec4(vec3(1.0-LinearizeDepth(depth)), 1.0); +}
\ No newline at end of file diff --git a/tests/glsl/sascha-willems/shadowmapping/quad.vert b/tests/glsl/sascha-willems/shadowmapping/quad.vert new file mode 100644 index 000000000..7c1286a4c --- /dev/null +++ b/tests/glsl/sascha-willems/shadowmapping/quad.vert @@ -0,0 +1,28 @@ +//TEST:COMPARE_GLSL: +#version 450 + +#extension GL_ARB_separate_shader_objects : enable +#extension GL_ARB_shading_language_420pack : enable + +layout (location = 0) in vec3 inPos; +layout (location = 1) in vec2 inUV; + +layout (binding = 0) uniform UBO +{ + mat4 projection; + mat4 model; +} ubo; + +layout (location = 0) out vec2 outUV; + +out gl_PerVertex +{ + vec4 gl_Position; +}; + + +void main() +{ + outUV = inUV; + gl_Position = ubo.projection * ubo.model * vec4(inPos.xyz, 1.0); +} diff --git a/tests/glsl/sascha-willems/shadowmapping/scene.frag b/tests/glsl/sascha-willems/shadowmapping/scene.frag new file mode 100644 index 000000000..58e2986ce --- /dev/null +++ b/tests/glsl/sascha-willems/shadowmapping/scene.frag @@ -0,0 +1,72 @@ +//TEST:COMPARE_GLSL: +#version 450 + +#extension GL_ARB_separate_shader_objects : enable +#extension GL_ARB_shading_language_420pack : enable + +layout (binding = 1) uniform sampler2D shadowMap; + +layout (location = 0) in vec3 inNormal; +layout (location = 1) in vec3 inColor; +layout (location = 2) in vec3 inViewVec; +layout (location = 3) in vec3 inLightVec; +layout (location = 4) in vec4 inShadowCoord; + +layout (constant_id = 0) const int enablePCF = 0; + +layout (location = 0) out vec4 outFragColor; + +#define ambient 0.1 + +float textureProj(vec4 P, vec2 off) +{ + float shadow = 1.0; + vec4 shadowCoord = P / P.w; + if ( shadowCoord.z > -1.0 && shadowCoord.z < 1.0 ) + { + float dist = texture( shadowMap, shadowCoord.st + off ).r; + if ( shadowCoord.w > 0.0 && dist < shadowCoord.z ) + { + shadow = ambient; + } + } + return shadow; +} + +float filterPCF(vec4 sc) +{ + ivec2 texDim = textureSize(shadowMap, 0); + float scale = 1.5; + float dx = scale * 1.0 / float(texDim.x); + float dy = scale * 1.0 / float(texDim.y); + + float shadowFactor = 0.0; + int count = 0; + int range = 1; + + for (int x = -range; x <= range; x++) + { + for (int y = -range; y <= range; y++) + { + shadowFactor += textureProj(sc, vec2(dx*x, dy*y)); + count++; + } + + } + return shadowFactor / count; +} + +void main() +{ + float shadow = (enablePCF == 1) ? filterPCF(inShadowCoord / inShadowCoord.w) : textureProj(inShadowCoord / inShadowCoord.w, vec2(0.0)); + + vec3 N = normalize(inNormal); + vec3 L = normalize(inLightVec); + vec3 V = normalize(inViewVec); + vec3 R = normalize(-reflect(L, N)); + vec3 diffuse = max(dot(N, L), ambient) * inColor; +// vec3 specular = pow(max(dot(R, V), 0.0), 50.0) * vec3(0.75); + + outFragColor = vec4(diffuse * shadow, 1.0); + +}
\ No newline at end of file diff --git a/tests/glsl/sascha-willems/shadowmapping/scene.vert b/tests/glsl/sascha-willems/shadowmapping/scene.vert new file mode 100644 index 000000000..6fda339c3 --- /dev/null +++ b/tests/glsl/sascha-willems/shadowmapping/scene.vert @@ -0,0 +1,52 @@ +//TEST:COMPARE_GLSL: +#version 450 + +#extension GL_ARB_separate_shader_objects : enable +#extension GL_ARB_shading_language_420pack : enable + +layout (location = 0) in vec3 inPos; +layout (location = 1) in vec2 inUV; +layout (location = 2) in vec3 inColor; +layout (location = 3) in vec3 inNormal; + +layout (binding = 0) uniform UBO +{ + mat4 projection; + mat4 view; + mat4 model; + mat4 lightSpace; + vec3 lightPos; +} ubo; + +layout (location = 0) out vec3 outNormal; +layout (location = 1) out vec3 outColor; +layout (location = 2) out vec3 outViewVec; +layout (location = 3) out vec3 outLightVec; +layout (location = 4) out vec4 outShadowCoord; + +out gl_PerVertex +{ + vec4 gl_Position; +}; + +const mat4 biasMat = mat4( + 0.5, 0.0, 0.0, 0.0, + 0.0, 0.5, 0.0, 0.0, + 0.0, 0.0, 1.0, 0.0, + 0.5, 0.5, 0.0, 1.0 ); + +void main() +{ + outColor = inColor; + outNormal = inNormal; + + gl_Position = ubo.projection * ubo.view * ubo.model * vec4(inPos.xyz, 1.0); + + vec4 pos = ubo.model * vec4(inPos, 1.0); + outNormal = mat3(ubo.model) * inNormal; + outLightVec = normalize(ubo.lightPos - inPos); + outViewVec = -pos.xyz; + + outShadowCoord = ( biasMat * ubo.lightSpace * ubo.model ) * vec4(inPos, 1.0); +} + |
