"\n"
"out vec4 aUv;\n"
"out vec3 aCo;\n"
+"out float aDepth;\n"
"\n"
"void main()\n"
"{\n"
" gl_Position = uPv * vec4(world_pos,1.0);\n"
"\n"
" vec2 depth_coords = (world_pos.xz-uDepthBounds.xy)*uDepthBounds.zw;\n"
-" aUv = vec4(world_pos.xz*0.1,depth_coords);\n"
+" aUv = vec4(world_pos.xz*0.01,depth_coords);\n"
" aCo = world_pos;\n"
+"\n"
+" aDepth = gl_Position.z;\n"
"}\n"
""},
.fs =
"uniform sampler2D uTexMain;\n"
"uniform sampler2D uTexDudv;\n"
"uniform sampler2D uTexDepth;\n"
+"uniform sampler2D uTexBack;\n"
+"\n"
"uniform vec2 uInvRes;\n"
"uniform float uTime;\n"
"\n"
+"uniform vec3 uCamera;\n"
+"uniform float uSurfaceY;\n"
+"\n"
"in vec4 aUv;\n"
"in vec3 aCo;\n"
+"in float aDepth;\n"
"\n"
"void main()\n"
"{\n"
+" // Reflected and warped texture\n"
" vec2 ssuv = gl_FragCoord.xy*uInvRes;\n"
-" vec4 dudva = texture( uTexDudv, aUv.xy + vec2(uTime*0.04f,uTime*0.03f) );\n"
-" vec4 dudvb = texture( uTexDudv, aUv.xy - vec2(uTime*0.1,uTime*0.054) );\n"
"\n"
-" vec2 distortamt = (dudva.rg-0.5) * (dudvb.ba-0.5) * 2.0;\n"
+" vec4 dudva = texture( uTexDudv, aUv.xy - vec2(uTime*0.004f,uTime*0.003f) );\n"
+" vec4 dudvb = texture( uTexDudv, aUv.xy*0.7 - vec2(uTime*0.01,uTime*0.0054) );\n"
+" vec2 distortamt = (dudva.rg-0.5) * (dudvb.ba-0.5) * 0.6;\n"
"\n"
" vec4 reflected = texture( uTexMain, ssuv+distortamt );\n"
+" \n"
+" // Surface colour composite\n"
" float depthvalue = texture( uTexDepth, aUv.zw ).r;\n"
-" float opacity = smoothstep( 0.0, 0.1, depthvalue );\n"
"\n"
-" vec3 colour_shore = vec3( 0.96, 0.98, 0.9 );\n"
-" vec3 colour_ocean = vec3( 0.61, 0.84, 0.9 );\n"
-" vec3 surface_tint = mix( colour_shore, colour_ocean, depthvalue );\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, pow(depthvalue,1.8))*1.5;\n"
+" \n"
+" // Foam\n"
+" float fband = fract( aCo.z*0.1+uTime*0.1-depthvalue*10.0 );\n"
+" fband = step( fband+dudvb.g*0.8, 0.5 ) * max((1.0-depthvalue*4.0),0.0);\n"
"\n"
-" vec3 comp_surf = mix(pow(surface_tint,vec3(6.0))*0.6,reflected.rgb, 0.7);\n"
+" // Lighting\n"
+" vec3 surfnorm = vec3(distortamt.x,1.0,distortamt.y);\n"
" \n"
-" float band = fract( aCo.z*0.1+uTime*0.1-depthvalue*10.0 );\n"
-" band = step( band + dudvb.g*0.8, 0.5 ) * max((1.0-depthvalue*4.0),0.0);\n"
+" vec3 halfview = -normalize( aCo-uCamera );\n"
+" float ffresnel = pow(1.0-dot( surfnorm, halfview ),5.0);\n"
"\n"
-" FragColor = vec4(comp_surf + band*0.2,opacity+band*0.2);\n"
+" vec3 lightdir = vec3(0.95,0.0,-0.3);\n"
+" vec3 specdir = reflect( -lightdir, surfnorm );\n"
+" float spec = pow(max(dot(halfview,specdir),0.0),20.0)*0.3;\n"
+" \n"
+" // Depth \n"
+" vec4 backsample = texture( uTexBack, ssuv+distortamt*0.1 );\n"
+" float depthblend = pow(backsample.a,0.8);\n"
+"\n"
+" // Composite\n"
+" vec3 vsurface = mix(surface_tint*backsample.rgb, reflected.rgb, ffresnel );\n"
+" vsurface += spec;\n"
+" \n"
+" FragColor = mix( vec4(vsurface,depthblend), vec4(1.0,1.0,1.0,0.8), fband );\n"
"}\n"
""},
};
static GLuint _uniform_water_uTexMain;
static GLuint _uniform_water_uTexDudv;
static GLuint _uniform_water_uTexDepth;
+static GLuint _uniform_water_uTexBack;
static GLuint _uniform_water_uInvRes;
static GLuint _uniform_water_uTime;
+static GLuint _uniform_water_uCamera;
+static GLuint _uniform_water_uSurfaceY;
static void shader_water_uPv(m4x4f m){
glUniformMatrix4fv( _uniform_water_uPv, 1, GL_FALSE, (float *)m );
}
static void shader_water_uTexDepth(int i){
glUniform1i( _uniform_water_uTexDepth, i );
}
+static void shader_water_uTexBack(int i){
+ glUniform1i( _uniform_water_uTexBack, i );
+}
static void shader_water_uInvRes(v2f v){
glUniform2fv( _uniform_water_uInvRes, 1, v );
}
static void shader_water_uTime(float f){
glUniform1f( _uniform_water_uTime, f );
}
+static void shader_water_uCamera(v3f v){
+ glUniform3fv( _uniform_water_uCamera, 1, v );
+}
+static void shader_water_uSurfaceY(float f){
+ glUniform1f( _uniform_water_uSurfaceY, f );
+}
static void shader_water_register(void){
vg_shader_register( &_shader_water );
}
_uniform_water_uTexMain = glGetUniformLocation( _shader_water.id, "uTexMain" );
_uniform_water_uTexDudv = glGetUniformLocation( _shader_water.id, "uTexDudv" );
_uniform_water_uTexDepth = glGetUniformLocation( _shader_water.id, "uTexDepth" );
+ _uniform_water_uTexBack = glGetUniformLocation( _shader_water.id, "uTexBack" );
_uniform_water_uInvRes = glGetUniformLocation( _shader_water.id, "uInvRes" );
_uniform_water_uTime = glGetUniformLocation( _shader_water.id, "uTime" );
+ _uniform_water_uCamera = glGetUniformLocation( _shader_water.id, "uCamera" );
+ _uniform_water_uSurfaceY = glGetUniformLocation( _shader_water.id, "uSurfaceY" );
}
#endif /* SHADER_water_H */