input update 1
[carveJwlIkooP6JGAAIwe30JlM.git] / shaders / model_font.h
1 #ifndef SHADER_model_font_H
2 #define SHADER_model_font_H
3 static void shader_model_font_link(void);
4 static void shader_model_font_register(void);
5 static struct vg_shader _shader_model_font = {
6 .name = "model_font",
7 .link = shader_model_font_link,
8 .vs =
9 {
10 .orig_file = "shaders/model_font.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 "uniform vec4 uOffset;\n"
43 "\n"
44 "out vec4 aColour;\n"
45 "out vec2 aUv;\n"
46 "out vec3 aNorm;\n"
47 "out vec3 aCo;\n"
48 "out vec3 aWorldCo;\n"
49 "\n"
50 "void main()\n"
51 "{\n"
52 " vec3 co = a_co*uOffset.w+uOffset.xyz;\n"
53 " vec3 world_pos0 = uMdl * vec4( co, 1.0 );\n"
54 " vec4 vproj0 = uPv * vec4( world_pos0, 1.0 );\n"
55 " vec4 vproj1 = uPvmPrev * vec4( co, 1.0 );\n"
56 "\n"
57 " vs_motion_out( vproj0, vproj1 );\n"
58 "\n"
59 " gl_Position = vproj0;\n"
60 " aWorldCo = world_pos0;\n"
61 " aColour = a_colour;\n"
62 " aUv = a_uv;\n"
63 " aNorm = mat3(uMdl) * a_norm;\n"
64 " aCo = a_co;\n"
65 "}\n"
66 ""},
67 .fs =
68 {
69 .orig_file = "shaders/model_font.fs",
70 .static_src =
71 "out vec4 FragColor;\n"
72 "\n"
73 "uniform sampler2D uTexMain;\n"
74 "uniform vec4 uColour;\n"
75 "\n"
76 "in vec4 aColour;\n"
77 "in vec2 aUv;\n"
78 "in vec3 aNorm;\n"
79 "in vec3 aCo;\n"
80 "\n"
81 "#line 1 1 \n"
82 "const float k_motion_lerp_amount = 0.01;\n"
83 "\n"
84 "#line 2 0 \n"
85 "\n"
86 "layout (location = 1) out vec2 oMotionVec;\n"
87 "\n"
88 "in vec3 aMotionVec0;\n"
89 "in vec3 aMotionVec1;\n"
90 "\n"
91 "void compute_motion_vectors()\n"
92 "{\n"
93 " // Write motion vectors\n"
94 " vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
95 " vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
96 "\n"
97 " oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
98 "}\n"
99 "\n"
100 "#line 12 0 \n"
101 "\n"
102 "void main()\n"
103 "{\n"
104 " compute_motion_vectors();\n"
105 " FragColor = texture( uTexMain, aUv ) * uColour;\n"
106 "}\n"
107 ""},
108 };
109
110 static GLuint _uniform_model_font_uMdl;
111 static GLuint _uniform_model_font_uPv;
112 static GLuint _uniform_model_font_uPvmPrev;
113 static GLuint _uniform_model_font_uOffset;
114 static GLuint _uniform_model_font_uTexMain;
115 static GLuint _uniform_model_font_uColour;
116 static void shader_model_font_uMdl(m4x3f m){
117 glUniformMatrix4x3fv(_uniform_model_font_uMdl,1,GL_FALSE,(float*)m);
118 }
119 static void shader_model_font_uPv(m4x4f m){
120 glUniformMatrix4fv(_uniform_model_font_uPv,1,GL_FALSE,(float*)m);
121 }
122 static void shader_model_font_uPvmPrev(m4x4f m){
123 glUniformMatrix4fv(_uniform_model_font_uPvmPrev,1,GL_FALSE,(float*)m);
124 }
125 static void shader_model_font_uOffset(v4f v){
126 glUniform4fv(_uniform_model_font_uOffset,1,v);
127 }
128 static void shader_model_font_uTexMain(int i){
129 glUniform1i(_uniform_model_font_uTexMain,i);
130 }
131 static void shader_model_font_uColour(v4f v){
132 glUniform4fv(_uniform_model_font_uColour,1,v);
133 }
134 static void shader_model_font_register(void){
135 vg_shader_register( &_shader_model_font );
136 }
137 static void shader_model_font_use(void){ glUseProgram(_shader_model_font.id); }
138 static void shader_model_font_link(void){
139 _uniform_model_font_uMdl = glGetUniformLocation( _shader_model_font.id, "uMdl" );
140 _uniform_model_font_uPv = glGetUniformLocation( _shader_model_font.id, "uPv" );
141 _uniform_model_font_uPvmPrev = glGetUniformLocation( _shader_model_font.id, "uPvmPrev" );
142 _uniform_model_font_uOffset = glGetUniformLocation( _shader_model_font.id, "uOffset" );
143 _uniform_model_font_uTexMain = glGetUniformLocation( _shader_model_font.id, "uTexMain" );
144 _uniform_model_font_uColour = glGetUniformLocation( _shader_model_font.id, "uColour" );
145 }
146 #endif /* SHADER_model_font_H */