X-Git-Url: https://codewiz.org/gitweb?p=mandelwow.git;a=blobdiff_plain;f=shaded.vert;h=e21f5fcbd6cdf4478054ad5331b1ac80dab69a2b;hp=4f3035c3a5c3400fee32c609a55d5e2764ecb228;hb=e909401ee19ae946d8888dc3aa75d269f408fb92;hpb=c298ca511683f329dfedd18bf9490520586cf8cf diff --git a/shaded.vert b/shaded.vert index 4f3035c..e21f5fc 100644 --- a/shaded.vert +++ b/shaded.vert @@ -3,20 +3,22 @@ precision lowp float; in vec3 position; in vec3 normal; -out vec4 color; +out vec4 color; // Shaded color -uniform mat4 perspective; -uniform mat4 view; uniform mat4 model; +uniform mat4 perspview; +uniform vec3 col; void main() { - mat4 modelview = view * model; - mat4 m = perspective * modelview; - vec3 dark = vec3(0.0, 0.0, 0.1); - vec3 bright = vec3(0.0, 0.0, 0.9); - vec3 u_light = vec3(-0.5, -0.5, -1.); + mat4 m = perspview * model; + vec3 dark = col * 0.1; + vec3 u_light = vec3(-0.5, -0.7, -0.6); vec3 v_normal = transpose(inverse(mat3(model))) * normal; - float brightness = max(dot(normalize(v_normal), normalize(u_light)), 0.0); - color = vec4(mix(dark, bright, brightness), 1.0); + + float distance = model[3][2]; + float attenuation = 1. / (1. + distance * distance * 0.05); + float brightness = max(dot(normalize(v_normal), normalize(u_light)) * attenuation, 0.0); + color = vec4(mix(dark, col, brightness), 1.0); + gl_Position = m * vec4(position, 1.0); }