Debian Codegraph @

code/renderergl2/glsl/shadowfill_vp.glsl

raw
1 attribute vec3 attr_Position;
2 attribute vec3 attr_Normal;
3 attribute vec4 attr_TexCoord0;
4
5 #if defined(USE_VERTEX_ANIMATION)
6 attribute vec3 attr_Position2;
7 attribute vec3 attr_Normal2;
8 #elif defined(USE_BONE_ANIMATION)
9 attribute vec4 attr_BoneIndexes;
10 attribute vec4 attr_BoneWeights;
11 #endif
12
13 //#if defined(USE_DEFORM_VERTEXES)
14 uniform int u_DeformGen;
15 uniform float u_DeformParams[5];
16 //#endif
17
18 uniform float u_Time;
19 uniform mat4 u_ModelViewProjectionMatrix;
20
21 uniform mat4 u_ModelMatrix;
22
23 #if defined(USE_VERTEX_ANIMATION)
24 uniform float u_VertexLerp;
25 #elif defined(USE_BONE_ANIMATION)
26 uniform mat4 u_BoneMatrix[MAX_GLSL_BONES];
27 #endif
28
29 varying vec3 var_Position;
30
31 vec3 DeformPosition(const vec3 pos, const vec3 normal, const vec2 st)
32 {
33 if (u_DeformGen == 0)
34 {
35 return pos;
36 }
37
38 float base = u_DeformParams[0];
39 float amplitude = u_DeformParams[1];
40 float phase = u_DeformParams[2];
41 float frequency = u_DeformParams[3];
42 float spread = u_DeformParams[4];
43
44 if (u_DeformGen == DGEN_BULGE)
45 {
46 phase *= st.x;
47 }
48 else // if (u_DeformGen <= DGEN_WAVE_INVERSE_SAWTOOTH)
49 {
50 phase += dot(pos.xyz, vec3(spread));
51 }
52
53 float value = phase + (u_Time * frequency);
54 float func;
55
56 if (u_DeformGen == DGEN_WAVE_SIN)
57 {
58 func = sin(value * 2.0 * M_PI);
59 }
60 else if (u_DeformGen == DGEN_WAVE_SQUARE)
61 {
62 func = sign(0.5 - fract(value));
63 }
64 else if (u_DeformGen == DGEN_WAVE_TRIANGLE)
65 {
66 func = abs(fract(value + 0.75) - 0.5) * 4.0 - 1.0;
67 }
68 else if (u_DeformGen == DGEN_WAVE_SAWTOOTH)
69 {
70 func = fract(value);
71 }
72 else if (u_DeformGen == DGEN_WAVE_INVERSE_SAWTOOTH)
73 {
74 func = (1.0 - fract(value));
75 }
76 else // if (u_DeformGen == DGEN_BULGE)
77 {
78 func = sin(value);
79 }
80
81 return pos + normal * (base + func * amplitude);
82 }
83
84 void main()
85 {
86 #if defined(USE_VERTEX_ANIMATION)
87 vec3 position = mix(attr_Position, attr_Position2, u_VertexLerp);
88 vec3 normal = mix(attr_Normal, attr_Normal2, u_VertexLerp);
89 #elif defined(USE_BONE_ANIMATION)
90 mat4 vtxMat = u_BoneMatrix[int(attr_BoneIndexes.x)] * attr_BoneWeights.x;
91 vtxMat += u_BoneMatrix[int(attr_BoneIndexes.y)] * attr_BoneWeights.y;
92 vtxMat += u_BoneMatrix[int(attr_BoneIndexes.z)] * attr_BoneWeights.z;
93 vtxMat += u_BoneMatrix[int(attr_BoneIndexes.w)] * attr_BoneWeights.w;
94 mat3 nrmMat = mat3(cross(vtxMat[1].xyz, vtxMat[2].xyz), cross(vtxMat[2].xyz, vtxMat[0].xyz), cross(vtxMat[0].xyz, vtxMat[1].xyz));
95
96 vec3 position = vec3(vtxMat * vec4(attr_Position, 1.0));
97 vec3 normal = normalize(nrmMat * attr_Normal);
98 #else
99 vec3 position = attr_Position;
100 vec3 normal = attr_Normal;
101 #endif
102
103 position = DeformPosition(position, normal, attr_TexCoord0.st);
104
105 gl_Position = u_ModelViewProjectionMatrix * vec4(position, 1.0);
106
107 var_Position = (u_ModelMatrix * vec4(position, 1.0)).xyz;
108 }