summaryrefslogtreecommitdiffstats
path: root/src/engine/shaders/vertexShadow
diff options
context:
space:
mode:
Diffstat (limited to 'src/engine/shaders/vertexShadow')
-rw-r--r--src/engine/shaders/vertexShadow34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/engine/shaders/vertexShadow b/src/engine/shaders/vertexShadow
new file mode 100644
index 00000000..24184376
--- /dev/null
+++ b/src/engine/shaders/vertexShadow
@@ -0,0 +1,34 @@
+attribute highp vec3 vertexPosition_mdl;
+attribute highp vec2 vertexUV;
+attribute highp vec3 vertexNormal_mdl;
+
+uniform highp mat4 MVP;
+uniform highp mat4 V;
+uniform highp mat4 M;
+uniform highp mat4 itM;
+uniform highp vec3 lightPosition_wrld; // this is for inverted light direction, not position (we are just reusing uniform)
+uniform highp mat4 depthMVP;
+
+varying highp vec2 UV;
+varying highp vec3 position_wrld;
+varying highp vec3 normal_cmr;
+varying highp vec3 eyeDirection_cmr;
+varying highp vec3 lightDirection_cmr;
+varying highp vec4 shadowCoord;
+
+const highp mat4 bias = 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);
+
+void main() {
+ gl_Position = MVP * vec4(vertexPosition_mdl, 1.0);
+ shadowCoord = bias * depthMVP * vec4(vertexPosition_mdl, 1.0);
+ position_wrld = (M * vec4(vertexPosition_mdl, 1.0)).xyz;
+ vec3 vertexPosition_cmr = (V * M * vec4(vertexPosition_mdl, 1.0)).xyz;
+ eyeDirection_cmr = vec3(0.0, 0.0, 0.0) - vertexPosition_cmr;
+ lightDirection_cmr = (V * vec4(lightPosition_wrld, 0.0)).xyz;
+ normal_cmr = (V * itM * vec4(vertexNormal_mdl, 0.0)).xyz; // Use modelMatrix's transposed inverse, as it's scaled
+ //normal_cmr = (V * M * vec4(vertexNormal_mdl, 0.0)).xyz; // Use modelMatrix's transposed inverse, as it's scaled
+ UV = vertexUV;
+}