3 static void shader_water_link(void);
4 static void shader_water_register(void);
5 static struct vg_shader _shader_water
= {
7 .link
= shader_water_link
,
10 .orig_file
= "../shaders/water.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 " vec3 world_pos = uMdl * vec4( a_co, 1.0 );\n"
27 " gl_Position = uPv * vec4(world_pos,1.0);\n"
28 " aUv = vec2(world_pos[0],world_pos[2])*0.15;\n"
33 .orig_file
= "../shaders/water.fs",
35 "out vec4 FragColor;\n"
37 "uniform sampler2D uTexMain;\n"
38 "uniform sampler2D uTexDudv;\n"
39 "uniform vec2 uInvRes;\n"
40 "uniform float uTime;\n"
46 " vec2 ssuv = gl_FragCoord.xy*uInvRes;\n"
47 " vec4 dudva = texture( uTexDudv, aUv + vec2(uTime*0.04f,uTime*0.03f) );\n"
48 " vec4 dudvb = texture( uTexDudv, aUv - vec2(uTime*0.1,uTime*0.054) );\n"
50 " vec2 distortamt = (dudva.rg-0.5) * (dudvb.ba-0.5) * 2.0;\n"
52 " vec4 reflected = texture( uTexMain, ssuv+distortamt );\n"
53 " FragColor = vec4(reflected.rgb*0.1,reflected.a);\n"
58 static GLuint _uniform_water_uPv
;
59 static GLuint _uniform_water_uMdl
;
60 static GLuint _uniform_water_uTexMain
;
61 static GLuint _uniform_water_uTexDudv
;
62 static GLuint _uniform_water_uInvRes
;
63 static GLuint _uniform_water_uTime
;
64 static void shader_water_uPv(m4x4f m
){
65 glUniformMatrix4fv( _uniform_water_uPv
, 1, GL_FALSE
, (float *)m
);
67 static void shader_water_uMdl(m4x3f m
){
68 glUniformMatrix4x3fv( _uniform_water_uMdl
, 1, GL_FALSE
, (float *)m
);
70 static void shader_water_uTexMain(int i
){
71 glUniform1i( _uniform_water_uTexMain
, i
);
73 static void shader_water_uTexDudv(int i
){
74 glUniform1i( _uniform_water_uTexDudv
, i
);
76 static void shader_water_uInvRes(v2f v
){
77 glUniform2fv( _uniform_water_uInvRes
, 1, v
);
79 static void shader_water_uTime(float f
){
80 glUniform1f( _uniform_water_uTime
, f
);
82 static void shader_water_register(void){
83 vg_shader_register( &_shader_water
);
85 static void shader_water_use(void){ glUseProgram(_shader_water
.id
); }
86 static void shader_water_link(void){
87 _uniform_water_uPv
= glGetUniformLocation( _shader_water
.id
, "uPv" );
88 _uniform_water_uMdl
= glGetUniformLocation( _shader_water
.id
, "uMdl" );
89 _uniform_water_uTexMain
= glGetUniformLocation( _shader_water
.id
, "uTexMain" );
90 _uniform_water_uTexDudv
= glGetUniformLocation( _shader_water
.id
, "uTexDudv" );
91 _uniform_water_uInvRes
= glGetUniformLocation( _shader_water
.id
, "uInvRes" );
92 _uniform_water_uTime
= glGetUniformLocation( _shader_water
.id
, "uTime" );
94 #endif /* SHADER_water_H */