mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-21 14:49:19 +02:00
initial rain material optimizations
This commit is contained in:
@@ -113,18 +113,21 @@ void NvRenderer::MaterialTemplate::Init(const YAML::Node &conf) {
|
||||
auto index = it.second["binding"].as<int>();
|
||||
m_texture_bindings.resize(
|
||||
glm::max(m_texture_bindings.size(), static_cast<size_t>(index) + 1));
|
||||
auto &[name, sampler_name, hint, default_texture] =
|
||||
m_texture_bindings[index];
|
||||
auto &binding = m_texture_bindings[index];
|
||||
|
||||
name = it.first.as<std::string>();
|
||||
sampler_name = fmt::format("{:s}_sampler", name.c_str());
|
||||
binding.m_name = it.first.as<std::string>();
|
||||
binding.m_sampler_name = fmt::format("{:s}_sampler", binding.m_name.c_str());
|
||||
|
||||
binding.disable_anisotropy = it.second["no_anisotropy"].as<bool>(false);
|
||||
binding.disable_filter = it.second["no_filter"].as<bool>(false);
|
||||
binding.disable_mip_bias = it.second["no_mip_bias"].as<bool>(false);
|
||||
|
||||
texture_mappings.emplace_back(
|
||||
MaResourceMapping::Texture_SRV(index, name.c_str()));
|
||||
MaResourceMapping::Texture_SRV(index, binding.m_name.c_str()));
|
||||
sampler_mappings.emplace_back(
|
||||
MaResourceMapping::Sampler(index, sampler_name.c_str()));
|
||||
MaResourceMapping::Sampler(index, binding.m_sampler_name.c_str()));
|
||||
|
||||
RegisterTexture(name.c_str(), 1);
|
||||
RegisterTexture(binding.m_name.c_str(), 1);
|
||||
RegisterResource(
|
||||
false, "masked_shadow_sampler",
|
||||
GetTextureManager()->GetSamplerForTraits(0, RenderPassType::ShadowMap),
|
||||
@@ -132,10 +135,10 @@ void NvRenderer::MaterialTemplate::Init(const YAML::Node &conf) {
|
||||
|
||||
const static std::unordered_map<std::string_view, int> hints{
|
||||
{"color", GL_SRGB_ALPHA}, {"linear", GL_RGBA}, {"normalmap", GL_RG}};
|
||||
hint = hints.at(it.second["hint"].as<std::string_view>());
|
||||
binding.m_hint = hints.at(it.second["hint"].as<std::string_view>());
|
||||
|
||||
if (it.first.Scalar() == conf["masked_shadow_texture"].Scalar()) {
|
||||
texture_mapping_shadow = MaResourceMapping::Texture_SRV(0, name.c_str());
|
||||
texture_mapping_shadow = MaResourceMapping::Texture_SRV(0, binding.m_name.c_str());
|
||||
sampler_mapping_shadow =
|
||||
MaResourceMapping::Sampler(0, "masked_shadow_sampler");
|
||||
}
|
||||
|
||||
@@ -1004,19 +1004,23 @@ material_handle NvRenderer::Fetch_Material(std::string const &Filename,
|
||||
auto texture_manager = GetTextureManager();
|
||||
|
||||
for (int i = 0; i < material_template->m_texture_bindings.size(); ++i) {
|
||||
const auto &[key, sampler_key, hint, m_default_texture] =
|
||||
material_template->m_texture_bindings[i];
|
||||
const auto &binding = material_template->m_texture_bindings[i];
|
||||
auto handle = texture_manager->FetchTexture(
|
||||
static_cast<std::string>(adapter.GetTexturePathForEntry(key)), hint,
|
||||
adapter.GetTextureSizeBiasForEntry(key), true);
|
||||
static_cast<std::string>(
|
||||
adapter.GetTexturePathForEntry(binding.m_name)),
|
||||
binding.m_hint, adapter.GetTextureSizeBiasForEntry(binding.m_name),
|
||||
true);
|
||||
cache.m_texture_handles[i] = handle;
|
||||
cache.RegisterTexture(key.c_str(), handle);
|
||||
cache.RegisterResource(false, sampler_key.c_str(),
|
||||
auto traits = texture_manager->GetTraits(handle);
|
||||
traits[MaTextureTraits_NoFilter] = binding.disable_filter;
|
||||
traits[MaTextureTraits_NoAnisotropy] = binding.disable_anisotropy;
|
||||
traits[MaTextureTraits_NoMipBias] = binding.disable_mip_bias;
|
||||
cache.RegisterTexture(binding.m_name.c_str(), handle);
|
||||
cache.RegisterResource(false, binding.m_sampler_name.c_str(),
|
||||
texture_manager->GetSamplerForTraits(
|
||||
texture_manager->GetTraits(handle),
|
||||
NvRenderer::RenderPassType::Deferred),
|
||||
traits, RenderPassType::Deferred),
|
||||
nvrhi::ResourceType::Sampler);
|
||||
if (key == cache.m_template->m_masked_shadow_texture &&
|
||||
if (binding.m_name == cache.m_template->m_masked_shadow_texture &&
|
||||
texture_manager->IsValidHandle(handle)) {
|
||||
cache.m_masked_shadow =
|
||||
texture_manager->GetTexture(handle)->m_has_alpha;
|
||||
|
||||
@@ -493,10 +493,10 @@ nvrhi::SamplerHandle NvTextureManager::GetSamplerForTraits(
|
||||
.setAddressV(traits[MaTextureTraits_ClampT]
|
||||
? nvrhi::SamplerAddressMode::Clamp
|
||||
: nvrhi::SamplerAddressMode::Wrap)
|
||||
.setAllFilters(true)
|
||||
.setAllFilters(!traits[MaTextureTraits_NoFilter])
|
||||
.setMipFilter(false)
|
||||
.setMaxAnisotropy(traits[MaTextureTraits_NoAnisotropy] ? 0.f : 16.f)
|
||||
.setMipBias(traits[MaTextureTraits_NoMipBias] ? 0.f : -1.76f);
|
||||
.setMaxAnisotropy(traits[MaTextureTraits_NoAnisotropy] || traits[MaTextureTraits_NoFilter] ? 0.f : 16.f)
|
||||
.setMipBias(traits[MaTextureTraits_NoMipBias] || traits[MaTextureTraits_NoFilter] ? 0.f : -1.76f);
|
||||
sampler = m_backend->GetDevice()->createSampler(desc);
|
||||
}
|
||||
return sampler;
|
||||
|
||||
@@ -16,6 +16,7 @@ enum MaTextureTraits {
|
||||
|
||||
MaTextureTraits_NoMipBias,
|
||||
MaTextureTraits_NoAnisotropy,
|
||||
MaTextureTraits_NoFilter,
|
||||
|
||||
MaTextureTraits_Num
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user