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
= {
7 .link
= shader_model_font_link
,
10 .orig_file
= "shaders/model_font.vs",
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"
17 "const float k_motion_lerp_amount = 0.01;\n"
21 "out vec3 aMotionVec0;\n"
22 "out vec3 aMotionVec1;\n"
24 "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
26 " // This magically solves some artifacting errors!\n"
28 " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
30 " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
31 " aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
36 "uniform mat4x3 uMdl;\n"
38 "uniform mat4 uPvmPrev;\n"
39 "uniform vec4 uOffset;\n"
44 "out vec3 aWorldCo;\n"
48 " vec3 co = a_co*uOffset.w+uOffset.xyz;\n"
49 " vec3 world_pos0 = uMdl * vec4( co, 1.0 );\n"
50 " vec4 vproj0 = uPv * vec4( world_pos0, 1.0 );\n"
51 " vec4 vproj1 = uPvmPrev * vec4( co, 1.0 );\n"
53 " vs_motion_out( vproj0, vproj1 );\n"
55 " gl_Position = vproj0;\n"
58 " aNorm = vec4( mat3(uMdl) * a_norm, 0.0 );\n"
60 " aWorldCo = world_pos0;\n"
65 .orig_file
= "shaders/model_font.fs",
67 "layout (location = 0) out vec4 oColour;\n"
69 "uniform sampler2D uTexMain;\n"
70 "uniform vec4 uColour;\n"
77 "const float k_motion_lerp_amount = 0.01;\n"
81 "layout (location = 1) out vec2 oMotionVec;\n"
83 "in vec3 aMotionVec0;\n"
84 "in vec3 aMotionVec1;\n"
86 "void compute_motion_vectors()\n"
88 " // Write motion vectors\n"
89 " vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
90 " vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
92 " oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
99 " compute_motion_vectors();\n"
100 " oColour = texture( uTexMain, aUv ) * uColour;\n"
105 static GLuint _uniform_model_font_uMdl
;
106 static GLuint _uniform_model_font_uPv
;
107 static GLuint _uniform_model_font_uPvmPrev
;
108 static GLuint _uniform_model_font_uOffset
;
109 static GLuint _uniform_model_font_uTexMain
;
110 static GLuint _uniform_model_font_uColour
;
111 static void shader_model_font_uMdl(m4x3f m
){
112 glUniformMatrix4x3fv(_uniform_model_font_uMdl
,1,GL_FALSE
,(float*)m
);
114 static void shader_model_font_uPv(m4x4f m
){
115 glUniformMatrix4fv(_uniform_model_font_uPv
,1,GL_FALSE
,(float*)m
);
117 static void shader_model_font_uPvmPrev(m4x4f m
){
118 glUniformMatrix4fv(_uniform_model_font_uPvmPrev
,1,GL_FALSE
,(float*)m
);
120 static void shader_model_font_uOffset(v4f v
){
121 glUniform4fv(_uniform_model_font_uOffset
,1,v
);
123 static void shader_model_font_uTexMain(int i
){
124 glUniform1i(_uniform_model_font_uTexMain
,i
);
126 static void shader_model_font_uColour(v4f v
){
127 glUniform4fv(_uniform_model_font_uColour
,1,v
);
129 static void shader_model_font_register(void){
130 vg_shader_register( &_shader_model_font
);
132 static void shader_model_font_use(void){ glUseProgram(_shader_model_font
.id
); }
133 static void shader_model_font_link(void){
134 _uniform_model_font_uMdl
= glGetUniformLocation( _shader_model_font
.id
, "uMdl" );
135 _uniform_model_font_uPv
= glGetUniformLocation( _shader_model_font
.id
, "uPv" );
136 _uniform_model_font_uPvmPrev
= glGetUniformLocation( _shader_model_font
.id
, "uPvmPrev" );
137 _uniform_model_font_uOffset
= glGetUniformLocation( _shader_model_font
.id
, "uOffset" );
138 _uniform_model_font_uTexMain
= glGetUniformLocation( _shader_model_font
.id
, "uTexMain" );
139 _uniform_model_font_uColour
= glGetUniformLocation( _shader_model_font
.id
, "uColour" );
141 #endif /* SHADER_model_font_H */