Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix blended textures for dx, opengl, and metal #393

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/graphic/Fast3D/gfx_direct3d_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,19 @@ void gfx_direct3d_common_build_shader(char buf[8192], size_t& len, size_t& num_f
}
len += sprintf(buf + len, " } else {\r\n");
len += sprintf(buf + len, " texVal%d = g_texture%d.Sample(g_sampler%d, tc%d);\r\n", i, i, i, i);
if (cc_features.used_masks[i]) {
if (cc_features.used_blend[i]) {
len += sprintf(buf + len,
" float4 blendVal%d = g_textureBlend%d.Sample(g_sampler%d, tc%d);\r\n", i,
i, i, i);
} else {
len += sprintf(buf + len, " float4 blendVal%d = float4(0, 0, 0, 0);\r\n", i);
}
len += sprintf(buf + len,
" texVal%d = lerp(texVal%d, blendVal%d, "
"g_textureMask%d.Sample(g_sampler%d, tc%d).a);\r\n",
i, i, i, i, i, i);
}
len += sprintf(buf + len, " }\r\n");
} else {
len +=
Expand Down
2 changes: 1 addition & 1 deletion src/graphic/Fast3D/gfx_metal_shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ static void append_formula(char* buf, size_t* len, const uint8_t c[2][4], bool d

// MARK: - Public Methods

MTL::VertexDescriptor* gfx_metal_build_shader(char buf[4096], size_t& num_floats, const CCFeatures& cc_features,
MTL::VertexDescriptor* gfx_metal_build_shader(char buf[8192], size_t& num_floats, const CCFeatures& cc_features,
bool three_point_filtering) {

size_t len = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/graphic/Fast3D/gfx_metal_shader.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <stdio.h>
#include "gfx_cc.h"

MTL::VertexDescriptor* gfx_metal_build_shader(char buf[4096], size_t& num_floats, const CCFeatures& cc_features,
MTL::VertexDescriptor* gfx_metal_build_shader(char buf[8192], size_t& num_floats, const CCFeatures& cc_features,
bool three_point_filtering);

#endif /* GFX_METAL_SHADER_H */
Expand Down
10 changes: 8 additions & 2 deletions src/graphic/Fast3D/gfx_pc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -901,10 +901,10 @@ static void import_texture_raw(int tile, bool importReplacement) {
// if texture type is CI4 or CI8 we need to apply tlut to it
switch (type) {
case LUS::TextureType::Palette4bpp:
import_texture_ci4(tile, false);
import_texture_ci4(tile, importReplacement);
return;
case LUS::TextureType::Palette8bpp:
import_texture_ci8(tile, false);
import_texture_ci8(tile, importReplacement);
return;
default:
break;
Expand Down Expand Up @@ -1565,6 +1565,12 @@ static void gfx_sp_tri1(uint8_t vtx1_idx, uint8_t vtx2_idx, uint8_t vtx3_idx, bo
if (linear_filter != rendering_state.textures[i]->second.linear_filter ||
cms != rendering_state.textures[i]->second.cms || cmt != rendering_state.textures[i]->second.cmt) {
gfx_flush();

// Set the same sampler params on the blended texture. Needed for opengl.
if (rdp.loaded_texture[i].blended) {
gfx_rapi->set_sampler_parameters(SHADER_FIRST_REPLACEMENT_TEXTURE + i, linear_filter, cms, cmt);
}

gfx_rapi->set_sampler_parameters(i, linear_filter, cms, cmt);
rendering_state.textures[i]->second.linear_filter = linear_filter;
rendering_state.textures[i]->second.cms = cms;
Expand Down
Loading