+#ifndef SHADER_planeinf_H
+#define SHADER_planeinf_H
+static void shader_planeinf_link(void);
+static void shader_planeinf_register(void);
+static struct vg_shader _shader_planeinf = {
+ .name = "planeinf",
+ .link = shader_planeinf_link,
+ .vs =
+{
+.orig_file = "../shaders/standard.vs",
+.static_src =
+"layout (location=0) in vec3 a_co;\n"
+"layout (location=1) in vec3 a_norm;\n"
+"layout (location=2) in vec4 a_colour;\n"
+"layout (location=3) in vec2 a_uv;\n"
+"\n"
+"#line 2 0 \n"
+"\n"
+"uniform mat4 uPv;\n"
+"uniform mat4x3 uMdl;\n"
+"\n"
+"out vec4 aColour;\n"
+"out vec2 aUv;\n"
+"out vec3 aNorm;\n"
+"out vec3 aCo;\n"
+"\n"
+"void main()\n"
+"{\n"
+" gl_Position = uPv * vec4( uMdl * vec4(a_co,1.0), 1.0 );\n"
+" aColour = a_colour;\n"
+" aUv = a_uv;\n"
+" aNorm = mat3(uMdl) * a_norm;\n"
+" aCo = a_co;\n"
+"}\n"
+""},
+ .fs =
+{
+.orig_file = "../shaders/planeinf.fs",
+.static_src =
+"vec4 water_surf( vec3 halfview, vec3 vnorm, float depthvalue, \n"
+" vec4 beneath, vec4 above )\n"
+"{\n"
+" vec3 colour_shore = vec3( 0.21, 0.6, 0.8 );\n"
+" vec3 colour_ocean = vec3( 0.01, 0.1, 0.2 );\n"
+" vec3 surface_tint = mix(colour_shore, colour_ocean, depthvalue);\n"
+"\n"
+" float ffresnel = pow(1.0-dot( vnorm, halfview ),5.0);\n"
+"\n"
+" vec3 lightdir = vec3(0.95,0.0,-0.3);\n"
+" vec3 specdir = reflect( -lightdir, vnorm );\n"
+" float spec = pow(max(dot(halfview,specdir),0.0),20.0)*0.3;\n"
+" \n"
+" // Depth \n"
+" float depthblend = pow( beneath.a,0.8 );\n"
+"\n"
+" // Composite\n"
+" vec3 vsurface = mix(surface_tint, above.rgb, ffresnel );\n"
+" //vsurface += spec;\n"
+"\n"
+" return vec4( vsurface,depthblend );\n"
+"}\n"
+"\n"
+"#line 2 0 \n"
+"\n"
+"out vec4 FragColor;\n"
+"\n"
+"uniform vec3 uCamera;\n"
+"uniform vec4 uPlane;\n"
+"\n"
+"in vec4 aColour;\n"
+"in vec2 aUv;\n"
+"in vec3 aNorm;\n"
+"in vec3 aCo;\n"
+"\n"
+"float ray_plane( vec3 pos, vec3 dir, vec4 plane )\n"
+"{\n"
+" float d = dot( plane.xyz, dir );\n"
+" float t = dot((plane.xyz*plane.w - pos),plane.xyz) / d;\n"
+" return t;\n"
+"}\n"
+"\n"
+"void main()\n"
+"{\n"
+" float fdist = ray_plane( uCamera, -aNorm, uPlane );\n"
+" vec3 world_pos = uCamera - aNorm*fdist;\n"
+"\n"
+" FragColor = vec4(fract(world_pos*0.1),1.0);\n"
+"}\n"
+""},
+};
+
+static GLuint _uniform_planeinf_uPv;
+static GLuint _uniform_planeinf_uMdl;
+static GLuint _uniform_planeinf_uCamera;
+static GLuint _uniform_planeinf_uPlane;
+static void shader_planeinf_uPv(m4x4f m){
+ glUniformMatrix4fv( _uniform_planeinf_uPv, 1, GL_FALSE, (float *)m );
+}
+static void shader_planeinf_uMdl(m4x3f m){
+ glUniformMatrix4x3fv( _uniform_planeinf_uMdl, 1, GL_FALSE, (float *)m );
+}
+static void shader_planeinf_uCamera(v3f v){
+ glUniform3fv( _uniform_planeinf_uCamera, 1, v );
+}
+static void shader_planeinf_uPlane(v4f v){
+ glUniform4fv( _uniform_planeinf_uPlane, 1, v );
+}
+static void shader_planeinf_register(void){
+ vg_shader_register( &_shader_planeinf );
+}
+static void shader_planeinf_use(void){ glUseProgram(_shader_planeinf.id); }
+static void shader_planeinf_link(void){
+ _uniform_planeinf_uPv = glGetUniformLocation( _shader_planeinf.id, "uPv" );
+ _uniform_planeinf_uMdl = glGetUniformLocation( _shader_planeinf.id, "uMdl" );
+ _uniform_planeinf_uCamera = glGetUniformLocation( _shader_planeinf.id, "uCamera" );
+ _uniform_planeinf_uPlane = glGetUniformLocation( _shader_planeinf.id, "uPlane" );
+}
+#endif /* SHADER_planeinf_H */