Point light specular intensity and shininess

This commit is contained in:
Dane Johnson 2021-03-04 15:10:48 -06:00
parent 0562cd8aea
commit a0936c92a9
2 changed files with 15 additions and 6 deletions

View File

@ -190,6 +190,9 @@ function init_point_lights()
pointLight:SetSpecular(0.1) pointLight:SetSpecular(0.1)
local lightBox = couch.Mesh.FromFile("../resources/cube.obj") local lightBox = couch.Mesh.FromFile("../resources/cube.obj")
lightBox:UniformScale(0.5); lightBox:UniformScale(0.5);
local material = lightBox:GetMaterial(0)
material.ambient = color
lightBox:SetMaterial(0, material)
pointLight:AddChild(lightBox); pointLight:AddChild(lightBox);
couch.Node.GetRoot():AddChild(pointLight:Instance()) couch.Node.GetRoot():AddChild(pointLight:Instance())
end end

View File

@ -60,18 +60,22 @@ float calcDiffuseIntensity(in vec3 direction, in vec3 normal) {
return max(diff, 0.0); return max(diff, 0.0);
} }
float calcSpecularIntensity(in vec3 direction, in vec3 normal, in int shininess) {
vec3 viewDir = normalize((VIEW * MODEL * vec4(pos, 1.0)).xyz);
vec3 reflectionDir = reflect(normalize(direction), normalize(normal));
float spec = dot(viewDir, reflectionDir);
spec = max(spec, 0.0);
spec = pow(spec, shininess);
return spec;
}
void calcDirectionalLight(in vec3 normal) { void calcDirectionalLight(in vec3 normal) {
AMBIENT += directionalLight.ambient * directionalLight.color * material.ambient; AMBIENT += directionalLight.ambient * directionalLight.color * material.ambient;
vec3 direction = -(VIEW * vec4(directionalLight.direction, 0.0)).xyz; vec3 direction = -(VIEW * vec4(directionalLight.direction, 0.0)).xyz;
DIFFUSE += directionalLight.diffuse * directionalLight.color * material.diffuse * calcDiffuseIntensity(direction, normal); DIFFUSE += directionalLight.diffuse * directionalLight.color * material.diffuse * calcDiffuseIntensity(direction, normal);
vec3 viewDir = normalize((VIEW * MODEL * vec4(pos, 1.0)).xyz); SPECULAR += directionalLight.color * material.specular * calcSpecularIntensity(direction, normal, material.shininess);
vec3 reflectionDir = reflect(normalize(direction), normalize(normal));
float spec = dot(viewDir, reflectionDir);
spec = max(spec, 0.0);
spec = pow(spec, material.shininess);
SPECULAR += directionalLight.color * (spec * material.specular);
} }
void calcPointLight(in vec3 normal, in PointLight pointLight) { void calcPointLight(in vec3 normal, in PointLight pointLight) {
@ -82,6 +86,8 @@ void calcPointLight(in vec3 normal, in PointLight pointLight) {
AMBIENT += pointLight.color * material.ambient * pointLight.ambient * attenuation; AMBIENT += pointLight.color * material.ambient * pointLight.ambient * attenuation;
DIFFUSE += pointLight.color * pointLight.diffuse * material.diffuse * calcDiffuseIntensity(direction, normal); DIFFUSE += pointLight.color * pointLight.diffuse * material.diffuse * calcDiffuseIntensity(direction, normal);
SPECULAR += pointLight.color * material.specular * calcSpecularIntensity(direction, normal, material.shininess);
} }
void main() { void main() {