summaryrefslogtreecommitdiffstats
path: root/tests/manual/shadow-map-qml/shaders
diff options
context:
space:
mode:
Diffstat (limited to 'tests/manual/shadow-map-qml/shaders')
-rw-r--r--tests/manual/shadow-map-qml/shaders/ads.frag60
-rw-r--r--tests/manual/shadow-map-qml/shaders/ads.vert33
-rw-r--r--tests/manual/shadow-map-qml/shaders/es3/ads.frag59
-rw-r--r--tests/manual/shadow-map-qml/shaders/es3/ads.vert30
-rw-r--r--tests/manual/shadow-map-qml/shaders/es3/shadowmap.frag7
-rw-r--r--tests/manual/shadow-map-qml/shaders/es3/shadowmap.vert10
-rw-r--r--tests/manual/shadow-map-qml/shaders/rhi/ads.frag89
-rw-r--r--tests/manual/shadow-map-qml/shaders/rhi/ads.vert67
-rw-r--r--tests/manual/shadow-map-qml/shaders/rhi/shadowmap.frag8
-rw-r--r--tests/manual/shadow-map-qml/shaders/rhi/shadowmap.vert22
-rw-r--r--tests/manual/shadow-map-qml/shaders/shadowmap.frag8
-rw-r--r--tests/manual/shadow-map-qml/shaders/shadowmap.vert13
12 files changed, 406 insertions, 0 deletions
diff --git a/tests/manual/shadow-map-qml/shaders/ads.frag b/tests/manual/shadow-map-qml/shaders/ads.frag
new file mode 100644
index 000000000..2d8318282
--- /dev/null
+++ b/tests/manual/shadow-map-qml/shaders/ads.frag
@@ -0,0 +1,60 @@
+// Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#version 150 core
+
+uniform mat4 viewMatrix;
+
+uniform vec3 lightPosition;
+uniform vec3 lightIntensity;
+
+uniform vec3 ka; // Ambient reflectivity
+uniform vec3 kd; // Diffuse reflectivity
+uniform vec3 ks; // Specular reflectivity
+uniform float shininess; // Specular shininess factor
+
+uniform sampler2DShadow shadowMapTexture;
+
+in vec4 positionInLightSpace;
+
+in vec3 position;
+in vec3 normal;
+
+out vec4 fragColor;
+
+vec3 dsModel(const in vec3 pos, const in vec3 n)
+{
+ // Calculate the vector from the light to the fragment
+ vec3 s = normalize(vec3(viewMatrix * vec4(lightPosition, 1.0)) - pos);
+
+ // Calculate the vector from the fragment to the eye position
+ // (origin since this is in "eye" or "camera" space)
+ vec3 v = normalize(-pos);
+
+ // Reflect the light beam using the normal at this fragment
+ vec3 r = reflect(-s, n);
+
+ // Calculate the diffuse component
+ float diffuse = max(dot(s, n), 0.0);
+
+ // Calculate the specular component
+ float specular = 0.0;
+ if (dot(s, n) > 0.0)
+ specular = pow(max(dot(r, v), 0.0), shininess);
+
+ // Combine the diffuse and specular contributions (ambient is taken into account by the caller)
+ return lightIntensity * (kd * diffuse + ks * specular);
+}
+
+void main()
+{
+ float shadowMapSample = textureProj(shadowMapTexture, positionInLightSpace);
+
+ vec3 ambient = lightIntensity * ka;
+
+ vec3 result = ambient;
+ if (shadowMapSample > 0)
+ result += dsModel(position, normalize(normal));
+
+ fragColor = vec4(result, 1.0);
+}
diff --git a/tests/manual/shadow-map-qml/shaders/ads.vert b/tests/manual/shadow-map-qml/shaders/ads.vert
new file mode 100644
index 000000000..017fa0082
--- /dev/null
+++ b/tests/manual/shadow-map-qml/shaders/ads.vert
@@ -0,0 +1,33 @@
+// Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#version 150 core
+
+in vec3 vertexPosition;
+in vec3 vertexNormal;
+
+out vec4 positionInLightSpace;
+out vec3 position;
+out vec3 normal;
+
+uniform mat4 lightViewProjection;
+uniform mat4 modelMatrix;
+uniform mat4 modelView;
+uniform mat3 modelViewNormal;
+uniform mat4 mvp;
+
+void main()
+{
+ // positionInLightSpace = lightViewProjection * modelMatrix * vec4(vertexPosition, 1.0);
+ const mat4 shadowMatrix = mat4(0.5, 0.0, 0.0, 0.0,
+ 0.0, 0.5, 0.0, 0.0,
+ 0.0, 0.0, 0.5, 0.0,
+ 0.5, 0.5, 0.5, 1.0);
+
+ positionInLightSpace = shadowMatrix * lightViewProjection * modelMatrix * vec4(vertexPosition, 1.0);
+
+ normal = normalize(modelViewNormal * vertexNormal);
+ position = vec3(modelView * vec4(vertexPosition, 1.0));
+
+ gl_Position = mvp * vec4(vertexPosition, 1.0);
+}
diff --git a/tests/manual/shadow-map-qml/shaders/es3/ads.frag b/tests/manual/shadow-map-qml/shaders/es3/ads.frag
new file mode 100644
index 000000000..8a59268ac
--- /dev/null
+++ b/tests/manual/shadow-map-qml/shaders/es3/ads.frag
@@ -0,0 +1,59 @@
+#version 300 es
+
+precision highp float;
+
+uniform mat4 viewMatrix;
+
+uniform vec3 lightPosition;
+uniform vec3 lightIntensity;
+
+uniform vec3 ka; // Ambient reflectivity
+uniform vec3 kd; // Diffuse reflectivity
+uniform vec3 ks; // Specular reflectivity
+uniform float shininess; // Specular shininess factor
+
+uniform highp sampler2DShadow shadowMapTexture;
+
+in vec4 positionInLightSpace;
+
+in vec3 position;
+in vec3 normal;
+
+out vec4 fragColor;
+
+vec3 dsModel(const in vec3 pos, const in vec3 n)
+{
+ // Calculate the vector from the light to the fragment
+ vec3 s = normalize(vec3(viewMatrix * vec4(lightPosition, 1.0)) - pos);
+
+ // Calculate the vector from the fragment to the eye position
+ // (origin since this is in "eye" or "camera" space)
+ vec3 v = normalize(-pos);
+
+ // Reflect the light beam using the normal at this fragment
+ vec3 r = reflect(-s, n);
+
+ // Calculate the diffuse component
+ float diffuse = max(dot(s, n), 0.0);
+
+ // Calculate the specular component
+ float specular = 0.0;
+ if (dot(s, n) > 0.0)
+ specular = pow(max(dot(r, v), 0.0), shininess);
+
+ // Combine the diffuse and specular contributions (ambient is taken into account by the caller)
+ return lightIntensity * (kd * diffuse + ks * specular);
+}
+
+void main()
+{
+ float shadowMapSample = textureProj(shadowMapTexture, positionInLightSpace);
+
+ vec3 ambient = lightIntensity * ka;
+
+ vec3 result = ambient;
+ if (shadowMapSample > 0.0)
+ result += dsModel(position, normalize(normal));
+
+ fragColor = vec4(result, 1.0);
+}
diff --git a/tests/manual/shadow-map-qml/shaders/es3/ads.vert b/tests/manual/shadow-map-qml/shaders/es3/ads.vert
new file mode 100644
index 000000000..9c16eb07d
--- /dev/null
+++ b/tests/manual/shadow-map-qml/shaders/es3/ads.vert
@@ -0,0 +1,30 @@
+#version 300 es
+
+in vec3 vertexPosition;
+in vec3 vertexNormal;
+
+out vec4 positionInLightSpace;
+out vec3 position;
+out vec3 normal;
+
+uniform mat4 lightViewProjection;
+uniform mat4 modelMatrix;
+uniform mat4 modelView;
+uniform mat3 modelViewNormal;
+uniform mat4 mvp;
+
+void main()
+{
+ // positionInLightSpace = lightViewProjection * modelMatrix * vec4(vertexPosition, 1.0);
+ const mat4 shadowMatrix = mat4(0.5, 0.0, 0.0, 0.0,
+ 0.0, 0.5, 0.0, 0.0,
+ 0.0, 0.0, 0.5, 0.0,
+ 0.5, 0.5, 0.5, 1.0);
+
+ positionInLightSpace = shadowMatrix * lightViewProjection * modelMatrix * vec4(vertexPosition, 1.0);
+
+ normal = normalize(modelViewNormal * vertexNormal);
+ position = vec3(modelView * vec4(vertexPosition, 1.0));
+
+ gl_Position = mvp * vec4(vertexPosition, 1.0);
+}
diff --git a/tests/manual/shadow-map-qml/shaders/es3/shadowmap.frag b/tests/manual/shadow-map-qml/shaders/es3/shadowmap.frag
new file mode 100644
index 000000000..93ced265c
--- /dev/null
+++ b/tests/manual/shadow-map-qml/shaders/es3/shadowmap.frag
@@ -0,0 +1,7 @@
+#version 300 es
+
+precision highp float;
+
+void main()
+{
+}
diff --git a/tests/manual/shadow-map-qml/shaders/es3/shadowmap.vert b/tests/manual/shadow-map-qml/shaders/es3/shadowmap.vert
new file mode 100644
index 000000000..4745c7214
--- /dev/null
+++ b/tests/manual/shadow-map-qml/shaders/es3/shadowmap.vert
@@ -0,0 +1,10 @@
+#version 300 es
+
+in vec3 vertexPosition;
+
+uniform mat4 mvp;
+
+void main()
+{
+ gl_Position = mvp * vec4(vertexPosition, 1.0);
+}
diff --git a/tests/manual/shadow-map-qml/shaders/rhi/ads.frag b/tests/manual/shadow-map-qml/shaders/rhi/ads.frag
new file mode 100644
index 000000000..c30b34a78
--- /dev/null
+++ b/tests/manual/shadow-map-qml/shaders/rhi/ads.frag
@@ -0,0 +1,89 @@
+// Copyright (C) 2020 Klaralvdalens Datakonsult AB (KDAB).
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#version 450
+
+layout(location = 0) in vec4 positionInLightSpace;
+layout(location = 1) in vec3 position;
+layout(location = 2) in vec3 normal;
+
+layout(location = 0) out vec4 fragColor;
+
+layout(std140, binding = 0) uniform qt3d_render_view_uniforms {
+ mat4 viewMatrix;
+ mat4 projectionMatrix;
+ mat4 viewProjectionMatrix;
+ mat4 inverseViewMatrix;
+ mat4 inverseProjectionMatrix;
+ mat4 inverseViewProjectionMatrix;
+ mat4 viewportMatrix;
+ mat4 inverseViewportMatrix;
+ vec4 textureTransformMatrix;
+ vec3 eyePosition;
+ float aspectRatio;
+ float gamma;
+ float exposure;
+ float time;
+};
+
+layout(std140, binding = 1) uniform qt3d_command_uniforms {
+ mat4 modelMatrix;
+ mat4 inverseModelMatrix;
+ mat4 modelView;
+ mat3 modelNormalMatrix;
+ mat4 inverseModelViewMatrix;
+ mat4 mvp;
+ mat4 inverseModelViewProjectionMatrix;
+ mat3 modelViewNormal;
+};
+
+layout(std140, binding = 2) uniform qt3d_custom_uniforms {
+ mat4 lightViewProjection;
+ vec3 lightPosition;
+ vec3 lightIntensity;
+
+ vec3 ka; // Ambient reflectivity
+ vec3 kd; // Diffuse reflectivity
+ vec3 ks; // Specular reflectivity
+ float shininess; // Specular shininess factor
+};
+
+layout(binding = 3) uniform sampler2DShadow shadowMapTexture;
+
+
+vec3 dsModel(const in vec3 pos, const in vec3 n)
+{
+ // Calculate the vector from the light to the fragment
+ vec3 s = normalize(vec3(viewMatrix * vec4(lightPosition, 1.0)) - pos);
+
+ // Calculate the vector from the fragment to the eye position
+ // (origin since this is in "eye" or "camera" space)
+ vec3 v = normalize(-pos);
+
+ // Reflect the light beam using the normal at this fragment
+ vec3 r = reflect(-s, n);
+
+ // Calculate the diffuse component
+ float diffuse = max(dot(s, n), 0.0);
+
+ // Calculate the specular component
+ float specular = 0.0;
+ if (dot(s, n) > 0.0)
+ specular = pow(max(dot(r, v), 0.0), shininess);
+
+ // Combine the diffuse and specular contributions (ambient is taken into account by the caller)
+ return lightIntensity * (kd * diffuse + ks * specular);
+}
+
+void main()
+{
+ float shadowMapSample = textureProj(shadowMapTexture, positionInLightSpace);
+
+ vec3 ambient = lightIntensity * ka;
+
+ vec3 result = ambient;
+ if (shadowMapSample > 0)
+ result += dsModel(position, normalize(normal));
+
+ fragColor = vec4(result, 1.0);
+}
diff --git a/tests/manual/shadow-map-qml/shaders/rhi/ads.vert b/tests/manual/shadow-map-qml/shaders/rhi/ads.vert
new file mode 100644
index 000000000..c4e484883
--- /dev/null
+++ b/tests/manual/shadow-map-qml/shaders/rhi/ads.vert
@@ -0,0 +1,67 @@
+// Copyright (C) 2020 Klaralvdalens Datakonsult AB (KDAB).
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#version 450
+
+layout(location = 0) in vec3 vertexPosition;
+layout(location = 1) in vec3 vertexNormal;
+
+layout(location = 0) out vec4 positionInLightSpace;
+layout(location = 1) out vec3 position;
+layout(location = 2) out vec3 normal;
+
+
+layout(std140, binding = 0) uniform qt3d_render_view_uniforms {
+ mat4 viewMatrix;
+ mat4 projectionMatrix;
+ mat4 viewProjectionMatrix;
+ mat4 inverseViewMatrix;
+ mat4 inverseProjectionMatrix;
+ mat4 inverseViewProjectionMatrix;
+ mat4 viewportMatrix;
+ mat4 inverseViewportMatrix;
+ vec4 textureTransformMatrix;
+ vec3 eyePosition;
+ float aspectRatio;
+ float gamma;
+ float exposure;
+ float time;
+};
+
+layout(std140, binding = 1) uniform qt3d_command_uniforms {
+ mat4 modelMatrix;
+ mat4 inverseModelMatrix;
+ mat4 modelView;
+ mat3 modelNormalMatrix;
+ mat4 inverseModelViewMatrix;
+ mat4 mvp;
+ mat4 inverseModelViewProjectionMatrix;
+ mat3 modelViewNormal;
+};
+
+layout(std140, binding = 2) uniform qt3d_custom_uniforms {
+ mat4 lightViewProjection;
+ vec3 lightPosition;
+ vec3 lightIntensity;
+
+ vec3 ka; // Ambient reflectivity
+ vec3 kd; // Diffuse reflectivity
+ vec3 ks; // Specular reflectivity
+ float shininess; // Specular shininess factor
+};
+
+void main()
+{
+ // positionInLightSpace = lightViewProjection * modelMatrix * vec4(vertexPosition, 1.0);
+ const mat4 shadowMatrix = mat4(0.5, 0.0, 0.0, 0.0,
+ 0.0, 0.5, 0.0, 0.0,
+ 0.0, 0.0, 0.5, 0.0,
+ 0.5, 0.5, 0.5, 1.0);
+
+ positionInLightSpace = shadowMatrix * lightViewProjection * modelMatrix * vec4(vertexPosition, 1.0);
+
+ normal = normalize(modelViewNormal * vertexNormal);
+ position = vec3(modelView * vec4(vertexPosition, 1.0));
+
+ gl_Position = mvp * vec4(vertexPosition, 1.0);
+}
diff --git a/tests/manual/shadow-map-qml/shaders/rhi/shadowmap.frag b/tests/manual/shadow-map-qml/shaders/rhi/shadowmap.frag
new file mode 100644
index 000000000..6e0b8a03a
--- /dev/null
+++ b/tests/manual/shadow-map-qml/shaders/rhi/shadowmap.frag
@@ -0,0 +1,8 @@
+// Copyright (C) 2020 Klaralvdalens Datakonsult AB (KDAB).
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#version 450
+
+void main()
+{
+}
diff --git a/tests/manual/shadow-map-qml/shaders/rhi/shadowmap.vert b/tests/manual/shadow-map-qml/shaders/rhi/shadowmap.vert
new file mode 100644
index 000000000..277819aef
--- /dev/null
+++ b/tests/manual/shadow-map-qml/shaders/rhi/shadowmap.vert
@@ -0,0 +1,22 @@
+// Copyright (C) 2020 Klaralvdalens Datakonsult AB (KDAB).
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#version 450
+
+layout(location = 0) in vec3 vertexPosition;
+
+layout(std140, binding = 1) uniform qt3d_command_uniforms {
+ mat4 modelMatrix;
+ mat4 inverseModelMatrix;
+ mat4 modelView;
+ mat3 modelNormalMatrix;
+ mat4 inverseModelViewMatrix;
+ mat4 mvp;
+ mat4 inverseModelViewProjectionMatrix;
+ mat3 modelViewNormal;
+};
+
+void main()
+{
+ gl_Position = mvp * vec4(vertexPosition, 1.0);
+}
diff --git a/tests/manual/shadow-map-qml/shaders/shadowmap.frag b/tests/manual/shadow-map-qml/shaders/shadowmap.frag
new file mode 100644
index 000000000..31b39e148
--- /dev/null
+++ b/tests/manual/shadow-map-qml/shaders/shadowmap.frag
@@ -0,0 +1,8 @@
+// Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#version 150 core
+
+void main()
+{
+}
diff --git a/tests/manual/shadow-map-qml/shaders/shadowmap.vert b/tests/manual/shadow-map-qml/shaders/shadowmap.vert
new file mode 100644
index 000000000..d245cd127
--- /dev/null
+++ b/tests/manual/shadow-map-qml/shaders/shadowmap.vert
@@ -0,0 +1,13 @@
+// Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#version 150 core
+
+in vec3 vertexPosition;
+
+uniform mat4 mvp;
+
+void main()
+{
+ gl_Position = mvp * vec4(vertexPosition, 1.0);
+}