Skip to content

Commit 39fef7e

Browse files
committed
nv2a: Handle LOCALEYE light control
1 parent 2192bbd commit 39fef7e

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

hw/xbox/nv2a/pgraph/glsl/vsh-ff.c

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,12 @@ GLSL_DEFINE(materialEmissionColor, GLSL_LTCTXA(NV_IGRAPH_XF_LTCTXA_CM_COL) ".xyz
268268

269269
mstring_append(body, "oD1 = vec4(0.0, 0.0, 0.0, specular.a);\n");
270270

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+
271277
for (i = 0; i < NV2A_MAX_LIGHTS; i++) {
272278
if (state->light[i] == LIGHT_OFF) {
273279
continue;
@@ -283,18 +289,20 @@ GLSL_DEFINE(materialEmissionColor, GLSL_LTCTXA(NV_IGRAPH_XF_LTCTXA_CM_COL) ".xyz
283289
"%svec3 lightLocalAttenuation%d;\n",
284290
u, i, u, i);
285291
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"
287294
" float d = length(VP);\n"
288295
" if (d <= lightLocalRange(%d)) {\n" /* FIXME: Double check that range is inclusive */
289296
" VP = normalize(VP);\n"
290297
" float attenuation = 1.0 / (lightLocalAttenuation%d.x\n"
291298
" + lightLocalAttenuation%d.y * d\n"
292299
" + 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"
294301
" float nDotVP = max(0.0, dot(tNormal, VP));\n"
295302
" 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+
);
298306
}
299307

300308
switch(state->light[i]) {
@@ -309,10 +317,19 @@ GLSL_DEFINE(materialEmissionColor, GLSL_LTCTXA(NV_IGRAPH_XF_LTCTXA_CM_COL) ".xyz
309317
mstring_append_fmt(body,
310318
" {\n"
311319
" 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+
}
316333
break;
317334
case LIGHT_LOCAL:
318335
/* Everything done already */
@@ -411,7 +428,7 @@ GLSL_DEFINE(materialEmissionColor, GLSL_LTCTXA(NV_IGRAPH_XF_LTCTXA_CM_COL) ".xyz
411428
}
412429
if (state->ignore_specular_alpha) {
413430
mstring_append(body,
414-
" oD1.w = 1.0;\n"
431+
" oD1.a = 1.0;\n"
415432
" oB1.a = 1.0;\n"
416433
);
417434
}

hw/xbox/nv2a/pgraph/shaders.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ ShaderState pgraph_get_shader_state(PGRAPHState *pg)
9696
pgraph_reg_r(pg, NV_PGRAPH_CSV0_C), NV_PGRAPH_CSV0_C_SEPARATE_SPECULAR);
9797
state.ignore_specular_alpha = !GET_MASK(
9898
pgraph_reg_r(pg, NV_PGRAPH_CSV0_C), NV_PGRAPH_CSV0_C_ALPHA_FROM_MATERIAL_SPECULAR);
99+
state.local_eye = GET_MASK(
100+
pgraph_reg_r(pg, NV_PGRAPH_CSV0_C), NV_PGRAPH_CSV0_C_LOCALEYE);
99101

100102
state.specular_power = pg->specular_power;
101103
state.specular_power_back = pg->specular_power_back;

hw/xbox/nv2a/pgraph/shaders.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ typedef struct ShaderState {
8181

8282
bool separate_specular;
8383
bool ignore_specular_alpha;
84+
bool local_eye;
8485
float specular_power;
8586
float specular_power_back;
8687

0 commit comments

Comments
 (0)