mirror of
https://git.suyu.dev/suyu/suyu.git
synced 2024-11-22 10:51:50 -05:00
pica: use correct coordinates for texture 2
This commit is contained in:
parent
06d4654966
commit
0f664ef89d
4 changed files with 22 additions and 5 deletions
|
@ -122,6 +122,10 @@ struct TexturingRegs {
|
|||
BitField<0, 1, u32> texture0_enable;
|
||||
BitField<1, 1, u32> texture1_enable;
|
||||
BitField<2, 1, u32> texture2_enable;
|
||||
BitField<8, 2, u32> texture3_coordinates; // TODO: unimplemented
|
||||
BitField<10, 1, u32> texture3_enable; // TODO: unimplemented
|
||||
BitField<13, 1, u32> texture2_use_coord1;
|
||||
BitField<16, 1, u32> clear_texture_cache; // TODO: unimplemented
|
||||
};
|
||||
TextureConfig texture0;
|
||||
INSERT_PADDING_WORDS(0x8);
|
||||
|
|
|
@ -40,6 +40,8 @@ PicaShaderConfig PicaShaderConfig::BuildFromRegs(const Pica::Regs& regs) {
|
|||
|
||||
state.texture0_type = regs.texturing.texture0.type;
|
||||
|
||||
state.texture2_use_coord1 = regs.texturing.texture2_use_coord1 != 0;
|
||||
|
||||
// Copy relevant tev stages fields.
|
||||
// We don't sync const_color here because of the high variance, it is a
|
||||
// shader uniform instead.
|
||||
|
@ -126,6 +128,15 @@ static bool IsPassThroughTevStage(const TevStageConfig& stage) {
|
|||
stage.GetColorMultiplier() == 1 && stage.GetAlphaMultiplier() == 1);
|
||||
}
|
||||
|
||||
static std::string TexCoord(const PicaShaderConfig& config, int texture_unit) {
|
||||
if (texture_unit == 2 && config.state.texture2_use_coord1) {
|
||||
return "texcoord[1]";
|
||||
}
|
||||
// TODO: if texture unit 3 (procedural texture) implementation also uses this function,
|
||||
// config.state.texture3_coordinates should be repected here.
|
||||
return "texcoord[" + std::to_string(texture_unit) + "]";
|
||||
}
|
||||
|
||||
/// Writes the specified TEV stage source component(s)
|
||||
static void AppendSource(std::string& out, const PicaShaderConfig& config,
|
||||
TevStageConfig::Source source, const std::string& index_name) {
|
||||
|
@ -162,7 +173,7 @@ static void AppendSource(std::string& out, const PicaShaderConfig& config,
|
|||
out += "texture(tex[1], texcoord[1])";
|
||||
break;
|
||||
case Source::Texture2:
|
||||
out += "texture(tex[2], texcoord[2])";
|
||||
out += "texture(tex[2], " + TexCoord(config, 2) + ")";
|
||||
break;
|
||||
case Source::PreviousBuffer:
|
||||
out += "combiner_buffer";
|
||||
|
@ -473,8 +484,8 @@ static void WriteLighting(std::string& out, const PicaShaderConfig& config) {
|
|||
// Bump mapping is enabled using a normal map, read perturbation vector from the selected
|
||||
// texture
|
||||
std::string bump_selector = std::to_string(lighting.bump_selector);
|
||||
out += "vec3 surface_normal = 2.0 * texture(tex[" + bump_selector + "], texcoord[" +
|
||||
bump_selector + "]).rgb - 1.0;\n";
|
||||
out += "vec3 surface_normal = 2.0 * texture(tex[" + bump_selector + "], " +
|
||||
TexCoord(config, lighting.bump_selector) + ").rgb - 1.0;\n";
|
||||
|
||||
// Recompute Z-component of perturbation if 'renorm' is enabled, this provides a higher
|
||||
// precision result
|
||||
|
|
|
@ -79,6 +79,7 @@ union PicaShaderConfig {
|
|||
Pica::FramebufferRegs::CompareFunc alpha_test_func;
|
||||
Pica::RasterizerRegs::ScissorMode scissor_test_mode;
|
||||
Pica::TexturingRegs::TextureConfig::TextureType texture0_type;
|
||||
bool texture2_use_coord1;
|
||||
std::array<TevStageConfigRaw, 6> tev_stages;
|
||||
u8 combiner_buffer_input;
|
||||
|
||||
|
|
|
@ -276,8 +276,9 @@ static void ProcessTriangleInternal(const Vertex& v0, const Vertex& v1, const Ve
|
|||
|
||||
DEBUG_ASSERT(0 != texture.config.address);
|
||||
|
||||
float24 u = uv[i].u();
|
||||
float24 v = uv[i].v();
|
||||
int coordinate_i = (i == 2 && regs.texturing.texture2_use_coord1) ? 1 : i;
|
||||
float24 u = uv[coordinate_i].u();
|
||||
float24 v = uv[coordinate_i].v();
|
||||
|
||||
// Only unit 0 respects the texturing type (according to 3DBrew)
|
||||
// TODO: Refactor so cubemaps and shadowmaps can be handled
|
||||
|
|
Loading…
Reference in a new issue