@@ -268,6 +268,12 @@ GLSL_DEFINE(materialEmissionColor, GLSL_LTCTXA(NV_IGRAPH_XF_LTCTXA_CM_COL) ".xyz
268
268
269
269
mstring_append (body , "oD1 = vec4(0.0, 0.0, 0.0, specular.a);\n" );
270
270
271
+ if (state -> local_eye ) {
272
+ mstring_append (body ,
273
+ "vec3 VPeye = normalize(eyePosition.xyz / eyePosition.w - tPosition.xyz / tPosition.w);\n"
274
+ );
275
+ }
276
+
271
277
for (i = 0 ; i < NV2A_MAX_LIGHTS ; i ++ ) {
272
278
if (state -> light [i ] == LIGHT_OFF ) {
273
279
continue ;
@@ -283,18 +289,20 @@ GLSL_DEFINE(materialEmissionColor, GLSL_LTCTXA(NV_IGRAPH_XF_LTCTXA_CM_COL) ".xyz
283
289
"%svec3 lightLocalAttenuation%d;\n" ,
284
290
u , i , u , i );
285
291
mstring_append_fmt (body ,
286
- " vec3 VP = lightLocalPosition%d - tPosition.xyz/tPosition.w;\n"
292
+ " vec3 tPos = tPosition.xyz/tPosition.w;\n"
293
+ " vec3 VP = lightLocalPosition%d - tPos;\n"
287
294
" float d = length(VP);\n"
288
295
" if (d <= lightLocalRange(%d)) {\n" /* FIXME: Double check that range is inclusive */
289
296
" VP = normalize(VP);\n"
290
297
" float attenuation = 1.0 / (lightLocalAttenuation%d.x\n"
291
298
" + lightLocalAttenuation%d.y * d\n"
292
299
" + lightLocalAttenuation%d.z * d * d);\n"
293
- " vec3 halfVector = normalize(VP + eyePosition.xyz / eyePosition.w );\n" /* FIXME: Not sure if eyePosition is correct */
300
+ " vec3 halfVector = normalize(VP + %s );\n"
294
301
" float nDotVP = max(0.0, dot(tNormal, VP));\n"
295
302
" float nDotHV = max(0.0, dot(tNormal, halfVector));\n" ,
296
- i , i , i , i , i );
297
-
303
+ i , i , i , i , i ,
304
+ state -> local_eye ? "VPeye" : "vec3(0.0, 0.0, -1.0)"
305
+ );
298
306
}
299
307
300
308
switch (state -> light [i ]) {
@@ -309,10 +317,19 @@ GLSL_DEFINE(materialEmissionColor, GLSL_LTCTXA(NV_IGRAPH_XF_LTCTXA_CM_COL) ".xyz
309
317
mstring_append_fmt (body ,
310
318
" {\n"
311
319
" float attenuation = 1.0;\n"
312
- " float nDotVP = max(0.0, dot(tNormal, normalize(lightInfiniteDirection%d)));\n"
313
- " float nDotHV = max(0.0, dot(tNormal, lightInfiniteHalfVector%d));\n" ,
314
- i , i );
315
-
320
+ " vec3 lightDirection = normalize(lightInfiniteDirection%d);\n"
321
+ " float nDotVP = max(0.0, dot(tNormal, lightDirection));\n" ,
322
+ i );
323
+ if (state -> local_eye ) {
324
+ mstring_append (body ,
325
+ " float nDotHV = max(0.0, dot(tNormal, normalize(lightDirection + VPeye)));\n"
326
+ );
327
+ } else {
328
+ mstring_append_fmt (body ,
329
+ " float nDotHV = max(0.0, dot(tNormal, lightInfiniteHalfVector%d));\n" ,
330
+ i
331
+ );
332
+ }
316
333
break ;
317
334
case LIGHT_LOCAL :
318
335
/* Everything done already */
@@ -411,7 +428,7 @@ GLSL_DEFINE(materialEmissionColor, GLSL_LTCTXA(NV_IGRAPH_XF_LTCTXA_CM_COL) ".xyz
411
428
}
412
429
if (state -> ignore_specular_alpha ) {
413
430
mstring_append (body ,
414
- " oD1.w = 1.0;\n"
431
+ " oD1.a = 1.0;\n"
415
432
" oB1.a = 1.0;\n"
416
433
);
417
434
}
0 commit comments