Add ambient light from point lights
This commit is contained in:
parent
55f293137f
commit
0562cd8aea
@ -91,6 +91,8 @@ void Shader::UpdatePointLights(PointLightList pointLights) {
|
||||
|
||||
glUniform1f(glGetUniformLocation(id, Util::ShaderArrayName("pointLights", i, "radius").c_str()), pointLights[i]->GetRadius());
|
||||
glUniform1f(glGetUniformLocation(id, Util::ShaderArrayName("pointLights", i, "ambient").c_str()), pointLights[i]->GetAmbient());
|
||||
glUniform1f(glGetUniformLocation(id, Util::ShaderArrayName("pointLights", i, "diffuse").c_str()), pointLights[i]->GetDiffuse());
|
||||
glUniform1f(glGetUniformLocation(id, Util::ShaderArrayName("pointLights", i, "specular").c_str()), pointLights[i]->GetSpecular());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -185,7 +185,8 @@ function init_point_lights()
|
||||
pointLight:Translate(couch.Vector3(i * -10.0, 0, -10))
|
||||
pointLight:SetRadius(10.0)
|
||||
pointLight:SetColor(color)
|
||||
pointLight:SetAmbient(1.0)
|
||||
pointLight:SetAmbient(0.2)
|
||||
pointLight:SetDiffuse(1.0)
|
||||
pointLight:SetSpecular(0.1)
|
||||
local lightBox = couch.Mesh.FromFile("../resources/cube.obj")
|
||||
lightBox:UniformScale(0.5);
|
||||
|
@ -55,13 +55,16 @@ struct Material {
|
||||
uniform DirectionalLight directionalLight;
|
||||
uniform Material material;
|
||||
|
||||
float calcDiffuseIntensity(in vec3 direction, in vec3 normal) {
|
||||
float diff = dot(normalize(direction), normalize(normal));
|
||||
return max(diff, 0.0);
|
||||
}
|
||||
|
||||
void calcDirectionalLight(in vec3 normal) {
|
||||
AMBIENT += directionalLight.ambient * directionalLight.color * material.ambient;
|
||||
|
||||
vec3 direction = -(VIEW * vec4(directionalLight.direction, 0.0)).xyz;
|
||||
float diff = dot(normalize(direction), normalize(normal));
|
||||
diff = max(diff, 0.0);
|
||||
DIFFUSE += directionalLight.diffuse * diff * directionalLight.color * material.diffuse;
|
||||
DIFFUSE += directionalLight.diffuse * directionalLight.color * material.diffuse * calcDiffuseIntensity(direction, normal);
|
||||
|
||||
vec3 viewDir = normalize((VIEW * MODEL * vec4(pos, 1.0)).xyz);
|
||||
vec3 reflectionDir = reflect(normalize(direction), normalize(normal));
|
||||
@ -72,10 +75,13 @@ void calcDirectionalLight(in vec3 normal) {
|
||||
}
|
||||
|
||||
void calcPointLight(in vec3 normal, in PointLight pointLight) {
|
||||
vec4 ray = VIEW * MODEL * vec4(pos, 1.0) - VIEW * vec4(pointLight.pos, 1.0);
|
||||
float dist = length(ray);
|
||||
vec3 direction = vec3(VIEW * vec4(pointLight.pos, 1.0) - VIEW * MODEL * vec4(pos, 1.0)).xyz;
|
||||
float dist = length(direction);
|
||||
|
||||
float attenuation = max(1.0 - dist * dist / pointLight.radius / pointLight.radius, 0.0);
|
||||
AMBIENT += pointLight.color * material.ambient * pointLight.ambient * attenuation;
|
||||
|
||||
DIFFUSE += pointLight.color * pointLight.diffuse * material.diffuse * calcDiffuseIntensity(direction, normal);
|
||||
}
|
||||
|
||||
void main() {
|
||||
|
Loading…
Reference in New Issue
Block a user