Ik revision
[carveJwlIkooP6JGAAIwe30JlM.git] / shaders / gatelq.h
1 #ifndef SHADER_gatelq_H
2 #define SHADER_gatelq_H
3 static void shader_gatelq_link(void);
4 static void shader_gatelq_register(void);
5 static struct vg_shader _shader_gatelq = {
6 .name = "gatelq",
7 .link = shader_gatelq_link,
8 .vs =
9 {
10 .orig_file = "../../shaders/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 "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"
18 "\n"
19 "#line 2 0 \n"
20 "uniform mat4 uPv;\n"
21 "uniform mat4x3 uMdl;\n"
22 "\n"
23 "out vec3 aNorm;\n"
24 "out vec2 aUv;\n"
25 "out vec3 aCo;\n"
26 "\n"
27 "void main()\n"
28 "{\n"
29 " vec3 world_pos = uMdl * vec4( a_co, 1.0 );\n"
30 " gl_Position = uPv * vec4(world_pos,1.0);\n"
31 "\n"
32 " aNorm = a_norm;\n"
33 " aCo = world_pos;\n"
34 " aUv = a_uv;\n"
35 "}\n"
36 ""},
37 .fs =
38 {
39 .orig_file = "../../shaders/gate_lq.fs",
40 .static_src =
41 "out vec4 FragColor;\n"
42 "\n"
43 "uniform float uTime;\n"
44 "uniform vec3 uCam;\n"
45 "uniform vec2 uInvRes;\n"
46 "\n"
47 "in vec3 aNorm;\n"
48 "in vec2 aUv;\n"
49 "in vec3 aCo;\n"
50 "\n"
51 "void main()\n"
52 "{\n"
53 " vec2 ssuv = gl_FragCoord.xy;\n"
54 " float opacity = 1.0-smoothstep(0.4,1.0,aUv.y);\n"
55 " \n"
56 " vec3 vDither = vec3( dot( vec2( 171.0, 231.0 ), ssuv) );\n"
57 " float dither = fract( vDither.g / 71.0 ) - 0.5;\n"
58 "\n"
59 " if( opacity+dither<0.5 )\n"
60 " discard;\n"
61 "\n"
62 " FragColor = vec4( 0.0, 1.0, 0.0, 1.0 );\n"
63 "}\n"
64 ""},
65 };
66
67 static GLuint _uniform_gatelq_uPv;
68 static GLuint _uniform_gatelq_uMdl;
69 static GLuint _uniform_gatelq_uTime;
70 static GLuint _uniform_gatelq_uCam;
71 static GLuint _uniform_gatelq_uInvRes;
72 static void shader_gatelq_uPv(m4x4f m){
73 glUniformMatrix4fv( _uniform_gatelq_uPv, 1, GL_FALSE, (float *)m );
74 }
75 static void shader_gatelq_uMdl(m4x3f m){
76 glUniformMatrix4x3fv( _uniform_gatelq_uMdl, 1, GL_FALSE, (float *)m );
77 }
78 static void shader_gatelq_uTime(float f){
79 glUniform1f( _uniform_gatelq_uTime, f );
80 }
81 static void shader_gatelq_uCam(v3f v){
82 glUniform3fv( _uniform_gatelq_uCam, 1, v );
83 }
84 static void shader_gatelq_uInvRes(v2f v){
85 glUniform2fv( _uniform_gatelq_uInvRes, 1, v );
86 }
87 static void shader_gatelq_register(void){
88 vg_shader_register( &_shader_gatelq );
89 }
90 static void shader_gatelq_use(void){ glUseProgram(_shader_gatelq.id); }
91 static void shader_gatelq_link(void){
92 _uniform_gatelq_uPv = glGetUniformLocation( _shader_gatelq.id, "uPv" );
93 _uniform_gatelq_uMdl = glGetUniformLocation( _shader_gatelq.id, "uMdl" );
94 _uniform_gatelq_uTime = glGetUniformLocation( _shader_gatelq.id, "uTime" );
95 _uniform_gatelq_uCam = glGetUniformLocation( _shader_gatelq.id, "uCam" );
96 _uniform_gatelq_uInvRes = glGetUniformLocation( _shader_gatelq.id, "uInvRes" );
97 }
98 #endif /* SHADER_gatelq_H */