nv2a: Fix material color source ambient and emissive

This commit is contained in:
Erik Abair 2025-04-01 10:38:49 -07:00
parent 39fef7e7e7
commit 4ec7cce3fa
1 changed files with 28 additions and 16 deletions

View File

@ -249,21 +249,21 @@ GLSL_DEFINE(materialEmissionColor, GLSL_LTCTXA(NV_IGRAPH_XF_LTCTXA_CM_COL) ".xyz
alpha_source = alpha_source_specular;
}
if (state->ambient_src == MATERIAL_COLOR_SRC_MATERIAL) {
mstring_append_fmt(body, "oD0 = vec4(sceneAmbientColor, %s);\n", alpha_source);
} else if (state->ambient_src == MATERIAL_COLOR_SRC_DIFFUSE) {
mstring_append_fmt(body, "oD0 = vec4(diffuse.rgb, %s);\n", alpha_source);
} else if (state->ambient_src == MATERIAL_COLOR_SRC_SPECULAR) {
mstring_append_fmt(body, "oD0 = vec4(specular.rgb, %s);\n", alpha_source);
}
// If emission and ambient sources are taken from a vertex color, the scene ambient color is reconstructed from
// the vertex colors.
bool use_scene_ambient =
state->emission_src == MATERIAL_COLOR_SRC_MATERIAL || state->ambient_src == MATERIAL_COLOR_SRC_MATERIAL;
mstring_append_fmt(body,
"oD0 = vec4(%s, %s);\n",
use_scene_ambient ? "sceneAmbientColor" :
(state->emission_src == MATERIAL_COLOR_SRC_DIFFUSE ? "diffuse.rgb" : "specular.rgb"),
alpha_source
);
mstring_append(body, "oD0.rgb *= materialEmissionColor.rgb;\n");
if (state->emission_src == MATERIAL_COLOR_SRC_MATERIAL) {
mstring_append(body, "oD0.rgb += sceneAmbientColor;\n");
} else if (state->emission_src == MATERIAL_COLOR_SRC_DIFFUSE) {
mstring_append(body, "oD0.rgb += diffuse.rgb;\n");
} else if (state->emission_src == MATERIAL_COLOR_SRC_SPECULAR) {
mstring_append(body, "oD0.rgb += specular.rgb;\n");
if (state->emission_src == MATERIAL_COLOR_SRC_DIFFUSE || state->ambient_src == MATERIAL_COLOR_SRC_DIFFUSE) {
mstring_append(body, "oD0.rgb += diffuse.rgb * materialEmissionColor;\n");
} else if (state->emission_src == MATERIAL_COLOR_SRC_SPECULAR || state->ambient_src == MATERIAL_COLOR_SRC_SPECULAR) {
mstring_append(body, "oD0.rgb += specular.rgb * materialEmissionColor;\n");
}
mstring_append(body, "oD1 = vec4(0.0, 0.0, 0.0, specular.a);\n");
@ -368,8 +368,20 @@ GLSL_DEFINE(materialEmissionColor, GLSL_LTCTXA(NV_IGRAPH_XF_LTCTXA_CM_COL) ".xyz
" vec3 lightSpecular = lightSpecularColor(%d) * attenuation * pf;\n",
state->specular_power, i, i, i);
mstring_append(body,
" oD0.xyz += lightAmbient;\n");
switch (state->ambient_src) {
case MATERIAL_COLOR_SRC_MATERIAL:
mstring_append(body,
" oD0.rgb += lightAmbient;\n");
break;
case MATERIAL_COLOR_SRC_DIFFUSE:
mstring_append(body,
" oD0.rgb += diffuse.rgb * lightAmbient;\n");
break;
case MATERIAL_COLOR_SRC_SPECULAR:
mstring_append(body,
" oD0.rgb += specular.rgb * lightAmbient;\n");
break;
}
switch (state->diffuse_src) {
case MATERIAL_COLOR_SRC_MATERIAL: