@@ -14,6 +14,8 @@ in vec3 ex_Position_view;
1414
1515out vec4 out_Color;
1616
17+ uniform uint u_TubeCount;
18+
1719
1820LightContributions applyLight_pbr(vec3 aView, vec3 aDiffuseLightDir, vec3 aSpecularLightDir, vec3 aShadingNormal,
1921 PbrParameters aParams, LightColors aColors)
@@ -149,35 +151,38 @@ void main(void)
149151 }
150152
151153
152- // // Point lights
153- // for(uint pointIdx = 0; pointIdx != ub_PointCount.x; ++pointIdx)
154- // {
155- // PointLight point = ub_PointLights[pointIdx];
154+ // The u_TubeCount first pairs of point lights are representing tube lights
155+ uint firstPoint = min (2 * u_TubeCount, ub_PointCount);
156+
157+ // Point lights
158+ for (uint pointIdx = firstPoint; pointIdx != ub_PointCount; ++ pointIdx)
159+ {
160+ PointLight point = ub_PointLights[pointIdx];
156161
157- // // see rtr 4th p110 (5.10)
158- // vec3 lightRay_view = point.position.xyz - ex_Position_view;
159- // float radius = length(lightRay_view);
160- // vec3 lightDir_view = lightRay_view / radius;
162+ // see rtr 4th p110 (5.10)
163+ vec3 lightRay_view = point.position.xyz - ex_Position_view;
164+ float radius = length (lightRay_view);
165+ vec3 lightDir_view = lightRay_view / radius;
161166
162- // vec3 specularLightDir_view = normalize(
163- // representativePoint_sphere(ex_Position_view,
164- // point.position.xyz,
165- // reflect(-viewDir_view, shadingNormal_view),
166- // point.radius.x));
167+ vec3 specularLightDir_view = normalize (
168+ representativePoint_sphere(ex_Position_view,
169+ point.position.xyz,
170+ reflect (- viewDir_view, shadingNormal_view),
171+ point.radius.x));
167172
168- // LightContributions lighting =
169- // applyLight_pbr(
170- // viewDir_view, lightDir_view, specularLightDir_view, shadingNormal_view,
171- // pbrParameters, point.colors);
173+ LightContributions lighting =
174+ applyLight_pbr(
175+ viewDir_view, lightDir_view, specularLightDir_view, shadingNormal_view,
176+ pbrParameters, point.colors);
172177
173- // float falloff = attenuatePoint(point, radius);
174- // diffuseAccum += lighting.diffuse * falloff;
175- // specularAccum += lighting.specular * falloff;
176- // }
178+ float falloff = attenuatePoint(point, radius);
179+ diffuseAccum += lighting.diffuse * falloff;
180+ specularAccum += lighting.specular * falloff;
181+ }
177182
178183
179184 // Tube lights
180- for (uint pointIdx = 0 ; pointIdx != ub_PointCount ; pointIdx += 2 )
185+ for (uint pointIdx = 0 ; ( pointIdx + 1 ) < firstPoint ; pointIdx += 2 )
181186 {
182187 PointLight p0 = ub_PointLights[pointIdx];
183188 PointLight p1 = ub_PointLights[pointIdx+ 1 ];
0 commit comments