Untitled
unknown
plain_text
a year ago
2.1 kB
7
Indexable
switch(Lightmode){ case 0: { vec3 i = normalize(light.position); vec3 j = normalize(cameraPosition - vertex_pos); vec3 k = normalize(i + j); vec3 l = normalize(vertex_normal); vec3 ambient = light.ambient * material.Ka; vec3 diffuse = max(dot(i, l), 0.0) * light.diffuse * material.Kd; vec3 specular = pow(max(dot(k, l), 0.0), shininess) * light.specular * material.Ks; vertex_color = ambient + diffuse + specular; break; } case 1: { vec3 i = normalize(light.position - vertex_pos); vec3 j = normalize(cameraPosition - vertex_pos); vec3 k = normalize(i + j); vec3 l = normalize(vertex_normal); vec3 ambient = light.ambient * material.Ka; vec3 diffuse = max(dot(i, l), 0.0) * light.diffuse * material.Kd; vec3 specular = pow(max(dot(k, l), 0.0), shininess) * light.specular * material.Ks; float dist = length(light.position - vertex_pos); float attenuation = light.Constant + light.Linear * dist + light.Quadratic * dist * dist; float f = min(1. / attenuation, 1.); vertex_color = ambient + f * (diffuse + specular); break; } case 2: { vec3 i = normalize(light.position - vertex_pos); vec3 j = normalize(cameraPosition - vertex_pos); vec3 k = normalize(i + j); vec3 l = normalize(vertex_normal); vec3 ambient = light.ambient * material.Ka; vec3 diffuse = max(dot(i, l), 0.0) * light.diffuse * material.Kd; vec3 specular = pow(max(dot(k, l), 0.0), shininess) * light.specular * material.Ks; float dist = length(light.position - vertex_pos); float attenuation = light.Constant + light.Linear * dist + light.Quadratic * dist * dist; float f = min(1. / attenuation, 1.); vec3 x = normalize(vertex_pos - light.position); vec3 y = normalize(spotlight.direction); float xy = dot(x, y); float spoteffect = 0; if(xy > cos(spotlight.cutoff * acos(-1) / 180.0)) spoteffect = pow(max(xy, 0.0), spotlight.exponent); vertex_color = ambient + spoteffect * f * (diffuse + specular); break; } default: break; }
Editor is loading...
Leave a Comment