fix: blending mode for passes using the wrong value

fix: shader uniforms from project properties should now be taken into account
This commit is contained in:
Almamu 2025-04-17 03:44:13 +02:00
parent beb186050b
commit 756f28ce19
3 changed files with 83 additions and 84 deletions

View File

@ -78,13 +78,13 @@ void CPass::setupRenderFramebuffer () {
glViewport (0, 0, this->m_drawTo->getRealWidth (), this->m_drawTo->getRealHeight ()); glViewport (0, 0, this->m_drawTo->getRealWidth (), this->m_drawTo->getRealHeight ());
// set texture blending // set texture blending
if (this->m_pass->getBlendingMode () == "translucent") { if (this->getBlendingMode () == "translucent") {
glEnable (GL_BLEND); glEnable (GL_BLEND);
glBlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
} else if (this->m_pass->getBlendingMode () == "additive") { } else if (this->getBlendingMode () == "additive") {
glEnable (GL_BLEND); glEnable (GL_BLEND);
glBlendFuncSeparate (GL_SRC_ALPHA, GL_ONE, GL_SRC_ALPHA, GL_ONE); glBlendFuncSeparate (GL_SRC_ALPHA, GL_ONE, GL_SRC_ALPHA, GL_ONE);
} else if (this->m_pass->getBlendingMode () == "normal") { } else if (this->getBlendingMode () == "normal") {
glEnable (GL_BLEND); glEnable (GL_BLEND);
glBlendFuncSeparate (GL_ONE, GL_ZERO, GL_ONE, GL_ZERO); glBlendFuncSeparate (GL_ONE, GL_ZERO, GL_ONE, GL_ZERO);
} else { } else {
@ -369,18 +369,24 @@ void CPass::setupShaders () {
// ensure the constants are defined // ensure the constants are defined
const ITexture* texture0 = this->m_material->getImage ()->getTexture (); const ITexture* texture0 = this->m_material->getImage ()->getTexture ();
// copy the combos from the pass
this->m_combos.insert (this->m_pass->getCombos ().begin (), this->m_pass->getCombos ().end ());
// TODO: THE VALUES ARE THE SAME AS THE ENUMERATION, SO MAYBE IT HAS TO BE SPECIFIED FOR THE TEXTURE 0 OF ALL // TODO: THE VALUES ARE THE SAME AS THE ENUMERATION, SO MAYBE IT HAS TO BE SPECIFIED FOR THE TEXTURE 0 OF ALL
// ELEMENTS? // ELEMENTS?
if (texture0 != nullptr) { if (texture0 != nullptr) {
if (texture0->getFormat () == ITexture::TextureFormat::RG88) { if (texture0->getFormat () == ITexture::TextureFormat::RG88) {
this->m_foundCombos.insert(std::pair("TEX0FORMAT", 8)); this->m_combos.insert_or_assign ("TEX0FORMAT", 8);
} else if (texture0->getFormat () == ITexture::TextureFormat::R8) { } else if (texture0->getFormat () == ITexture::TextureFormat::R8) {
this->m_foundCombos.insert (std::pair("TEX0FORMAT", 9)); this->m_combos.insert_or_assign ("TEX0FORMAT", 9);
} }
} }
// TODO: REVIEW THE SHADER TEXTURES HERE, THE ONES PASSED ON TO THE SHADER SHOULD NOT BE IN THE LIST
// TODO: USED TO BUILD THE TEXTURES LATER
// use the combos copied from the pass so it includes the texture format
this->m_shader = new Render::Shaders::CShader ( this->m_shader = new Render::Shaders::CShader (
this->getMaterial ()->getImage ()->getContainer (), this->m_pass->getShader (), this->m_pass->getCombos (), this->getMaterial ()->getImage ()->getContainer (), this->m_pass->getShader (), this->m_combos,
this->m_pass->getTextures (), this->m_pass->getConstants () this->m_pass->getTextures (), this->m_pass->getConstants ()
); );
@ -464,36 +470,34 @@ void CPass::setupTextureUniforms () {
this->addUniform ("g_Texture7", 7); this->addUniform ("g_Texture7", 7);
this->addUniform ("g_Texture0Resolution", texture->getResolution ()); this->addUniform ("g_Texture0Resolution", texture->getResolution ());
// do the real, final texture setup for the whole process // TODO: SHOULDN'T THIS POINT TO THE BIND DIRECTLY? WHAT GIVES?
auto cur = this->m_textures.begin (); for (const auto& bind : this->m_material->getMaterial ()->getTextureBinds ()) {
const auto end = this->m_textures.end (); this->m_finalTextures [bind.first] = nullptr;
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 ();
int index = 1;
// technically m_textures should have the right amount of textures
// but better be safe than sorry
while (bindCur != bindEnd || cur != end || fragCur != fragEnd || vertCur != vertEnd) {
if (bindCur != bindEnd) {
this->m_finalTextures [bindCur->first] = nullptr;
++bindCur;
} }
if (cur != end) { int index = 0;
if ((*cur) != nullptr)
this->m_finalTextures [index] = *cur;
index++; for (const auto& texture : this->m_textures) {
++cur; ++index;
if (texture == nullptr) {
continue;
} }
if (fragCur != fragEnd) { this->m_finalTextures [index] = texture;
std::string textureName = fragCur->second; }
for (const auto& texture : this->m_shader->getFragment ().getTextures ()) {
// do not need to add a texture if there's one already
if (this->m_finalTextures.find (texture.first) != this->m_finalTextures.end ()) {
continue;
}
if (texture.first == 0) {
continue;
}
std::string textureName = texture.second;
try { try {
// resolve the texture first // resolve the texture first
@ -509,23 +513,30 @@ void CPass::setupTextureUniforms () {
// ensure there's no texture in that slot already, shader textures are defaults in case nothing is // ensure there's no texture in that slot already, shader textures are defaults in case nothing is
// there // there
if (this->m_finalTextures.find (fragCur->first) == this->m_finalTextures.end ()) if (this->m_finalTextures.find (texture.first) == this->m_finalTextures.end ())
this->m_finalTextures [fragCur->first] = textureRef; this->m_finalTextures [texture.first] = textureRef;
} catch (std::runtime_error& ex) { } catch (std::runtime_error& ex) {
sLog.error ("Cannot resolve texture ", textureName, " for fragment shader ", ex.what ()); sLog.error ("Cannot resolve texture ", textureName, " for fragment shader ", ex.what ());
} }
++fragCur;
} }
if (vertCur != vertEnd) { for (const auto& texture : this->m_shader->getVertex ().getTextures ()) {
std::string textureName = vertCur->second; // do not need to add a texture if there's one already
if (this->m_finalTextures.find (texture.first) != this->m_finalTextures.end ()) {
continue;
}
if (texture.first == 0) {
continue;
}
std::string textureName = texture.second;
try { try {
// resolve the texture first // resolve the texture first
const ITexture* textureRef; const ITexture* textureRef;
if (textureName.find ("_rt_") == 0) { if (textureName.find ("_rt_") == 0 || textureName.find ("_alias_") == 0) {
textureRef = this->getMaterial ()->getEffect ()->findFBO (textureName); textureRef = this->getMaterial ()->getEffect ()->findFBO (textureName);
if (textureRef == nullptr) if (textureRef == nullptr)
@ -535,13 +546,10 @@ void CPass::setupTextureUniforms () {
// ensure there's no texture in that slot already, shader textures are defaults in case nothing is // ensure there's no texture in that slot already, shader textures are defaults in case nothing is
// there // there
if (this->m_finalTextures.find (vertCur->first) == this->m_finalTextures.end ()) if (this->m_finalTextures.find (texture.first) == this->m_finalTextures.end ())
this->m_finalTextures [vertCur->first] = textureRef; this->m_finalTextures [texture.first] = textureRef;
} catch (std::runtime_error& ex) { } catch (std::runtime_error& ex) {
sLog.error ("Cannot resolve texture ", textureName, " for vertex shader ", ex.what ()); sLog.error ("Cannot resolve texture ", textureName, " for fragment shader ", ex.what ());
}
++vertCur;
} }
} }
@ -689,10 +697,6 @@ void CPass::setupShaderVariables () {
if (this->m_uniforms.find (cur->getName ()) == this->m_uniforms.end ()) if (this->m_uniforms.find (cur->getName ()) == this->m_uniforms.end ())
this->addUniform (cur); this->addUniform (cur);
if (this->getMaterial ()->getImage ()->getImage ()->getName ()== "Blur") {
sLog.out("girl!");
}
// find variables in the shaders and set the value with the constants if possible // find variables in the shaders and set the value with the constants if possible
for (const auto& [name, value] : this->m_pass->getConstants ()) { for (const auto& [name, value] : this->m_pass->getConstants ()) {
const auto parameters = this->m_shader->findParameter (name); const auto parameters = this->m_shader->findParameter (name);
@ -736,12 +740,7 @@ void CPass::setupShaderVariables () {
} else if (value->is<CShaderConstantProperty> ()) { } else if (value->is<CShaderConstantProperty> ()) {
const auto property = value->as<CShaderConstantProperty> (); const auto property = value->as<CShaderConstantProperty> ();
// resolve the property to a current setting this->addUniform (var, property->getProperty ());
// resolve property to a user setting and store that value instead
// properties have different kinds of values
sLog.out("property!");
} else { } else {
sLog.exception ("Constant ", name, sLog.exception ("Constant ", name,
" type does not match pixel/vertex shader variable and cannot be converted (", " type does not match pixel/vertex shader variable and cannot be converted (",
@ -771,7 +770,7 @@ void CPass::addUniform (CShaderVariable* value) {
sLog.exception ("Trying to add an uniform from an unknown type: ", value->getName ()); sLog.exception ("Trying to add an uniform from an unknown type: ", value->getName ());
} }
void CPass::addUniform (CShaderVariable* value, CProperty* setting) { void CPass::addUniform (CShaderVariable* value, const CProperty* setting) {
// TODO: CHECK THIS? CAN WE KEEP A REF SO THE VALUES ARE AUTOMATICALLY UPDATED? // TODO: CHECK THIS? CAN WE KEEP A REF SO THE VALUES ARE AUTOMATICALLY UPDATED?
// TODO: MAYBE PROVIDE PUBLIC CASTS FOR EVERYTHING INSTEAD OF MANUALLY DOING IT EVERYWHERE // TODO: MAYBE PROVIDE PUBLIC CASTS FOR EVERYTHING INSTEAD OF MANUALLY DOING IT EVERYWHERE
if (value->is<CShaderVariableVector2> ()) { if (value->is<CShaderVariableVector2> ()) {

View File

@ -109,7 +109,7 @@ class CPass final : public Helpers::CContextAware {
void setupAttributes (); void setupAttributes ();
void addAttribute (const std::string& name, GLint type, GLint elements, const GLuint* value); void addAttribute (const std::string& name, GLint type, GLint elements, const GLuint* value);
void addUniform (CShaderVariable* value); void addUniform (CShaderVariable* value);
void addUniform (CShaderVariable* value, CProperty* setting); void addUniform (CShaderVariable* value, const CProperty* setting);
void addUniform (const std::string& name, CShaderConstant* value); void addUniform (const std::string& name, CShaderConstant* value);
void addUniform (const std::string& name, const CShaderConstant* value); void addUniform (const std::string& name, const CShaderConstant* value);
void addUniform (const std::string& name, int value); void addUniform (const std::string& name, int value);
@ -154,7 +154,7 @@ class CPass final : public Helpers::CContextAware {
const Core::Objects::Images::Materials::CPass* m_pass; const Core::Objects::Images::Materials::CPass* m_pass;
std::vector<const ITexture*> m_textures; std::vector<const ITexture*> m_textures;
std::map<int, const CFBO*> m_fbos; std::map<int, const CFBO*> m_fbos;
std::map<std::string, bool> m_foundCombos; std::map<std::string, int> m_combos;
std::vector<AttribEntry*> m_attribs; std::vector<AttribEntry*> m_attribs;
std::map<std::string, UniformEntry*> m_uniforms; std::map<std::string, UniformEntry*> m_uniforms;
std::map<std::string, ReferenceUniformEntry*> m_referenceUniforms; std::map<std::string, ReferenceUniformEntry*> m_referenceUniforms;