summaryrefslogtreecommitdiff
path: root/tests/glsl/sascha-willems/deferred
diff options
context:
space:
mode:
authorTim Foley <tfoley@nvidia.com>2017-06-09 11:34:21 -0700
committerTim Foley <tfoley@nvidia.com>2017-06-09 13:44:59 -0700
commitfcf83dbf9effab3bd98bad2b83b2468b7eb05cfd (patch)
tree41047c94883b86ec085a81597391ce3ef557cd43 /tests/glsl/sascha-willems/deferred
parent52e8d4b9a27ab0060f874c3a63ab531847be35c0 (diff)
Initial import of code.
Diffstat (limited to 'tests/glsl/sascha-willems/deferred')
-rw-r--r--tests/glsl/sascha-willems/deferred/debug.frag27
-rw-r--r--tests/glsl/sascha-willems/deferred/debug.vert28
-rw-r--r--tests/glsl/sascha-willems/deferred/deferred.frag76
-rw-r--r--tests/glsl/sascha-willems/deferred/deferred.vert18
-rw-r--r--tests/glsl/sascha-willems/deferred/mrt.frag34
-rw-r--r--tests/glsl/sascha-willems/deferred/mrt.vert53
6 files changed, 236 insertions, 0 deletions
diff --git a/tests/glsl/sascha-willems/deferred/debug.frag b/tests/glsl/sascha-willems/deferred/debug.frag
new file mode 100644
index 000000000..6b77990b5
--- /dev/null
+++ b/tests/glsl/sascha-willems/deferred/debug.frag
@@ -0,0 +1,27 @@
+#version 450
+//TEST:COMPARE_GLSL:
+
+#extension GL_ARB_separate_shader_objects : enable
+#extension GL_ARB_shading_language_420pack : enable
+
+layout (binding = 1) uniform sampler2D samplerPosition;
+layout (binding = 2) uniform sampler2D samplerNormal;
+layout (binding = 3) uniform sampler2D samplerAlbedo;
+
+layout (location = 0) in vec3 inUV;
+
+layout (location = 0) out vec4 outFragColor;
+
+void main()
+{
+ vec3 components[3];
+ components[0] = texture(samplerPosition, inUV.st).rgb;
+ components[1] = texture(samplerNormal, inUV.st).rgb;
+ components[2] = texture(samplerAlbedo, inUV.st).rgb;
+ // Uncomment to display specular component
+ //components[2] = vec3(texture(samplerAlbedo, inUV.st).a);
+
+ // Select component depending on z coordinate of quad
+ highp int index = int(inUV.z);
+ outFragColor.rgb = components[index];
+} \ No newline at end of file
diff --git a/tests/glsl/sascha-willems/deferred/debug.vert b/tests/glsl/sascha-willems/deferred/debug.vert
new file mode 100644
index 000000000..de1b380f6
--- /dev/null
+++ b/tests/glsl/sascha-willems/deferred/debug.vert
@@ -0,0 +1,28 @@
+#version 450
+//TEST:COMPARE_GLSL:
+
+#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 = 3) in vec3 inNormal;
+
+layout (binding = 0) uniform UBO
+{
+ mat4 projection;
+ mat4 model;
+} ubo;
+
+layout (location = 0) out vec3 outUV;
+
+out gl_PerVertex
+{
+ vec4 gl_Position;
+};
+
+void main()
+{
+ outUV = vec3(inUV.st, inNormal.z);
+ gl_Position = ubo.projection * ubo.model * vec4(inPos.xyz, 1.0);
+}
diff --git a/tests/glsl/sascha-willems/deferred/deferred.frag b/tests/glsl/sascha-willems/deferred/deferred.frag
new file mode 100644
index 000000000..aead2f872
--- /dev/null
+++ b/tests/glsl/sascha-willems/deferred/deferred.frag
@@ -0,0 +1,76 @@
+#version 450
+//TEST:COMPARE_GLSL:
+
+#extension GL_ARB_separate_shader_objects : enable
+#extension GL_ARB_shading_language_420pack : enable
+
+layout (binding = 1) uniform sampler2D samplerposition;
+layout (binding = 2) uniform sampler2D samplerNormal;
+layout (binding = 3) uniform sampler2D samplerAlbedo;
+
+layout (location = 0) in vec2 inUV;
+
+layout (location = 0) out vec4 outFragcolor;
+
+struct Light {
+ vec4 position;
+ vec3 color;
+ float radius;
+};
+
+layout (binding = 4) uniform UBO
+{
+ Light lights[6];
+ vec4 viewPos;
+} ubo;
+
+
+void main()
+{
+ // Get G-Buffer values
+ vec3 fragPos = texture(samplerposition, inUV).rgb;
+ vec3 normal = texture(samplerNormal, inUV).rgb;
+ vec4 albedo = texture(samplerAlbedo, inUV);
+
+ #define lightCount 6
+ #define ambient 0.0
+
+ // Ambient part
+ vec3 fragcolor = albedo.rgb * ambient;
+
+ for(int i = 0; i < lightCount; ++i)
+ {
+ // Vector to light
+ vec3 L = ubo.lights[i].position.xyz - fragPos;
+ // Distance from light to fragment position
+ float dist = length(L);
+
+ // Viewer to fragment
+ vec3 V = ubo.viewPos.xyz - fragPos;
+ V = normalize(V);
+
+ //if(dist < ubo.lights[i].radius)
+ {
+ // Light to fragment
+ L = normalize(L);
+
+ // Attenuation
+ float atten = ubo.lights[i].radius / (pow(dist, 2.0) + 1.0);
+
+ // Diffuse part
+ vec3 N = normalize(normal);
+ float NdotL = max(0.0, dot(N, L));
+ vec3 diff = ubo.lights[i].color * albedo.rgb * NdotL * atten;
+
+ // Specular part
+ // Specular map values are stored in alpha of albedo mrt
+ vec3 R = reflect(-L, N);
+ float NdotR = max(0.0, dot(R, V));
+ vec3 spec = ubo.lights[i].color * albedo.a * pow(NdotR, 16.0) * atten;
+
+ fragcolor += diff + spec;
+ }
+ }
+
+ outFragcolor = vec4(fragcolor, 1.0);
+} \ No newline at end of file
diff --git a/tests/glsl/sascha-willems/deferred/deferred.vert b/tests/glsl/sascha-willems/deferred/deferred.vert
new file mode 100644
index 000000000..548284554
--- /dev/null
+++ b/tests/glsl/sascha-willems/deferred/deferred.vert
@@ -0,0 +1,18 @@
+#version 450
+//TEST:COMPARE_GLSL:
+
+#extension GL_ARB_separate_shader_objects : enable
+#extension GL_ARB_shading_language_420pack : enable
+
+layout (location = 0) out vec2 outUV;
+
+out gl_PerVertex
+{
+ vec4 gl_Position;
+};
+
+void main()
+{
+ outUV = vec2((gl_VertexIndex << 1) & 2, gl_VertexIndex & 2);
+ gl_Position = vec4(outUV * 2.0f - 1.0f, 0.0f, 1.0f);
+}
diff --git a/tests/glsl/sascha-willems/deferred/mrt.frag b/tests/glsl/sascha-willems/deferred/mrt.frag
new file mode 100644
index 000000000..4bd2a10a5
--- /dev/null
+++ b/tests/glsl/sascha-willems/deferred/mrt.frag
@@ -0,0 +1,34 @@
+#version 450
+//TEST:COMPARE_GLSL:
+
+#extension GL_ARB_separate_shader_objects : enable
+#extension GL_ARB_shading_language_420pack : enable
+
+layout (binding = 1) uniform sampler2D samplerColor;
+layout (binding = 2) uniform sampler2D samplerNormalMap;
+
+layout (location = 0) in vec3 inNormal;
+layout (location = 1) in vec2 inUV;
+layout (location = 2) in vec3 inColor;
+layout (location = 3) in vec3 inWorldPos;
+layout (location = 4) in vec3 inTangent;
+
+layout (location = 0) out vec4 outPosition;
+layout (location = 1) out vec4 outNormal;
+layout (location = 2) out vec4 outAlbedo;
+
+void main()
+{
+ outPosition = vec4(inWorldPos, 1.0);
+
+ // Calculate normal in tangent space
+ vec3 N = normalize(inNormal);
+ N.y = -N.y;
+ vec3 T = normalize(inTangent);
+ vec3 B = cross(N, T);
+ mat3 TBN = mat3(T, B, N);
+ vec3 tnorm = TBN * normalize(texture(samplerNormalMap, inUV).xyz * 2.0 - vec3(1.0));
+ outNormal = vec4(tnorm, 1.0);
+
+ outAlbedo = texture(samplerColor, inUV);
+} \ No newline at end of file
diff --git a/tests/glsl/sascha-willems/deferred/mrt.vert b/tests/glsl/sascha-willems/deferred/mrt.vert
new file mode 100644
index 000000000..26f764176
--- /dev/null
+++ b/tests/glsl/sascha-willems/deferred/mrt.vert
@@ -0,0 +1,53 @@
+#version 450
+//TEST:COMPARE_GLSL:
+
+#extension GL_ARB_separate_shader_objects : enable
+#extension GL_ARB_shading_language_420pack : enable
+
+layout (location = 0) in vec4 inPos;
+layout (location = 1) in vec2 inUV;
+layout (location = 2) in vec3 inColor;
+layout (location = 3) in vec3 inNormal;
+layout (location = 4) in vec3 inTangent;
+
+layout (binding = 0) uniform UBO
+{
+ mat4 projection;
+ mat4 model;
+ mat4 view;
+ vec4 instancePos[3];
+} ubo;
+
+layout (location = 0) out vec3 outNormal;
+layout (location = 1) out vec2 outUV;
+layout (location = 2) out vec3 outColor;
+layout (location = 3) out vec3 outWorldPos;
+layout (location = 4) out vec3 outTangent;
+
+out gl_PerVertex
+{
+ vec4 gl_Position;
+};
+
+void main()
+{
+ vec4 tmpPos = inPos + ubo.instancePos[gl_InstanceIndex];
+
+ gl_Position = ubo.projection * ubo.view * ubo.model * tmpPos;
+
+ outUV = inUV;
+ outUV.t = 1.0 - outUV.t;
+
+ // Vertex position in world space
+ outWorldPos = vec3(ubo.model * tmpPos);
+ // GL to Vulkan coord space
+ outWorldPos.y = -outWorldPos.y;
+
+ // Normal in world space
+ mat3 mNormal = transpose(inverse(mat3(ubo.model)));
+ outNormal = mNormal * normalize(inNormal);
+ outTangent = mNormal * normalize(inTangent);
+
+ // Currently just vertex color
+ outColor = inColor;
+}