mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-29 04:08:55 +00:00
VideoCommon: Expose SamplerState to shaders
The benefit to exposing this over the raw BP state is that adjustments Dolphin makes, such as LOD biases from arbitrary mipmap detection, will work properly.
This commit is contained in:
parent
9ef228503a
commit
4a9b26de86
14 changed files with 188 additions and 139 deletions
|
@ -988,15 +988,15 @@ static void SetSamplerState(u32 index, float custom_tex_scale, bool custom_tex,
|
|||
// Force texture filtering config option.
|
||||
if (g_ActiveConfig.bForceFiltering)
|
||||
{
|
||||
state.min_filter = SamplerState::Filter::Linear;
|
||||
state.mag_filter = SamplerState::Filter::Linear;
|
||||
state.mipmap_filter = tm0.mipmap_filter != MipMode::None ? SamplerState::Filter::Linear :
|
||||
SamplerState::Filter::Point;
|
||||
state.tm0.min_filter = FilterMode::Linear;
|
||||
state.tm0.mag_filter = FilterMode::Linear;
|
||||
state.tm0.mipmap_filter =
|
||||
tm0.mipmap_filter != MipMode::None ? FilterMode::Linear : FilterMode::Near;
|
||||
}
|
||||
|
||||
// Custom textures may have a greater number of mips
|
||||
if (custom_tex)
|
||||
state.max_lod = 255;
|
||||
state.tm1.max_lod = 255;
|
||||
|
||||
// Anisotropic filtering option.
|
||||
if (g_ActiveConfig.iMaxAnisotropy != 0 && IsAnisostropicEnhancementSafe(tm0))
|
||||
|
@ -1008,15 +1008,15 @@ static void SetSamplerState(u32 index, float custom_tex_scale, bool custom_tex,
|
|||
// Letting the game set other combinations will have varying arbitrary results;
|
||||
// possibly being interpreted as equal to bilinear/trilinear, implicitly
|
||||
// disabling anisotropy, or changing the anisotropic algorithm employed.
|
||||
state.min_filter = SamplerState::Filter::Linear;
|
||||
state.mag_filter = SamplerState::Filter::Linear;
|
||||
state.tm0.min_filter = FilterMode::Linear;
|
||||
state.tm0.mag_filter = FilterMode::Linear;
|
||||
if (tm0.mipmap_filter != MipMode::None)
|
||||
state.mipmap_filter = SamplerState::Filter::Linear;
|
||||
state.anisotropic_filtering = 1;
|
||||
state.tm0.mipmap_filter = FilterMode::Linear;
|
||||
state.tm0.anisotropic_filtering = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
state.anisotropic_filtering = 0;
|
||||
state.tm0.anisotropic_filtering = false;
|
||||
}
|
||||
|
||||
if (has_arbitrary_mips && tm0.mipmap_filter != MipMode::None)
|
||||
|
@ -1025,14 +1025,15 @@ static void SetSamplerState(u32 index, float custom_tex_scale, bool custom_tex,
|
|||
// that have arbitrary contents, eg. are used for fog effects where the
|
||||
// distance they kick in at is important to preserve at any resolution.
|
||||
// Correct this with the upscaling factor of custom textures.
|
||||
s64 lod_offset = std::log2(g_renderer->GetEFBScale() / custom_tex_scale) * 256.f;
|
||||
state.lod_bias = std::clamp<s64>(state.lod_bias + lod_offset, -32768, 32767);
|
||||
s32 lod_offset = std::log2(g_renderer->GetEFBScale() / custom_tex_scale) * 256.f;
|
||||
state.tm0.lod_bias = std::clamp<s32>(state.tm0.lod_bias + lod_offset, -32768, 32767);
|
||||
|
||||
// Anisotropic also pushes mips farther away so it cannot be used either
|
||||
state.anisotropic_filtering = 0;
|
||||
state.tm0.anisotropic_filtering = false;
|
||||
}
|
||||
|
||||
g_renderer->SetSamplerState(index, state);
|
||||
PixelShaderManager::SetSamplerState(index, state.tm0.hex, state.tm1.hex);
|
||||
}
|
||||
|
||||
void TextureCacheBase::BindTextures(BitSet32 used_textures)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue