Skip to content

Commit 6829a30

Browse files
committed
nv2a: Fix material color source ambient and emissive
1 parent 679f6d0 commit 6829a30

File tree

1 file changed

+29
-17
lines changed

1 file changed

+29
-17
lines changed

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

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -251,21 +251,21 @@ GLSL_DEFINE(materialEmissionColor, GLSL_LTCTXA(NV_IGRAPH_XF_LTCTXA_CM_COL) ".xyz
251251
alpha_source = alpha_source_specular;
252252
}
253253

254-
if (state->ambient_src == MATERIAL_COLOR_SRC_MATERIAL) {
255-
mstring_append_fmt(body, "oD0 = vec4(sceneAmbientColor, %s);\n", alpha_source);
256-
} else if (state->ambient_src == MATERIAL_COLOR_SRC_DIFFUSE) {
257-
mstring_append_fmt(body, "oD0 = vec4(diffuse.rgb, %s);\n", alpha_source);
258-
} else if (state->ambient_src == MATERIAL_COLOR_SRC_SPECULAR) {
259-
mstring_append_fmt(body, "oD0 = vec4(specular.rgb, %s);\n", alpha_source);
260-
}
261-
262-
mstring_append(body, "oD0.rgb *= materialEmissionColor.rgb;\n");
263-
if (state->emission_src == MATERIAL_COLOR_SRC_MATERIAL) {
264-
mstring_append(body, "oD0.rgb += sceneAmbientColor;\n");
265-
} else if (state->emission_src == MATERIAL_COLOR_SRC_DIFFUSE) {
266-
mstring_append(body, "oD0.rgb += diffuse.rgb;\n");
267-
} else if (state->emission_src == MATERIAL_COLOR_SRC_SPECULAR) {
268-
mstring_append(body, "oD0.rgb += specular.rgb;\n");
254+
// If emission and ambient sources are taken from a vertex color, the scene ambient color is reconstructed from
255+
// the vertex colors.
256+
bool use_scene_ambient =
257+
state->emission_src == MATERIAL_COLOR_SRC_MATERIAL || state->ambient_src == MATERIAL_COLOR_SRC_MATERIAL;
258+
mstring_append_fmt(body,
259+
"oD0 = vec4(%s, %s);\n",
260+
use_scene_ambient ? "sceneAmbientColor" :
261+
(state->emission_src == MATERIAL_COLOR_SRC_DIFFUSE ? "diffuse.rgb" : "specular.rgb"),
262+
alpha_source
263+
);
264+
265+
if (state->emission_src == MATERIAL_COLOR_SRC_DIFFUSE || state->ambient_src == MATERIAL_COLOR_SRC_DIFFUSE) {
266+
mstring_append(body, "oD0.rgb += diffuse.rgb * materialEmissionColor;\n");
267+
} else if (state->emission_src == MATERIAL_COLOR_SRC_SPECULAR || state->ambient_src == MATERIAL_COLOR_SRC_SPECULAR) {
268+
mstring_append(body, "oD0.rgb += specular.rgb * materialEmissionColor;\n");
269269
}
270270

271271
mstring_append(body, "oD1 = vec4(0.0, 0.0, 0.0, specular.a);\n");
@@ -370,8 +370,20 @@ GLSL_DEFINE(materialEmissionColor, GLSL_LTCTXA(NV_IGRAPH_XF_LTCTXA_CM_COL) ".xyz
370370
" vec3 lightSpecular = lightSpecularColor(%d) * attenuation * pf;\n",
371371
i, i, i);
372372

373-
mstring_append(body,
374-
" oD0.xyz += lightAmbient;\n");
373+
switch (state->ambient_src) {
374+
case MATERIAL_COLOR_SRC_MATERIAL:
375+
mstring_append(body,
376+
" oD0.rgb += lightAmbient;\n");
377+
break;
378+
case MATERIAL_COLOR_SRC_DIFFUSE:
379+
mstring_append(body,
380+
" oD0.rgb += diffuse.rgb * lightAmbient;\n");
381+
break;
382+
case MATERIAL_COLOR_SRC_SPECULAR:
383+
mstring_append(body,
384+
" oD0.rgb += specular.rgb * lightAmbient;\n");
385+
break;
386+
}
375387

376388
switch (state->diffuse_src) {
377389
case MATERIAL_COLOR_SRC_MATERIAL:

0 commit comments

Comments
 (0)