1 #ifndef SHADER_standard_H
2 #define SHADER_standard_H
3 static void shader_standard_link(void);
4 static void shader_standard_register(void);
5 static struct vg_shader _shader_standard
= {
7 .link
= shader_standard_link
,
10 .orig_file
= "../shaders/standard.vs",
12 "layout (location=0) in vec3 a_co;\n"
13 "layout (location=1) in vec3 a_norm;\n"
14 "layout (location=2) in vec4 a_colour;\n"
15 "layout (location=3) in vec2 a_uv;\n"
20 "uniform mat4x3 uMdl;\n"
26 "out vec3 aWorldCo;\n"
30 " vec3 world_pos = uMdl * vec4(a_co,1.0);\n"
31 " gl_Position = uPv * vec4( world_pos, 1.0 );\n"
32 " aColour = a_colour;\n"
34 " aNorm = mat3(uMdl) * a_norm;\n"
36 " aWorldCo = world_pos;\n"
41 .orig_file
= "../shaders/standard.fs",
43 "out vec4 FragColor;\n"
45 "uniform sampler2D uTexMain;\n"
46 "uniform vec4 uColour;\n"
55 " vec3 diffuse = texture( uTexMain, aUv ).rgb;\n"
56 " float light1 = max(0.0,dot(-vec3(0.5,-0.8,0.25), aNorm));\n"
57 " float light2 = max(0.0,dot(-vec3(-0.8,0.5,-0.25), aNorm));\n"
58 " diffuse += vec3(0.2,0.2,0.2) +\n"
59 " vec3(1.0,1.0,0.9)*light1 + \n"
60 " vec3(0.1,0.3,0.4)*light2;\n"
61 " FragColor = vec4(diffuse*uColour.rgb, aColour.a*uColour.a);\n"
66 static GLuint _uniform_standard_uPv
;
67 static GLuint _uniform_standard_uMdl
;
68 static GLuint _uniform_standard_uTexMain
;
69 static GLuint _uniform_standard_uColour
;
70 static void shader_standard_uPv(m4x4f m
){
71 glUniformMatrix4fv( _uniform_standard_uPv
, 1, GL_FALSE
, (float *)m
);
73 static void shader_standard_uMdl(m4x3f m
){
74 glUniformMatrix4x3fv( _uniform_standard_uMdl
, 1, GL_FALSE
, (float *)m
);
76 static void shader_standard_uTexMain(int i
){
77 glUniform1i( _uniform_standard_uTexMain
, i
);
79 static void shader_standard_uColour(v4f v
){
80 glUniform4fv( _uniform_standard_uColour
, 1, v
);
82 static void shader_standard_register(void){
83 vg_shader_register( &_shader_standard
);
85 static void shader_standard_use(void){ glUseProgram(_shader_standard
.id
); }
86 static void shader_standard_link(void){
87 _uniform_standard_uPv
= glGetUniformLocation( _shader_standard
.id
, "uPv" );
88 _uniform_standard_uMdl
= glGetUniformLocation( _shader_standard
.id
, "uMdl" );
89 _uniform_standard_uTexMain
= glGetUniformLocation( _shader_standard
.id
, "uTexMain" );
90 _uniform_standard_uColour
= glGetUniformLocation( _shader_standard
.id
, "uColour" );
92 #endif /* SHADER_standard_H */