|
@@ -36,84 +36,82 @@ void phongModel(vec4 position, vec3 normal, vec3 camDir, vec3 matAmbient, vec3 m
|
|
|
vec3 diffuseTotal = vec3(0.0);
|
|
vec3 diffuseTotal = vec3(0.0);
|
|
|
vec3 specularTotal = vec3(0.0);
|
|
vec3 specularTotal = vec3(0.0);
|
|
|
|
|
|
|
|
- {{if .AmbientLightsMax }}
|
|
|
|
|
- for (int i = 0; i < {{.AmbientLightsMax}}; i++) {
|
|
|
|
|
- ambientTotal += AmbientLightColor[i] * matAmbient;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ {{ range loop .AmbientLightsMax }}
|
|
|
|
|
+ ambientTotal += AmbientLightColor[{{.}}] * matAmbient;
|
|
|
{{ end }}
|
|
{{ end }}
|
|
|
|
|
|
|
|
- {{if .DirLightsMax }}
|
|
|
|
|
- for (int i = 0; i < {{.DirLightsMax}}; i++) {
|
|
|
|
|
|
|
+ {{ range loop .DirLightsMax }}
|
|
|
|
|
+ {
|
|
|
// Diffuse reflection
|
|
// Diffuse reflection
|
|
|
// DirLightPosition is the direction of the current light
|
|
// DirLightPosition is the direction of the current light
|
|
|
- vec3 lightDirection = normalize(DirLightPosition[i]);
|
|
|
|
|
|
|
+ vec3 lightDirection = normalize(DirLightPosition[{{.}}]);
|
|
|
// Calculates the dot product between the light direction and this vertex normal.
|
|
// Calculates the dot product between the light direction and this vertex normal.
|
|
|
float dotNormal = max(dot(lightDirection, normal), 0.0);
|
|
float dotNormal = max(dot(lightDirection, normal), 0.0);
|
|
|
- diffuseTotal += DirLightColor[i] * matDiffuse * dotNormal;
|
|
|
|
|
|
|
+ diffuseTotal += DirLightColor[{{.}}] * matDiffuse * dotNormal;
|
|
|
|
|
|
|
|
// Specular reflection
|
|
// Specular reflection
|
|
|
// Calculates the light reflection vector
|
|
// Calculates the light reflection vector
|
|
|
vec3 ref = reflect(-lightDirection, normal);
|
|
vec3 ref = reflect(-lightDirection, normal);
|
|
|
if (dotNormal > 0.0) {
|
|
if (dotNormal > 0.0) {
|
|
|
- specularTotal += DirLightColor[i] * MatSpecularColor * pow(max(dot(ref, camDir), 0.0), MatShininess);
|
|
|
|
|
|
|
+ specularTotal += DirLightColor[{{.}}] * MatSpecularColor * pow(max(dot(ref, camDir), 0.0), MatShininess);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
{{ end }}
|
|
{{ end }}
|
|
|
|
|
|
|
|
- {{if .PointLightsMax }}
|
|
|
|
|
- for (int i = 0; i < {{.PointLightsMax}}; i++) {
|
|
|
|
|
|
|
+ {{ range loop .PointLightsMax }}
|
|
|
|
|
+ {
|
|
|
// Calculates the direction and distance from the current vertex to this point light.
|
|
// Calculates the direction and distance from the current vertex to this point light.
|
|
|
- vec3 lightDirection = PointLightPosition[i] - vec3(position);
|
|
|
|
|
|
|
+ vec3 lightDirection = PointLightPosition[{{.}}] - vec3(position);
|
|
|
float lightDistance = length(lightDirection);
|
|
float lightDistance = length(lightDirection);
|
|
|
// Normalizes the lightDirection
|
|
// Normalizes the lightDirection
|
|
|
lightDirection = lightDirection / lightDistance;
|
|
lightDirection = lightDirection / lightDistance;
|
|
|
// Calculates the attenuation due to the distance of the light
|
|
// Calculates the attenuation due to the distance of the light
|
|
|
- float attenuation = 1.0 / (1.0 + PointLightLinearDecay[i] * lightDistance +
|
|
|
|
|
- PointLightQuadraticDecay[i] * lightDistance * lightDistance);
|
|
|
|
|
|
|
+ float attenuation = 1.0 / (1.0 + PointLightLinearDecay[{{.}}] * lightDistance +
|
|
|
|
|
+ PointLightQuadraticDecay[{{.}}] * lightDistance * lightDistance);
|
|
|
|
|
|
|
|
// Diffuse reflection
|
|
// Diffuse reflection
|
|
|
float dotNormal = max(dot(lightDirection, normal), 0.0);
|
|
float dotNormal = max(dot(lightDirection, normal), 0.0);
|
|
|
- diffuseTotal += PointLightColor[i] * matDiffuse * dotNormal * attenuation;
|
|
|
|
|
|
|
+ diffuseTotal += PointLightColor[{{.}}] * matDiffuse * dotNormal * attenuation;
|
|
|
|
|
|
|
|
// Specular reflection
|
|
// Specular reflection
|
|
|
// Calculates the light reflection vector
|
|
// Calculates the light reflection vector
|
|
|
vec3 ref = reflect(-lightDirection, normal);
|
|
vec3 ref = reflect(-lightDirection, normal);
|
|
|
if (dotNormal > 0.0) {
|
|
if (dotNormal > 0.0) {
|
|
|
- specularTotal += PointLightColor[i] * MatSpecularColor *
|
|
|
|
|
|
|
+ specularTotal += PointLightColor[{{.}}] * MatSpecularColor *
|
|
|
pow(max(dot(ref, camDir), 0.0), MatShininess) * attenuation;
|
|
pow(max(dot(ref, camDir), 0.0), MatShininess) * attenuation;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
{{ end }}
|
|
{{ end }}
|
|
|
|
|
|
|
|
- {{if .SpotLightsMax }}
|
|
|
|
|
- for (int i = 0; i < {{.SpotLightsMax}}; i++) {
|
|
|
|
|
|
|
+ {{ range loop .SpotLightsMax }}
|
|
|
|
|
+ {
|
|
|
// Calculates the direction and distance from the current vertex to this spot light.
|
|
// Calculates the direction and distance from the current vertex to this spot light.
|
|
|
- vec3 lightDirection = SpotLightPosition[i] - vec3(position);
|
|
|
|
|
|
|
+ vec3 lightDirection = SpotLightPosition[{{.}}] - vec3(position);
|
|
|
float lightDistance = length(lightDirection);
|
|
float lightDistance = length(lightDirection);
|
|
|
lightDirection = lightDirection / lightDistance;
|
|
lightDirection = lightDirection / lightDistance;
|
|
|
|
|
|
|
|
// Calculates the attenuation due to the distance of the light
|
|
// Calculates the attenuation due to the distance of the light
|
|
|
- float attenuation = 1.0 / (1.0 + SpotLightLinearDecay[i] * lightDistance +
|
|
|
|
|
- SpotLightQuadraticDecay[i] * lightDistance * lightDistance);
|
|
|
|
|
|
|
+ float attenuation = 1.0 / (1.0 + SpotLightLinearDecay[{{.}}] * lightDistance +
|
|
|
|
|
+ SpotLightQuadraticDecay[{{.}}] * lightDistance * lightDistance);
|
|
|
|
|
|
|
|
// Calculates the angle between the vertex direction and spot direction
|
|
// Calculates the angle between the vertex direction and spot direction
|
|
|
// If this angle is greater than the cutoff the spotlight will not contribute
|
|
// If this angle is greater than the cutoff the spotlight will not contribute
|
|
|
// to the final color.
|
|
// to the final color.
|
|
|
- float angle = acos(dot(-lightDirection, SpotLightDirection[i]));
|
|
|
|
|
- float cutoff = radians(clamp(SpotLightCutoffAngle[i], 0.0, 90.0));
|
|
|
|
|
- if (angle >= cutoff) {
|
|
|
|
|
- continue;
|
|
|
|
|
- }
|
|
|
|
|
- float spotFactor = pow(dot(-lightDirection, SpotLightDirection[i]), SpotLightAngularDecay[i]);
|
|
|
|
|
|
|
+ float angle = acos(dot(-lightDirection, SpotLightDirection[{{.}}]));
|
|
|
|
|
+ float cutoff = radians(clamp(SpotLightCutoffAngle[{{.}}], 0.0, 90.0));
|
|
|
|
|
|
|
|
- // Diffuse reflection
|
|
|
|
|
- float dotNormal = max(dot(lightDirection, normal), 0.0);
|
|
|
|
|
- diffuseTotal += SpotLightColor[i] * matDiffuse * dotNormal * attenuation * spotFactor;
|
|
|
|
|
|
|
+ if (angle < cutoff) {
|
|
|
|
|
+ float spotFactor = pow(dot(-lightDirection, SpotLightDirection[{{.}}]), SpotLightAngularDecay[{{.}}]);
|
|
|
|
|
|
|
|
- // Specular reflection
|
|
|
|
|
- vec3 ref = reflect(-lightDirection, normal);
|
|
|
|
|
- if (dotNormal > 0.0) {
|
|
|
|
|
- specularTotal += SpotLightColor[i] * MatSpecularColor * pow(max(dot(ref, camDir), 0.0), MatShininess) * attenuation * spotFactor;
|
|
|
|
|
|
|
+ // Diffuse reflection
|
|
|
|
|
+ float dotNormal = max(dot(lightDirection, normal), 0.0);
|
|
|
|
|
+ diffuseTotal += SpotLightColor[{{.}}] * matDiffuse * dotNormal * attenuation * spotFactor;
|
|
|
|
|
+
|
|
|
|
|
+ // Specular reflection
|
|
|
|
|
+ vec3 ref = reflect(-lightDirection, normal);
|
|
|
|
|
+ if (dotNormal > 0.0) {
|
|
|
|
|
+ specularTotal += SpotLightColor[{{.}}] * MatSpecularColor * pow(max(dot(ref, camDir), 0.0), MatShininess) * attenuation * spotFactor;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
{{ end }}
|
|
{{ end }}
|