From 0b71328102c8cfad263e096b21a9042a3452a3c5 Mon Sep 17 00:00:00 2001 From: cutealien Date: Fri, 3 Jan 2020 14:58:46 +0000 Subject: [PATCH] Use BlendFactor only when MaterialType != EMT_ONETEXTURE_BLEND The way this was implemented BlendFactor and MaterialTypeParam could conflict otherwise as they both send the blend functions. We could probably rewrite all places which use EMT_ONETEXTURE_BLEND+MaterialTypeParam to additionally check for BlendFactor, but it would still set the blend-functions twice. I'm not sure if BlendFactor works with 2D materials currently? (but we can't set those to shaders yet anyway except in the gles branch...). I've also started documenting a few things about how I suppose it's working, I hope I got it all right. git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6034 dfc29bdd-3216-0410-991c-e03cc46cb475 --- include/EMaterialTypes.h | 4 +++- include/SMaterial.h | 17 ++++++++++++----- source/Irrlicht/CD3D9Driver.cpp | 4 +++- source/Irrlicht/CNullDriver.cpp | 4 +++- source/Irrlicht/COpenGLDriver.cpp | 4 +++- source/Irrlicht/COpenGLShaderMaterialRenderer.h | 2 +- tests/tests-last-passed-at.txt | 2 +- 7 files changed, 26 insertions(+), 11 deletions(-) diff --git a/include/EMaterialTypes.h b/include/EMaterialTypes.h index a845a1bd..cdbd4997 100644 --- a/include/EMaterialTypes.h +++ b/include/EMaterialTypes.h @@ -187,7 +187,9 @@ namespace video EMT_PARALLAX_MAP_TRANSPARENT_VERTEX_ALPHA, //! BlendFunc = source * sourceFactor + dest * destFactor ( E_BLEND_FUNC ) - /** Using only first texture. Generic blending method. */ + /** Using only first texture. Generic blending method. + The blend function is set to SMaterial::MaterialTypeParam with + pack_textureBlendFunc (for 2D) or pack_textureBlendFuncSeparate (for 3D). */ EMT_ONETEXTURE_BLEND, //! This value is not used. It only forces this enumeration to compile to 32 bit. diff --git a/include/SMaterial.h b/include/SMaterial.h index 3661f7ee..29bc3327 100644 --- a/include/SMaterial.h +++ b/include/SMaterial.h @@ -19,7 +19,8 @@ namespace video { class ITexture; - //! Flag for EMT_ONETEXTURE_BLEND, ( BlendFactor ) BlendFunc = source * sourceFactor + dest * destFactor + //! Flag for MaterialTypeParam (in combination with EMT_ONETEXTURE_BLEND) or for BlendFactor + //! BlendFunc = source * sourceFactor + dest * destFactor enum E_BLEND_FACTOR { EBF_ZERO = 0, //!< src & dest (0, 0, 0, 0) @@ -431,8 +432,8 @@ namespace video f32 Shininess; //! Free parameter, dependent on the material type. - /** Mostly ignored, used for example in EMT_PARALLAX_MAP_SOLID - and EMT_TRANSPARENT_ALPHA_CHANNEL. */ + /** Mostly ignored, used for example in EMT_PARALLAX_MAP_SOLID, + EMT_TRANSPARENT_ALPHA_CHANNEL and EMT_ONETEXTURE_BLEND. */ f32 MaterialTypeParam; //! Second free parameter, dependent on the material type. @@ -474,8 +475,14 @@ namespace video //! Store the blend factors /** textureBlendFunc/textureBlendFuncSeparate functions should be used to write - properly blending factors to this parameter. If you use EMT_ONETEXTURE_BLEND - type for this material, this field should be equal to MaterialTypeParams. */ + properly blending factors to this parameter. + Due to historical reasons this parameter is not used for material type + EMT_ONETEXTURE_BLEND which uses MaterialTypeParam instead for the blend factor. + It's generally used only for materials without any blending otherwise (like EMT_SOLID). + It's main use is to allow having shader materials which can enable/disable + blending after they have been created. + When you set this you usually also have to set BlendOperation to a value != EBO_NONE + (setting it to EBO_ADD is probably the most common one value). */ f32 BlendFactor; //! DEPRECATED. Will be removed after Irrlicht 1.9. Please use PolygonOffsetDepthBias instead. diff --git a/source/Irrlicht/CD3D9Driver.cpp b/source/Irrlicht/CD3D9Driver.cpp index 03a45864..c376ac8d 100644 --- a/source/Irrlicht/CD3D9Driver.cpp +++ b/source/Irrlicht/CD3D9Driver.cpp @@ -2219,7 +2219,9 @@ void CD3D9Driver::setBasicRenderStates(const SMaterial& material, const SMateria } // Blend Factor - if (IR(material.BlendFactor) & 0xFFFFFFFF) + if (IR(material.BlendFactor) & 0xFFFFFFFF // TODO: why the & 0xFFFFFFFF? + && material.MaterialType != EMT_ONETEXTURE_BLEND + ) { E_BLEND_FACTOR srcRGBFact = EBF_ZERO; E_BLEND_FACTOR dstRGBFact = EBF_ZERO; diff --git a/source/Irrlicht/CNullDriver.cpp b/source/Irrlicht/CNullDriver.cpp index 3c4d745c..f2c8d731 100644 --- a/source/Irrlicht/CNullDriver.cpp +++ b/source/Irrlicht/CNullDriver.cpp @@ -2759,7 +2759,9 @@ bool CNullDriver::needsTransparentRenderPass(const irr::video::SMaterial& materi // zwrite disabled and getWriteZBuffer calls this function. video::IMaterialRenderer* rnd = getMaterialRenderer(material.MaterialType); - if (rnd && rnd->isTransparent()) + // TODO: I suspect IMaterialRenderer::isTransparent also often could use SMaterial as parameter + // We could for example then get rid of IsTransparent function in SMaterial and move that to the software material renderer. + if (rnd && rnd->isTransparent()) return true; return false; diff --git a/source/Irrlicht/COpenGLDriver.cpp b/source/Irrlicht/COpenGLDriver.cpp index 8d233c2c..c7e183ee 100644 --- a/source/Irrlicht/COpenGLDriver.cpp +++ b/source/Irrlicht/COpenGLDriver.cpp @@ -2585,7 +2585,9 @@ void COpenGLDriver::setBasicRenderStates(const SMaterial& material, const SMater } // Blend Factor - if (IR(material.BlendFactor) & 0xFFFFFFFF) + if (IR(material.BlendFactor) & 0xFFFFFFFF // TODO: why the & 0xFFFFFFFF? + && material.MaterialType != EMT_ONETEXTURE_BLEND + ) { E_BLEND_FACTOR srcRGBFact = EBF_ZERO; E_BLEND_FACTOR dstRGBFact = EBF_ZERO; diff --git a/source/Irrlicht/COpenGLShaderMaterialRenderer.h b/source/Irrlicht/COpenGLShaderMaterialRenderer.h index 50e70f1d..7cae915e 100644 --- a/source/Irrlicht/COpenGLShaderMaterialRenderer.h +++ b/source/Irrlicht/COpenGLShaderMaterialRenderer.h @@ -21,7 +21,7 @@ namespace video class COpenGLDriver; class IShaderConstantSetCallBack; -//! Class for using vertex and pixel shaders with OpenGL +//! Class for using vertex and pixel shaders with OpenGL (asm not glsl!) class COpenGLShaderMaterialRenderer : public IMaterialRenderer { public: diff --git a/tests/tests-last-passed-at.txt b/tests/tests-last-passed-at.txt index d47378ad..5016da9e 100644 --- a/tests/tests-last-passed-at.txt +++ b/tests/tests-last-passed-at.txt @@ -1,4 +1,4 @@ Tests finished. 72 tests of 72 passed. Compiled as DEBUG -Test suite pass at GMT Fri Jan 03 10:49:15 2020 +Test suite pass at GMT Fri Jan 03 14:40:24 2020