bvh interface and high perf gate
[carveJwlIkooP6JGAAIwe30JlM.git] / shaders / standard.h
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 = {
6 .name = "standard",
7 .link = shader_standard_link,
8 .vs =
9 {
10 .orig_file = "../shaders/standard.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 vec4 a_colour;\n"
15 "layout (location=3) in vec2 a_uv;\n"
16 "\n"
17 "#line 2 0 \n"
18 "\n"
19 "uniform mat4 uPv;\n"
20 "uniform mat4x3 uMdl;\n"
21 "\n"
22 "out vec4 aColour;\n"
23 "out vec2 aUv;\n"
24 "out vec3 aNorm;\n"
25 "out vec3 aCo;\n"
26 "\n"
27 "void main()\n"
28 "{\n"
29 " gl_Position = uPv * vec4( uMdl * vec4(a_co,1.0), 1.0 );\n"
30 " aColour = a_colour;\n"
31 " aUv = a_uv;\n"
32 " aNorm = mat3(uMdl) * a_norm;\n"
33 " aCo = a_co;\n"
34 "}\n"
35 ""},
36 .fs =
37 {
38 .orig_file = "../shaders/standard.fs",
39 .static_src =
40 "out vec4 FragColor;\n"
41 "\n"
42 "uniform sampler2D uTexMain;\n"
43 "uniform vec4 uColour;\n"
44 "\n"
45 "in vec4 aColour;\n"
46 "in vec2 aUv;\n"
47 "in vec3 aNorm;\n"
48 "in vec3 aCo;\n"
49 "\n"
50 "void main()\n"
51 "{\n"
52 " vec3 diffuse = texture( uTexMain, aUv ).rgb;\n"
53 " float light1 = max(0.0,dot(-vec3(0.5,-0.8,0.25), aNorm));\n"
54 " float light2 = max(0.0,dot(-vec3(-0.8,0.5,-0.25), aNorm));\n"
55 " diffuse += vec3(0.2,0.2,0.2) +\n"
56 " vec3(1.0,1.0,0.9)*light1 + \n"
57 " vec3(0.1,0.3,0.4)*light2;\n"
58 " FragColor = vec4(diffuse*uColour.rgb, aColour.a*uColour.a);\n"
59 "}\n"
60 ""},
61 };
62
63 static GLuint _uniform_standard_uPv;
64 static GLuint _uniform_standard_uMdl;
65 static GLuint _uniform_standard_uTexMain;
66 static GLuint _uniform_standard_uColour;
67 static void shader_standard_uPv(m4x4f m){
68 glUniformMatrix4fv( _uniform_standard_uPv, 1, GL_FALSE, (float *)m );
69 }
70 static void shader_standard_uMdl(m4x3f m){
71 glUniformMatrix4x3fv( _uniform_standard_uMdl, 1, GL_FALSE, (float *)m );
72 }
73 static void shader_standard_uTexMain(int i){
74 glUniform1i( _uniform_standard_uTexMain, i );
75 }
76 static void shader_standard_uColour(v4f v){
77 glUniform4fv( _uniform_standard_uColour, 1, v );
78 }
79 static void shader_standard_register(void){
80 vg_shader_register( &_shader_standard );
81 }
82 static void shader_standard_use(void){ glUseProgram(_shader_standard.id); }
83 static void shader_standard_link(void){
84 _uniform_standard_uPv = glGetUniformLocation( _shader_standard.id, "uPv" );
85 _uniform_standard_uMdl = glGetUniformLocation( _shader_standard.id, "uMdl" );
86 _uniform_standard_uTexMain = glGetUniformLocation( _shader_standard.id, "uTexMain" );
87 _uniform_standard_uColour = glGetUniformLocation( _shader_standard.id, "uColour" );
88 }
89 #endif /* SHADER_standard_H */