diff --git a/hw/xbox/nv2a/pgraph/glsl/psh.c b/hw/xbox/nv2a/pgraph/glsl/psh.c index ec18562849..2f3af6a68e 100644 --- a/hw/xbox/nv2a/pgraph/glsl/psh.c +++ b/hw/xbox/nv2a/pgraph/glsl/psh.c @@ -179,10 +179,19 @@ void pgraph_glsl_set_psh_state(PGRAPHState *pg, PshState *state) } } - /* Keep track of textures that are uploaded as signed normalized data. - * Those must not be remapped a second time in the fragment shader. */ - state->snorm_tex[i] = - color_format == NV097_SET_TEXTURE_FORMAT_COLOR_SZ_R6G5B5; + /* Keep track of whether texture data has been loaded as signed + * normalized integers or not. This dictates whether or not we will need + * to re-map in fragment shader for certain texture modes (e.g. + * bumpenvmap). + * + * FIXME: When signed texture data is loaded as unsigned and remapped in + * fragment shader, there may be interpolation artifacts. Fix this to + * support signed textures more appropriately. + */ +#if 0 // FIXME + psh->snorm_tex[i] = (f.gl_internal_format == GL_RGB8_SNORM) + || (f.gl_internal_format == GL_RG8_SNORM); +#endif state->shadow_map[i] = f.depth; uint32_t filter = pgraph_reg_r(pg, NV_PGRAPH_TEXFILTER0 + i * 4); diff --git a/hw/xbox/nv2a/pgraph/glsl/vsh-ff.c b/hw/xbox/nv2a/pgraph/glsl/vsh-ff.c index 5e5c42ab11..0e010369c7 100644 --- a/hw/xbox/nv2a/pgraph/glsl/vsh-ff.c +++ b/hw/xbox/nv2a/pgraph/glsl/vsh-ff.c @@ -262,8 +262,6 @@ GLSL_DEFINE(materialEmissionColor, GLSL_LTCTXA(NV_IGRAPH_XF_LTCTXA_CM_COL) ".xyz static char alpha_source_specular[] = "specular.a"; static char alpha_source_material[] = "material_alpha"; const char *alpha_source = alpha_source_diffuse; - const char *ambient_source_rgb = "diffuse.rgb"; - const char *emission_source_rgb = "diffuse.rgb"; if (state->fixed_function.diffuse_src == MATERIAL_COLOR_SRC_MATERIAL) { alpha_source = alpha_source_material; } else if (state->fixed_function.diffuse_src == MATERIAL_COLOR_SRC_SPECULAR) { @@ -271,23 +269,21 @@ GLSL_DEFINE(materialEmissionColor, GLSL_LTCTXA(NV_IGRAPH_XF_LTCTXA_CM_COL) ".xyz } if (state->fixed_function.ambient_src == MATERIAL_COLOR_SRC_MATERIAL) { - ambient_source_rgb = "materialEmissionColor.rgb"; + mstring_append_fmt(body, "oD0 = vec4(sceneAmbientColor, %s);\n", alpha_source); } else if (state->fixed_function.ambient_src == MATERIAL_COLOR_SRC_DIFFUSE) { - ambient_source_rgb = "diffuse.rgb"; + mstring_append_fmt(body, "oD0 = vec4(diffuse.rgb, %s);\n", alpha_source); } else if (state->fixed_function.ambient_src == MATERIAL_COLOR_SRC_SPECULAR) { - ambient_source_rgb = "specular.rgb"; + mstring_append_fmt(body, "oD0 = vec4(specular.rgb, %s);\n", alpha_source); } + mstring_append(body, "oD0.rgb *= materialEmissionColor.rgb;\n"); if (state->fixed_function.emission_src == MATERIAL_COLOR_SRC_MATERIAL) { - emission_source_rgb = "materialEmissionColor.rgb"; + mstring_append(body, "oD0.rgb += sceneAmbientColor;\n"); } else if (state->fixed_function.emission_src == MATERIAL_COLOR_SRC_DIFFUSE) { - emission_source_rgb = "diffuse.rgb"; + mstring_append(body, "oD0.rgb += diffuse.rgb;\n"); } else if (state->fixed_function.emission_src == MATERIAL_COLOR_SRC_SPECULAR) { - emission_source_rgb = "specular.rgb"; + mstring_append(body, "oD0.rgb += specular.rgb;\n"); } - mstring_append_fmt(body, "oD0 = vec4(sceneAmbientColor * %s, %s);\n", - ambient_source_rgb, alpha_source); - mstring_append_fmt(body, "oD0.rgb += %s;\n", emission_source_rgb); mstring_append(body, "oD1 = vec4(0.0, 0.0, 0.0, specular.a);\n"); diff --git a/hw/xbox/nv2a/pgraph/pgraph.c b/hw/xbox/nv2a/pgraph/pgraph.c index eb54656645..913ce46109 100644 --- a/hw/xbox/nv2a/pgraph/pgraph.c +++ b/hw/xbox/nv2a/pgraph/pgraph.c @@ -2489,8 +2489,10 @@ DEF_METHOD_INC(NV097, SET_TEXCOORD3_2F) do { \ VertexAttribute *attribute = &pg->vertex_attributes[(attr_index)]; \ pgraph_allocate_inline_buffer_vertices(pg, (attr_index)); \ - pgraph_argb_pack32_to_rgba_float(parameter, \ - attribute->inline_value); \ + attribute->inline_value[0] = (parameter & 0xFF) / 255.0f; \ + attribute->inline_value[1] = ((parameter >> 8) & 0xFF) / 255.0f; \ + attribute->inline_value[2] = ((parameter >> 16) & 0xFF) / 255.0f; \ + attribute->inline_value[3] = ((parameter >> 24) & 0xFF) / 255.0f; \ } while (0) DEF_METHOD_INC(NV097, SET_DIFFUSE_COLOR4UB) @@ -2917,14 +2919,10 @@ DEF_METHOD_INC(NV097, SET_VERTEX_DATA4UB) int slot = (method - NV097_SET_VERTEX_DATA4UB) / 4; VertexAttribute *attribute = &pg->vertex_attributes[slot]; pgraph_allocate_inline_buffer_vertices(pg, slot); - if (slot == NV2A_VERTEX_ATTR_DIFFUSE || slot == NV2A_VERTEX_ATTR_SPECULAR) { - pgraph_argb_pack32_to_rgba_float(parameter, attribute->inline_value); - } else { - attribute->inline_value[0] = (parameter & 0xFF) / 255.0; - attribute->inline_value[1] = ((parameter >> 8) & 0xFF) / 255.0; - attribute->inline_value[2] = ((parameter >> 16) & 0xFF) / 255.0; - attribute->inline_value[3] = ((parameter >> 24) & 0xFF) / 255.0; - } + attribute->inline_value[0] = (parameter & 0xFF) / 255.0; + attribute->inline_value[1] = ((parameter >> 8) & 0xFF) / 255.0; + attribute->inline_value[2] = ((parameter >> 16) & 0xFF) / 255.0; + attribute->inline_value[3] = ((parameter >> 24) & 0xFF) / 255.0; if (slot == 0) { pgraph_finish_inline_buffer_vertex(pg); } diff --git a/hw/xbox/nv2a/pgraph/vertex.c b/hw/xbox/nv2a/pgraph/vertex.c index 309ac2af37..31076896e7 100644 --- a/hw/xbox/nv2a/pgraph/vertex.c +++ b/hw/xbox/nv2a/pgraph/vertex.c @@ -31,14 +31,6 @@ void pgraph_update_inline_value(VertexAttribute *attr, const uint8_t *data) switch (attr->format) { case NV097_SET_VERTEX_DATA_ARRAY_FORMAT_TYPE_UB_D3D: - if (attr->count == 4) { - attr->inline_value[0] = (float)data[2] / 255.0f; - attr->inline_value[1] = (float)data[1] / 255.0f; - attr->inline_value[2] = (float)data[0] / 255.0f; - attr->inline_value[3] = (float)data[3] / 255.0f; - break; - } - /* Fall back to direct copy for unexpected non-BGRA cases. */ case NV097_SET_VERTEX_DATA_ARRAY_FORMAT_TYPE_UB_OGL: for (uint32_t i = 0; i < attr->count; ++i) { attr->inline_value[i] = (float)data[i] / 255.0f;