X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=shaders%2Fterrain.fs;h=6e01684cf9b85bb3825436488f5c2fc2c770e2de;hb=403726131f9b460c3264e4f64c46f8aaa82978fe;hp=98895a0d1ddd1c00df5eb3fb403d3911b9767940;hpb=dfee9022b3513fddec36f7ea70867ee5961a44da;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/shaders/terrain.fs b/shaders/terrain.fs index 98895a0..6e01684 100644 --- a/shaders/terrain.fs +++ b/shaders/terrain.fs @@ -1,29 +1,32 @@ -out vec4 FragColor; - uniform sampler2D uTexGarbage; uniform sampler2D uTexGradients; uniform vec3 uCamera; -uniform vec4 uPlane; +uniform vec3 uSandColour; +uniform vec2 uBlendOffset; in vec4 aColour; in vec2 aUv; in vec3 aNorm; in vec3 aCo; +in vec3 aWorldCo; -float water_depth( vec3 pos, vec3 dir, vec4 plane ) -{ - float d = dot( plane.xyz, dir ); - float t = dot((plane.xyz*plane.w - pos),plane.xyz) / d; - return t*0.05; -} +#include "common_world.glsl" +#include "motion_vectors_fs.glsl" void main() { + compute_motion_vectors(); + + // Colour + // ------ + vec3 vfrag = vec3(0.5,0.5,0.5); + + // ws modulation vec4 wgarbage = texture( uTexGarbage, aCo.xz * 0.015 ); // Creating normal patches vec3 modnorm = (wgarbage.rgb-0.4) * 1.4; - vec3 qnorm = normalize(floor(aNorm*4.0+modnorm) * 0.25); + vec3 qnorm = normalize(floor(aNorm*4.0+modnorm)*0.25) + vec3(0.001,0.0,0.0); vec2 dir = normalize(qnorm.xz); vec2 uvdiffuse = aCo.xz * 0.02; uvdiffuse = mat2(dir.y, dir.x, -dir.x, dir.y) * uvdiffuse; @@ -33,22 +36,27 @@ void main() // Colour blending float amtgrass = step(qnorm.y,0.6); - float amtsand = min(max((aCo.y + 90.0) * -0.08,0.0)*qnorm.y,1.0); - vec2 uvgradients = vec2( rgarbage.a, -amtgrass*0.125 ) + aUv; - vec3 diffuse = texture( uTexGradients, uvgradients ).rgb; - diffuse = mix( diffuse, vec3(1.0,0.9,0.7), amtsand ); + float amtsand = min(max((aCo.y - 10.0) * -0.1,0.0)*qnorm.y,1.0); + vec2 uvgradients = aUv + vec2( amtgrass + rgarbage.a*0.8 )*uBlendOffset; + vfrag = texture( uTexGradients, uvgradients ).rgb; + vfrag = mix( vfrag, uSandColour, amtsand ); - // Lighting - vec3 lightdir = vec3(0.95,0.0,-0.3); - vec3 shadow = pow(vec3(0.014,0.034,0.084),vec3(1.0/3.2)); - float light1 = dot( lightdir, mix(qnorm,aNorm,amtsand) )*0.5+0.5; - diffuse = diffuse * (light1*vec3(1.0,0.96,0.9)*1.2 + shadow*(1.0-light1)); + qnorm = mix( qnorm, aNorm, amtsand ); - // Specular lighting - vec3 halfview = normalize( uCamera - aCo ); - vec3 specdir = reflect( -lightdir, qnorm ); - float spec = pow(max(dot(halfview,specdir),0.0),10.0) * 0.2*rgarbage.r; - diffuse += spec * vec3(1.0,0.8,0.8); + if( g_light_preview == 1 ) + { + vfrag = vec3(0.5); + } + + // Lighting + vec3 halfview = uCamera - aCo; + float fdist = length( halfview ); + halfview /= fdist; + + vfrag = do_light_diffuse( vfrag, qnorm ); + vfrag = do_light_spec( vfrag, qnorm, halfview, 0.1 ); + vfrag = do_light_shadowing( vfrag ); + vfrag = apply_fog( vfrag, fdist ); - FragColor = vec4(diffuse, water_depth(aCo,halfview,uPlane)); + oColour = vec4(vfrag, 1.0 ); }