DonkeyKong64 grind crash
[carveJwlIkooP6JGAAIwe30JlM.git] / shaders / model_gate.h
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 = {
6 .name = "model_gate",
7 .link = shader_model_gate_link,
8 .vs =
9 {
10 .orig_file = "shaders/model_gate.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 vec2 a_uv;\n"
15 "\n"
16 "uniform mat4 uPv;\n"
17 "uniform mat4x3 uMdl;\n"
18 "\n"
19 "out vec3 aNorm;\n"
20 "out vec2 aUv;\n"
21 "out vec3 aCo;\n"
22 "\n"
23 "void main()\n"
24 "{\n"
25 " vec3 world_pos = uMdl * vec4( a_co, 1.0 );\n"
26 " gl_Position = uPv * vec4(world_pos,1.0);\n"
27 "\n"
28 " aNorm = a_norm;\n"
29 " aCo = world_pos;\n"
30 " aUv = a_uv;\n"
31 "}\n"
32 ""},
33 .fs =
34 {
35 .orig_file = "shaders/model_gate_lq.fs",
36 .static_src =
37 "out vec4 FragColor;\n"
38 "\n"
39 "uniform float uTime;\n"
40 "uniform vec3 uCam;\n"
41 "uniform vec2 uInvRes;\n"
42 "uniform vec4 uColour;\n"
43 "\n"
44 "in vec3 aNorm;\n"
45 "in vec2 aUv;\n"
46 "in vec3 aCo;\n"
47 "\n"
48 "void main()\n"
49 "{\n"
50 " vec2 ssuv = gl_FragCoord.xy;\n"
51 " float opacity = 1.0-smoothstep(0.0,1.0,aUv.y+uColour.a);\n"
52 " \n"
53 " vec3 vDither = vec3( dot( vec2( 171.0, 231.0 ), ssuv) );\n"
54 " float dither = fract( vDither.g / 71.0 ) - 0.5;\n"
55 "\n"
56 " if( opacity+dither<0.5 )\n"
57 " discard;\n"
58 "\n"
59 " FragColor = uColour;\n"
60 "}\n"
61 ""},
62 };
63
64 static GLuint _uniform_model_gate_uPv;
65 static GLuint _uniform_model_gate_uMdl;
66 static GLuint _uniform_model_gate_uTime;
67 static GLuint _uniform_model_gate_uCam;
68 static GLuint _uniform_model_gate_uInvRes;
69 static GLuint _uniform_model_gate_uColour;
70 static void shader_model_gate_uPv(m4x4f m){
71 glUniformMatrix4fv(_uniform_model_gate_uPv,1,GL_FALSE,(float*)m);
72 }
73 static void shader_model_gate_uMdl(m4x3f m){
74 glUniformMatrix4x3fv(_uniform_model_gate_uMdl,1,GL_FALSE,(float*)m);
75 }
76 static void shader_model_gate_uTime(float f){
77 glUniform1f(_uniform_model_gate_uTime,f);
78 }
79 static void shader_model_gate_uCam(v3f v){
80 glUniform3fv(_uniform_model_gate_uCam,1,v);
81 }
82 static void shader_model_gate_uInvRes(v2f v){
83 glUniform2fv(_uniform_model_gate_uInvRes,1,v);
84 }
85 static void shader_model_gate_uColour(v4f v){
86 glUniform4fv(_uniform_model_gate_uColour,1,v);
87 }
88 static void shader_model_gate_register(void){
89 vg_shader_register( &_shader_model_gate );
90 }
91 static void shader_model_gate_use(void){ glUseProgram(_shader_model_gate.id); }
92 static void shader_model_gate_link(void){
93 _uniform_model_gate_uPv = glGetUniformLocation( _shader_model_gate.id, "uPv" );
94 _uniform_model_gate_uMdl = glGetUniformLocation( _shader_model_gate.id, "uMdl" );
95 _uniform_model_gate_uTime = glGetUniformLocation( _shader_model_gate.id, "uTime" );
96 _uniform_model_gate_uCam = glGetUniformLocation( _shader_model_gate.id, "uCam" );
97 _uniform_model_gate_uInvRes = glGetUniformLocation( _shader_model_gate.id, "uInvRes" );
98 _uniform_model_gate_uColour = glGetUniformLocation( _shader_model_gate.id, "uColour" );
99 }
100 #endif /* SHADER_model_gate_H */