[Chapter 10 Lighting Fundamentals]
In Ambient Reflection part, I noticed the intensity
attribute is not there as it says in the book description
Common.h:
typedef struct {
LightType type;
vector_float3 position;
vector_float3 color;
vector_float3 specularColor;
float radius;
vector_float3 attenuation;
float coneAngle;
vector_float3 coneDirection;
float coneAttenuation;
float intensity; // <-- insert here
} Light;
SceneLighting.swift:
struct Lighting {
static func buildDefaultLight() -> Light {
var light = Light()
light.position = [0, 0, 0]
light.color = [1, 1, 1]
light.specularColor = [0.6, 0.6, 0.6]
light.attenuation = [1, 0, 0]
light.type = Sun
light.intensity = 0.1 // <-- insert here
return light
}
let ambientLight: Light = {
var light = Self.buildDefaultLight()
light.color = [0.05, 0.1, 0]
light.intensity = 0.5 // <-- change property here
light.type = Ambient
return light
}()
Lighting.metal:
float3 phongLighting(...) {
// code
case Ambient: {
ambientColor += light.color * light.intensity; // <-- that right ?
break;
}
// code
}