fix: some textures applied were not the right ones

This commit is contained in:
Almamu 2025-04-16 17:23:32 +02:00
parent 8adeefad9c
commit 94a4d9ecee
8 changed files with 109 additions and 74 deletions

View File

@ -215,18 +215,17 @@ std::map<int, Images::CMaterial::OverrideInfo> CEffect::overridesFromJSON (
++textureNumber;
std::string name;
if (texture.is_null ()) {
if (textureNumber == 0) {
auto passTextures = (*material->getPasses ().begin ())->getTextures ();
if (texture.is_null () && textureNumber > 0) {
continue;
}
if (passTextures.empty ()) {
// TODO: SET CHECKERBOARD TEXTURE AS DEFAULT IN THESE SITUATIONS
name = "";
} else {
name = passTextures.begin ()->second;
}
if (textureNumber == 0) {
auto passTextures = (*material->getPasses ().begin ())->getTextures ();
if (passTextures.empty()) {
continue;
} else {
name = "";
name = passTextures.begin ()->second;
}
} else {
name = texture;

View File

@ -58,7 +58,7 @@ const CPass* CPass::fromJSON (const json& data, const CMaterial::OverrideInfo* o
for (const auto& [name, value] : overrides->constants)
constants[name] = value;
for (const auto& [id, value] : overrides->textures)
textures.insert(std::pair(id, value));
textures[id] = value;
}
return new CPass (

View File

@ -219,7 +219,7 @@ void CPrettyPrinter::printPass (const CPass& pass, int passId) {
this->decreaseIndentation ();
}
const auto fragmentTextures = pass.getShader ()->getFragmentTextures();
const auto fragmentTextures = pass.getShader ()->getFragment ().getTextures ();
if (fragmentTextures.size () > 0) {
this->m_out << "Fragment textures " << fragmentTextures.size () << ":";
@ -233,7 +233,7 @@ void CPrettyPrinter::printPass (const CPass& pass, int passId) {
this->decreaseIndentation ();
}
const auto vertexTextures = pass.getShader ()->getVertexTextures ();
const auto vertexTextures = pass.getShader ()->getFragment ().getTextures ();
if (vertexTextures.size () > 0) {
this->m_out << "Vertex textures " << textures.size () << ":";
@ -261,6 +261,34 @@ void CPrettyPrinter::printPass (const CPass& pass, int passId) {
this->decreaseIndentation ();
}
const auto vertexCombos = pass.getShader ()->getVertex ().getDiscoveredCombos ();
if (vertexCombos.size () > 0) {
this->m_out << "Vertex combos " << vertexCombos.size () << ":";
this->increaseIndentation ();
for (const auto& combo : vertexCombos) {
this->m_out << combo.first << " = " << combo.second;
this->lineEnd ();
}
this->decreaseIndentation ();
}
const auto fragmentCombos = pass.getShader ()->getFragment ().getDiscoveredCombos ();
if (fragmentCombos.size () > 0) {
this->m_out << "Vertex combos " << fragmentCombos.size () << ":";
this->increaseIndentation ();
for (const auto& combo : fragmentCombos) {
this->m_out << combo.first << " = " << combo.second;
this->lineEnd ();
}
this->decreaseIndentation ();
}
const auto constants = base->getConstants ();
if (constants.size () > 0) {

View File

@ -447,10 +447,10 @@ void CPass::setupTextureUniforms () {
// do the real, final texture setup for the whole process
auto cur = this->m_textures.begin ();
const auto end = this->m_textures.end ();
auto fragCur = this->m_shader->getFragmentTextures ().begin ();
const auto fragEnd = this->m_shader->getFragmentTextures ().end ();
auto vertCur = this->m_shader->getVertexTextures ().begin ();
const auto vertEnd = this->m_shader->getVertexTextures ().end ();
auto fragCur = this->m_shader->getFragment ().getTextures ().begin ();
const auto fragEnd = this->m_shader->getFragment ().getTextures ().end ();
auto vertCur = this->m_shader->getVertex ().getTextures ().begin ();
const auto vertEnd = this->m_shader->getVertex ().getTextures ().end ();
auto bindCur = this->m_material->getMaterial ()->getTextureBinds ().begin ();
const auto bindEnd = this->m_material->getMaterial ()->getTextureBinds ().end ();
@ -704,11 +704,11 @@ void CPass::setupShaderVariables () {
}
}
for (const auto& cur : this->m_shader->getVertexParameters ())
for (const auto& cur : this->m_shader->getVertex ().getParameters ())
if (this->m_uniforms.find (cur->getName ()) == this->m_uniforms.end ())
this->addUniform (cur);
for (const auto& cur : this->m_shader->getFragmentParameters ())
for (const auto& cur : this->m_shader->getVertex ().getParameters ())
if (this->m_uniforms.find (cur->getName ()) == this->m_uniforms.end ())
this->addUniform (cur);
}

View File

@ -41,20 +41,12 @@ const std::string& CShader::fragment () {
return this->m_fragment.compile ();
}
const std::vector<Variables::CShaderVariable*>& CShader::getVertexParameters () const {
return this->m_vertex.getParameters ();
const CShaderUnit& CShader::getVertex () const {
return this->m_vertex;
}
const std::vector<Variables::CShaderVariable*>& CShader::getFragmentParameters () const {
return this->m_fragment.getParameters ();
}
const std::map<int, std::string>& CShader::getVertexTextures () const {
return this->m_fragment.getTextures ();
}
const std::map<int, std::string>& CShader::getFragmentTextures () const {
return this->m_fragment.getTextures ();
const CShaderUnit& CShader::getFragment () const {
return this->m_fragment;
}
const std::map<std::string, int>& CShader::getCombos () const {

View File

@ -54,21 +54,13 @@ class CShader {
*/
const std::string& fragment ();
/**
* @return The parameters the vertex shader needs
* @return The vertex shader unit
*/
[[nodiscaard]]const std::vector<Variables::CShaderVariable*>& getVertexParameters () const;
[[nodiscard]] const CShaderUnit& getVertex () const;
/**
* @return The parameters the fragment shader needs
* @return The fragment shader unit
*/
[[nodiscard]] const std::vector<Variables::CShaderVariable*>& getFragmentParameters () const;
/**
* @return The textures required for the vertex shader
*/
[[nodiscard]] const std::map<int, std::string>& getVertexTextures () const;
/**
* @return The textures required for the fragment shader
*/
[[nodiscard]] const std::map<int, std::string>& getFragmentTextures () const;
[[nodiscard]] const CShaderUnit& getFragment () const;
/**
* @return The list of combos available for this shader after compilation
*/
@ -94,22 +86,6 @@ class CShader {
* The shader file this instance is loading
*/
std::string m_file;
/**
* The original file content
*/
std::string m_content;
/**
* The final, compiled content ready to be used by OpenGL
*/
std::string m_processedContent;
/**
* The contents of all the included files
*/
std::string m_includeContent;
/**
* The type of shader
*/
CGLSLContext::UnitType m_type;
/**
* The parameters the shader needs
*/

View File

@ -402,6 +402,8 @@ void CShaderUnit::parseParameterConfiguration (const std::string& type, const st
const auto textureName = data.find ("default");
// extract the texture number from the name
const char value = name.at (std::string ("g_Texture").length ());
const auto requireany = data.find ("requireany");
const auto require = data.find ("require");
// now convert it to integer
size_t index = value - '0';
@ -409,14 +411,53 @@ void CShaderUnit::parseParameterConfiguration (const std::string& type, const st
// if the texture exists (and is not null), add to the combo
auto texture = this->m_textures.find (index);
if (texture != this->m_textures.end () && (texture->second.empty () || textureName != data.end ())) {
// add the new combo to the list
this->m_discoveredCombos.insert (std::make_pair (*combo, 1));
if (textureName == data.end () && texture == this->m_textures.end ()) {
// is this required?
if (require == data.end ()) {
// if no require information we assume this one is always required, so signal it as such
sLog.exception ("Shader ", this->m_file, " requires a texture that is not present");
}
// textures linked to combos need to be tracked too
if (this->m_usedCombos.find (*combo) == this->m_usedCombos.end ())
this->m_usedCombos.insert (std::make_pair (*combo, true));
// some require conditions are set, validate these
if (requireany == data.end ()) {
// all values have to exist for this to be required
for (const auto& item : require->items ()) {
const std::string& macro = item.key ();
const auto it = this->m_combos.find (macro);
// these can not exist and that'd be fine, we just care about the values
if (it == this->m_combos.end ()) {
return;
}
if (it->second != item.value ()) {
return;
}
}
sLog.exception ("Shader ", this->m_file, " requires a texture that is not present, activated by condition");
} else {
// any of the values set are valid, check for them
for (const auto& item : require->items ()) {
const std::string& macro = item.key ();
const auto it = this->m_combos.find (macro);
// these can not exist and that'd be fine, we just care about the values
if (it == this->m_combos.end ()) {
continue;
}
if (it->second == item.value ()) {
sLog.exception ("Shader ", this->m_file, " requires a texture that is not present, activated by condition ", macro);
}
}
}
}
// add the new combo to the list
this->m_discoveredCombos.insert (std::make_pair (*combo, 1));
// textures linked to combos need to be tracked too
if (this->m_usedCombos.find (*combo) == this->m_usedCombos.end ())
this->m_usedCombos.insert (std::make_pair (*combo, true));
}
if (textureName != data.end ())

View File

@ -49,15 +49,6 @@ class CShaderUnit {
* @return The textures this shader unit requires
*/
[[nodiscard]] const std::map<int, std::string>& getTextures () const;
protected:
/**
* Extracts any and all possible shader combo configurations
* available in this shader unit, prepares includes
* and lays the ground for the actual code to be ready
*/
void preprocess ();
/**
* @return The combos set for this shader unit by the configuration
*/
@ -67,6 +58,14 @@ class CShaderUnit {
*/
[[nodiscard]] const std::map<std::string, int>& getDiscoveredCombos () const;
protected:
/**
* Extracts any and all possible shader combo configurations
* available in this shader unit, prepares includes
* and lays the ground for the actual code to be ready
*/
void preprocess ();
private:
/**
* Parses the input shader looking for possible combo values that are required for it to properly work