1fda296a7a51e05b7300403adb13c0269be401da
[carveJwlIkooP6JGAAIwe30JlM.git] / shaders / model_gate_unlinked.h
1 #ifndef SHADER_model_gate_unlinked_H
2 #define SHADER_model_gate_unlinked_H
3 static void shader_model_gate_unlinked_link(void);
4 static void shader_model_gate_unlinked_register(void);
5 static struct vg_shader _shader_model_gate_unlinked = {
6 .name = "model_gate_unlinked",
7 .link = shader_model_gate_unlinked_link,
8 .vs =
9 {
10 .orig_file = "shaders/model.vs",
11 .static_src =
12 "layout (location=0) in vec3 a_co;\n"
13 "layout (location=1) in vec3 a_norm;\n"
14 "layout (location=2) in vec2 a_uv;\n"
15 "layout (location=3) in vec4 a_colour;\n"
16 "layout (location=4) in vec4 a_weights;\n"
17 "layout (location=5) in ivec4 a_groups;\n"
18 "\n"
19 "#line 1 1 \n"
20 "const float k_motion_lerp_amount = 0.01;\n"
21 "\n"
22 "#line 2 0 \n"
23 "\n"
24 "out vec3 aMotionVec0;\n"
25 "out vec3 aMotionVec1;\n"
26 "\n"
27 "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
28 "{\n"
29 " // This magically solves some artifacting errors!\n"
30 " //\n"
31 " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
32 "\n"
33 " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
34 " aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
35 "}\n"
36 "\n"
37 "#line 9 0 \n"
38 "\n"
39 "uniform mat4x3 uMdl;\n"
40 "uniform mat4 uPv;\n"
41 "uniform mat4 uPvmPrev;\n"
42 "\n"
43 "out vec4 aColour;\n"
44 "out vec2 aUv;\n"
45 "out vec3 aNorm;\n"
46 "out vec3 aCo;\n"
47 "out vec3 aWorldCo;\n"
48 "\n"
49 "void main()\n"
50 "{\n"
51 " vec3 world_pos0 = uMdl * vec4( a_co, 1.0 );\n"
52 " vec4 vproj0 = uPv * vec4( world_pos0, 1.0 );\n"
53 " vec4 vproj1 = uPvmPrev * vec4( a_co, 1.0 );\n"
54 "\n"
55 " vs_motion_out( vproj0, vproj1 );\n"
56 "\n"
57 " gl_Position = vproj0;\n"
58 " aWorldCo = world_pos0;\n"
59 " aColour = a_colour;\n"
60 " aUv = a_uv;\n"
61 " aNorm = mat3(uMdl) * a_norm;\n"
62 " aCo = a_co;\n"
63 "}\n"
64 ""},
65 .fs =
66 {
67 .orig_file = "shaders/model_gate_unlinked.fs",
68 .static_src =
69 "out vec4 FragColor;\n"
70 "\n"
71 "uniform float uTime;\n"
72 "uniform vec3 uCam;\n"
73 "uniform vec4 uColour;\n"
74 "\n"
75 "in vec3 aNorm;\n"
76 "in vec2 aUv;\n"
77 "in vec3 aCo;\n"
78 "\n"
79 "#line 1 1 \n"
80 "const float k_motion_lerp_amount = 0.01;\n"
81 "\n"
82 "#line 2 0 \n"
83 "\n"
84 "layout (location = 1) out vec2 oMotionVec;\n"
85 "\n"
86 "in vec3 aMotionVec0;\n"
87 "in vec3 aMotionVec1;\n"
88 "\n"
89 "void compute_motion_vectors()\n"
90 "{\n"
91 " // Write motion vectors\n"
92 " vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
93 " vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
94 "\n"
95 " oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
96 "}\n"
97 "\n"
98 "#line 12 0 \n"
99 "\n"
100 "const int NOISE_LOOP = 3;\n"
101 "vec3 digital_noise( uvec3 iuv ){\n"
102 " iuv *=uvec3(8,2524,7552);\n"
103 " for( int i=0; i<NOISE_LOOP; i++ )\n"
104 " iuv += (iuv.yzx<<2) ^ (iuv.yxz)+iuv.z;\n"
105 " return vec3(iuv)*(1.0/float(0xffffffffU));\n"
106 "}\n"
107 "\n"
108 "vec2 rand_hash22( vec2 p ){\n"
109 " vec3 p3 = fract(vec3(p.xyx) * 213.8976123);\n"
110 " p3 += dot(p3, p3.yzx+19.19);\n"
111 " return fract(vec2((p3.x + p3.y)*p3.z, (p3.x+p3.z)*p3.y));\n"
112 "}\n"
113 "\n"
114 "void main(){\n"
115 " compute_motion_vectors();\n"
116 "\n"
117 " vec2 ssuv = gl_FragCoord.xy;\n"
118 " float grad = 1.0-aUv.y*0.1;\n"
119 " float opacity = rand_hash22( vec2(floor(aUv.y*100.0),floor(aCo.z*10.0+uTime*40.0)) ).r*grad;\n"
120 " \n"
121 " vec3 vDither = vec3( dot( vec2( 171.0, 231.0 ), ssuv) );\n"
122 " float dither = fract( vDither.g / 71.0 ) - 0.5;\n"
123 "\n"
124 " if( opacity<0.9 )\n"
125 " discard;\n"
126 "\n"
127 " FragColor = vec4(0.7,0.5,0.5,1.0);\n"
128 "}\n"
129 ""},
130 };
131
132 static GLuint _uniform_model_gate_unlinked_uMdl;
133 static GLuint _uniform_model_gate_unlinked_uPv;
134 static GLuint _uniform_model_gate_unlinked_uPvmPrev;
135 static GLuint _uniform_model_gate_unlinked_uTime;
136 static GLuint _uniform_model_gate_unlinked_uCam;
137 static GLuint _uniform_model_gate_unlinked_uColour;
138 static void shader_model_gate_unlinked_uMdl(m4x3f m){
139 glUniformMatrix4x3fv(_uniform_model_gate_unlinked_uMdl,1,GL_FALSE,(float*)m);
140 }
141 static void shader_model_gate_unlinked_uPv(m4x4f m){
142 glUniformMatrix4fv(_uniform_model_gate_unlinked_uPv,1,GL_FALSE,(float*)m);
143 }
144 static void shader_model_gate_unlinked_uPvmPrev(m4x4f m){
145 glUniformMatrix4fv(_uniform_model_gate_unlinked_uPvmPrev,1,GL_FALSE,(float*)m);
146 }
147 static void shader_model_gate_unlinked_uTime(float f){
148 glUniform1f(_uniform_model_gate_unlinked_uTime,f);
149 }
150 static void shader_model_gate_unlinked_uCam(v3f v){
151 glUniform3fv(_uniform_model_gate_unlinked_uCam,1,v);
152 }
153 static void shader_model_gate_unlinked_uColour(v4f v){
154 glUniform4fv(_uniform_model_gate_unlinked_uColour,1,v);
155 }
156 static void shader_model_gate_unlinked_register(void){
157 vg_shader_register( &_shader_model_gate_unlinked );
158 }
159 static void shader_model_gate_unlinked_use(void){ glUseProgram(_shader_model_gate_unlinked.id); }
160 static void shader_model_gate_unlinked_link(void){
161 _uniform_model_gate_unlinked_uMdl = glGetUniformLocation( _shader_model_gate_unlinked.id, "uMdl" );
162 _uniform_model_gate_unlinked_uPv = glGetUniformLocation( _shader_model_gate_unlinked.id, "uPv" );
163 _uniform_model_gate_unlinked_uPvmPrev = glGetUniformLocation( _shader_model_gate_unlinked.id, "uPvmPrev" );
164 _uniform_model_gate_unlinked_uTime = glGetUniformLocation( _shader_model_gate_unlinked.id, "uTime" );
165 _uniform_model_gate_unlinked_uCam = glGetUniformLocation( _shader_model_gate_unlinked.id, "uCam" );
166 _uniform_model_gate_unlinked_uColour = glGetUniformLocation( _shader_model_gate_unlinked.id, "uColour" );
167 }
168 #endif /* SHADER_model_gate_unlinked_H */