Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #version 150
- const vec3 GROUND_COL = vec3(0.8, 1.0, 0.5);
- const vec3 SKY_COL = vec3(0.5, 0.75, 1.0);
- in vec3 pass_colour;
- in vec3 pass_worldPos;
- in vec3 pass_worldNormal;
- in vec4 pass_material;//spec, shinyness, matFactor, flex
- out vec4 out_colour;
- uniform vec3 cameraPosition;
- uniform vec3 lightDirection;
- uniform vec3 lightColour;
- uniform vec3 lightSettings;//ambient, diffuse, shade
- void main(void){
- vec3 normal = normalize(pass_worldNormal);
- vec3 toCamera = normalize(cameraPosition - pass_worldPos);
- vec3 toLight = normalize(-lightDirection);//already normalized?
- vec3 reflectedView = reflect(-toCamera, normal);
- float sunDiffuse = clamp(dot(normal, toLight), 0.0, 1.0);
- float skyDiffuse = 0.5 + 0.5 * clamp(normal.y, 0.0, 1.0);
- float bounceDiffuse = 0.1 + 0.9 *clamp(-normal.y, 0.0, 1.0) * clamp(1.0 - 0.1 * pass_worldPos.y, 0.0, 1.0);
- float fresnel = pow(1.0 - clamp(dot(toCamera, normal), 0.0, 1.0), 2.5);
- float sunSpecular = pow(clamp(dot(reflectedView, -lightDirection), 0.0, 1.0), 8.0) * (0.8 + 5.0 * fresnel);
- float rimLight = fresnel;
- float skyReflection = smoothstep(0.0, 0.4, reflectedView.y) * (0.4 + 0.6 * fresnel);//use shinyness
- vec3 lighting = vec3(0.0);
- lighting += 1.2 * skyDiffuse * SKY_COL;
- lighting += 1.1 * sunDiffuse * lightColour;
- lighting += 0.2 * bounceDiffuse * GROUND_COL;
- vec3 finalColour = pass_colour * lighting;
- finalColour += 0.07 * skyReflection * SKY_COL * skyDiffuse;
- finalColour += 0.15 * rimLight * lightColour;
- finalColour += 0.25 * sunSpecular * lightColour;
- out_colour = vec4(pow(finalColour, vec3(0.4545)), 1.0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement