1 #ifndef SHADER_model_gate_H
2 #define SHADER_model_gate_H
3 static void shader_model_gate_link(void);
4 static void shader_model_gate_register(void);
5 static struct vg_shader _shader_model_gate
= {
7 .link
= shader_model_gate_link
,
10 .orig_file
= "shaders/model.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"
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"
20 "const float k_motion_lerp_amount = 0.01;\n"
24 "out vec3 aMotionVec0;\n"
25 "out vec3 aMotionVec1;\n"
27 "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
29 " // This magically solves some artifacting errors!\n"
31 " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
33 " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
34 " aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
39 "uniform mat4x3 uMdl;\n"
41 "uniform mat4 uPvmPrev;\n"
47 "out vec3 aWorldCo;\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"
55 " vs_motion_out( vproj0, vproj1 );\n"
57 " gl_Position = vproj0;\n"
58 " aWorldCo = world_pos0;\n"
59 " aColour = a_colour;\n"
61 " aNorm = mat3(uMdl) * a_norm;\n"
67 .orig_file
= "shaders/model_gate_lq.fs",
69 "out vec4 FragColor;\n"
71 "uniform float uTime;\n"
72 "uniform vec3 uCam;\n"
73 "uniform vec2 uInvRes;\n"
74 "uniform vec4 uColour;\n"
82 " vec2 ssuv = gl_FragCoord.xy;\n"
83 " float opacity = 1.0-smoothstep(0.0,1.0,aUv.y+uColour.a);\n"
85 " vec3 vDither = vec3( dot( vec2( 171.0, 231.0 ), ssuv) );\n"
86 " float dither = fract( vDither.g / 71.0 ) - 0.5;\n"
88 " if( opacity+dither<0.5 )\n"
91 " FragColor = uColour;\n"
96 static GLuint _uniform_model_gate_uMdl
;
97 static GLuint _uniform_model_gate_uPv
;
98 static GLuint _uniform_model_gate_uPvmPrev
;
99 static GLuint _uniform_model_gate_uTime
;
100 static GLuint _uniform_model_gate_uCam
;
101 static GLuint _uniform_model_gate_uInvRes
;
102 static GLuint _uniform_model_gate_uColour
;
103 static void shader_model_gate_uMdl(m4x3f m
){
104 glUniformMatrix4x3fv(_uniform_model_gate_uMdl
,1,GL_FALSE
,(float*)m
);
106 static void shader_model_gate_uPv(m4x4f m
){
107 glUniformMatrix4fv(_uniform_model_gate_uPv
,1,GL_FALSE
,(float*)m
);
109 static void shader_model_gate_uPvmPrev(m4x4f m
){
110 glUniformMatrix4fv(_uniform_model_gate_uPvmPrev
,1,GL_FALSE
,(float*)m
);
112 static void shader_model_gate_uTime(float f
){
113 glUniform1f(_uniform_model_gate_uTime
,f
);
115 static void shader_model_gate_uCam(v3f v
){
116 glUniform3fv(_uniform_model_gate_uCam
,1,v
);
118 static void shader_model_gate_uInvRes(v2f v
){
119 glUniform2fv(_uniform_model_gate_uInvRes
,1,v
);
121 static void shader_model_gate_uColour(v4f v
){
122 glUniform4fv(_uniform_model_gate_uColour
,1,v
);
124 static void shader_model_gate_register(void){
125 vg_shader_register( &_shader_model_gate
);
127 static void shader_model_gate_use(void){ glUseProgram(_shader_model_gate
.id
); }
128 static void shader_model_gate_link(void){
129 _uniform_model_gate_uMdl
= glGetUniformLocation( _shader_model_gate
.id
, "uMdl" );
130 _uniform_model_gate_uPv
= glGetUniformLocation( _shader_model_gate
.id
, "uPv" );
131 _uniform_model_gate_uPvmPrev
= glGetUniformLocation( _shader_model_gate
.id
, "uPvmPrev" );
132 _uniform_model_gate_uTime
= glGetUniformLocation( _shader_model_gate
.id
, "uTime" );
133 _uniform_model_gate_uCam
= glGetUniformLocation( _shader_model_gate
.id
, "uCam" );
134 _uniform_model_gate_uInvRes
= glGetUniformLocation( _shader_model_gate
.id
, "uInvRes" );
135 _uniform_model_gate_uColour
= glGetUniformLocation( _shader_model_gate
.id
, "uColour" );
137 #endif /* SHADER_model_gate_H */