1 #ifndef SHADER_model_menu_H
2 #define SHADER_model_menu_H
3 static void shader_model_menu_link(void);
4 static void shader_model_menu_register(void);
5 static struct vg_shader _shader_model_menu
= {
7 .link
= shader_model_menu_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_menu.fs",
69 "out vec4 FragColor;\n"
71 "uniform sampler2D uTexMain;\n"
72 "uniform vec4 uColour;\n"
81 " vec4 diffuse = texture( uTexMain, aUv );\n"
83 " if( diffuse.a < 0.5 )\n"
86 " FragColor = vec4( diffuse.rgb, 1.0 ) * uColour;\n"
91 static GLuint _uniform_model_menu_uMdl
;
92 static GLuint _uniform_model_menu_uPv
;
93 static GLuint _uniform_model_menu_uPvmPrev
;
94 static GLuint _uniform_model_menu_uTexMain
;
95 static GLuint _uniform_model_menu_uColour
;
96 static void shader_model_menu_uMdl(m4x3f m
){
97 glUniformMatrix4x3fv(_uniform_model_menu_uMdl
,1,GL_FALSE
,(float*)m
);
99 static void shader_model_menu_uPv(m4x4f m
){
100 glUniformMatrix4fv(_uniform_model_menu_uPv
,1,GL_FALSE
,(float*)m
);
102 static void shader_model_menu_uPvmPrev(m4x4f m
){
103 glUniformMatrix4fv(_uniform_model_menu_uPvmPrev
,1,GL_FALSE
,(float*)m
);
105 static void shader_model_menu_uTexMain(int i
){
106 glUniform1i(_uniform_model_menu_uTexMain
,i
);
108 static void shader_model_menu_uColour(v4f v
){
109 glUniform4fv(_uniform_model_menu_uColour
,1,v
);
111 static void shader_model_menu_register(void){
112 vg_shader_register( &_shader_model_menu
);
114 static void shader_model_menu_use(void){ glUseProgram(_shader_model_menu
.id
); }
115 static void shader_model_menu_link(void){
116 _uniform_model_menu_uMdl
= glGetUniformLocation( _shader_model_menu
.id
, "uMdl" );
117 _uniform_model_menu_uPv
= glGetUniformLocation( _shader_model_menu
.id
, "uPv" );
118 _uniform_model_menu_uPvmPrev
= glGetUniformLocation( _shader_model_menu
.id
, "uPvmPrev" );
119 _uniform_model_menu_uTexMain
= glGetUniformLocation( _shader_model_menu
.id
, "uTexMain" );
120 _uniform_model_menu_uColour
= glGetUniformLocation( _shader_model_menu
.id
, "uColour" );
122 #endif /* SHADER_model_menu_H */