From 18827109c7f60163cfa60a0473d44c7505cbc5d4 Mon Sep 17 00:00:00 2001 From: XProger Date: Sun, 26 Mar 2017 14:32:17 +0300 Subject: [PATCH] #23 shadow volume shader --- src/volume.glsl | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/volume.glsl diff --git a/src/volume.glsl b/src/volume.glsl new file mode 100644 index 0000000..0a7b841 --- /dev/null +++ b/src/volume.glsl @@ -0,0 +1,45 @@ +R"====( +#ifdef GL_ES + precision lowp int; + precision highp float; +#endif + + +varying vec3 color; + +#ifdef VERTEX + attribute vec4 aCoord; + attribute vec4 aNormal; + attribute vec4 aColor; + + uniform mat4 uViewProj; + uniform vec4 uBasis[2]; // quat rot, pos + uniform vec3 uPosScale; // xyz - scale + uniform vec4 uLightPos; // xyz - pos, w - radius + + vec3 mulQuat(vec4 q, vec3 v) { + return v + 2.0 * cross(q.xyz, cross(q.xyz, v) + v * q.w); + } + + vec3 mulBasis(vec4 rot, vec4 pos, vec3 v) { + return mulQuat(rot, v) + pos.xyz; + } + + void main() { + vec4 c = vec4(mulBasis(uBasis[0], uBasis[1], aCoord.xyz * uPosScale), 1.0); + vec3 n = mulQuat(uBasis[0], normalize(aNormal.xyz)); + vec3 lv = uLightPos.xyz - c.xyz; + + if (dot(lv, n) < 0.0) + c.xyz -= normalize(lv) * 3000.0;//uLightPos.w; + + color = aColor.xyz; + + gl_Position = uViewProj * c; + } +#else + void main() { + gl_FragColor = vec4(color, 1.0); + } +#endif +)====" \ No newline at end of file