diff --git a/source/gameengine/Converter/BL_BlenderDataConversion.cpp b/source/gameengine/Converter/BL_BlenderDataConversion.cpp index c4ea4b869198..c5a450a8e0cf 100644 --- a/source/gameengine/Converter/BL_BlenderDataConversion.cpp +++ b/source/gameengine/Converter/BL_BlenderDataConversion.cpp @@ -388,7 +388,7 @@ static KX_BlenderMaterial *ConvertMaterial( name = "MA"; } - KX_BlenderMaterial *kx_blmat = new KX_BlenderMaterial(scene, mat, name, (mat ? &mat->game : nullptr), lightlayer); + KX_BlenderMaterial *kx_blmat = new KX_BlenderMaterial(scene, mat, name, lightlayer); return kx_blmat; } diff --git a/source/gameengine/Ketsji/KX_BlenderMaterial.cpp b/source/gameengine/Ketsji/KX_BlenderMaterial.cpp index ff39f5da5bc2..2c56bdf67b8b 100644 --- a/source/gameengine/Ketsji/KX_BlenderMaterial.cpp +++ b/source/gameengine/Ketsji/KX_BlenderMaterial.cpp @@ -47,9 +47,8 @@ KX_BlenderMaterial::KX_BlenderMaterial( KX_Scene *scene, Material *mat, const std::string& name, - GameSettings *game, int lightlayer) - :RAS_IPolyMaterial(name, game), + :RAS_IPolyMaterial(name), m_material(mat), m_shader(nullptr), m_blenderShader(nullptr), @@ -95,7 +94,29 @@ KX_BlenderMaterial::KX_BlenderMaterial( m_rasMode |= (mat && (mat->game.alpha_blend & GEMAT_ALPHA_SORT)) ? RAS_ZSORT : 0; } - // RAS_IPolyMaterial variables... + switch (mat->game.face_orientation) { + case GEMAT_NORMAL: + { + m_drawingMode = RAS_NORMAL; + break; + } + case GEMAT_BILLBOARD: + { + m_drawingMode = RAS_BILLBOARD; + break; + } + case GEMAT_HALO: + { + m_drawingMode = RAS_HALO; + break; + } + case GEMAT_SHADOW: + { + m_drawingMode = RAS_SHADOW; + break; + } + } + m_flag |= ((mat->mode & MA_SHLESS) != 0) ? 0 : RAS_MULTILIGHT; m_flag |= RAS_BLENDERGLSL; m_flag |= ((mat->mode2 & MA_CASTSHADOW) != 0) ? RAS_CASTSHADOW : 0; diff --git a/source/gameengine/Ketsji/KX_BlenderMaterial.h b/source/gameengine/Ketsji/KX_BlenderMaterial.h index 3e9fd86f53c0..0bf4bca00bf7 100644 --- a/source/gameengine/Ketsji/KX_BlenderMaterial.h +++ b/source/gameengine/Ketsji/KX_BlenderMaterial.h @@ -33,7 +33,6 @@ class KX_BlenderMaterial : public CValue, public RAS_IPolyMaterial KX_Scene *scene, Material *mat, const std::string& name, - GameSettings *game, int lightlayer); virtual ~KX_BlenderMaterial(); diff --git a/source/gameengine/Ketsji/KX_TextMaterial.cpp b/source/gameengine/Ketsji/KX_TextMaterial.cpp index 5131a4556cd4..b29505690bfd 100644 --- a/source/gameengine/Ketsji/KX_TextMaterial.cpp +++ b/source/gameengine/Ketsji/KX_TextMaterial.cpp @@ -29,7 +29,7 @@ #include "DNA_material_types.h" KX_TextMaterial::KX_TextMaterial() - :RAS_IPolyMaterial("__TextMaterial__", nullptr) + :RAS_IPolyMaterial("__TextMaterial__") { m_rasMode |= (RAS_ALPHA | RAS_TEXT); m_flag |= RAS_BLENDERGLSL; diff --git a/source/gameengine/Rasterizer/RAS_IPolygonMaterial.cpp b/source/gameengine/Rasterizer/RAS_IPolygonMaterial.cpp index 958cb56bc45d..9817c1c63e75 100644 --- a/source/gameengine/Rasterizer/RAS_IPolygonMaterial.cpp +++ b/source/gameengine/Rasterizer/RAS_IPolygonMaterial.cpp @@ -32,21 +32,14 @@ #include "RAS_IPolygonMaterial.h" -#include "DNA_material_types.h" - -RAS_IPolyMaterial::RAS_IPolyMaterial( - const std::string& name, - GameSettings *game) +RAS_IPolyMaterial::RAS_IPolyMaterial(const std::string& name) :m_name(name), + m_drawingMode(0), m_alphablend(0), m_zoffset(0.0f), m_rasMode(0), m_flag(0) { - if (game) { - m_drawingmode = ConvertFaceMode(game); - } - for (unsigned short i = 0; i < RAS_Texture::MaxUnits; ++i) { m_textures[i] = nullptr; } @@ -61,19 +54,6 @@ RAS_IPolyMaterial::~RAS_IPolyMaterial() } } -int RAS_IPolyMaterial::ConvertFaceMode(struct GameSettings *game) const -{ - int modefinal = 0; - - int orimode = game->face_orientation; - int alpha_blend = game->alpha_blend; - int flags = game->flag & (GEMAT_BACKCULL); - - modefinal = orimode | alpha_blend | flags; - - return modefinal; -} - bool RAS_IPolyMaterial::IsAlphaShadow() const { return (m_rasMode & RAS_ALPHA_SHADOW); @@ -119,7 +99,7 @@ bool RAS_IPolyMaterial::IsZSort() const int RAS_IPolyMaterial::GetDrawingMode() const { - return m_drawingmode; + return m_drawingMode; } int RAS_IPolyMaterial::GetAlphaBlend() const diff --git a/source/gameengine/Rasterizer/RAS_IPolygonMaterial.h b/source/gameengine/Rasterizer/RAS_IPolygonMaterial.h index 2b10b94320d6..85760629761c 100644 --- a/source/gameengine/Rasterizer/RAS_IPolygonMaterial.h +++ b/source/gameengine/Rasterizer/RAS_IPolygonMaterial.h @@ -36,43 +36,51 @@ #include "RAS_MeshObject.h" #include "RAS_Rasterizer.h" -#include - #include "MT_Vector4.h" +#include #include struct Material; struct Scene; struct GameSettings; -enum MaterialProps -{ - RAS_MULTILIGHT = (1 << 1), - RAS_BLENDERGLSL = (1 << 3), - RAS_CASTSHADOW = (1 << 4), - RAS_ONLYSHADOW = (1 << 5), -}; - -enum MaterialRasterizerModes -{ - RAS_ZSORT = (1 << 0), - RAS_ALPHA = (1 << 1), - RAS_DEPTH_ALPHA = (1 << 2), - RAS_ALPHA_SHADOW = (1 << 3), - RAS_WIRE = (1 << 4), - RAS_TEXT = (1 << 5), - RAS_TWOSIDED = (1 << 6), -}; - /** * Polygon Material on which the material buckets are sorted */ class RAS_IPolyMaterial { +public: + enum Props + { + RAS_MULTILIGHT = (1 << 1), + RAS_BLENDERGLSL = (1 << 3), + RAS_CASTSHADOW = (1 << 4), + RAS_ONLYSHADOW = (1 << 5), + }; + + enum RasterizerModes + { + RAS_ZSORT = (1 << 0), + RAS_ALPHA = (1 << 1), + RAS_DEPTH_ALPHA = (1 << 2), + RAS_ALPHA_SHADOW = (1 << 3), + RAS_WIRE = (1 << 4), + RAS_TEXT = (1 << 5), + RAS_TWOSIDED = (1 << 6), + }; + + enum DrawingModes + { + RAS_NORMAL, + RAS_BILLBOARD, + RAS_HALO, + RAS_SHADOW + }; + protected: std::string m_name; // also needed for collisionsensor - int m_drawingmode; + int m_drawingMode; int m_alphablend; float m_zoffset; int m_rasMode; @@ -81,17 +89,7 @@ class RAS_IPolyMaterial RAS_Texture *m_textures[RAS_Texture::MaxUnits]; public: - - // care! these are taken from blender polygonflags, see file DNA_mesh_types.h for #define TF_BILLBOARD etc. - enum MaterialFlags - { - BILLBOARD_SCREENALIGNED = 512, // GEMAT_HALO - BILLBOARD_AXISALIGNED = 1024, // GEMAT_BILLBOARD - SHADOW = 2048 // GEMAT_SHADOW - }; - - RAS_IPolyMaterial(const std::string& name, - GameSettings *game); + RAS_IPolyMaterial(const std::string& name); virtual ~RAS_IPolyMaterial(); diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp index 9d775280878c..6da2d6880155 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp @@ -331,20 +331,12 @@ void RAS_OpenGLRasterizer::DrawDerivedMesh(RAS_MeshSlot *ms, RAS_Rasterizer::Dra RAS_MaterialBucket *bucket = arrayBucket->GetBucket(); RAS_IPolyMaterial *material = bucket->GetPolyMaterial(); - // handle two-side - if (material->GetDrawingMode() & RAS_Rasterizer::RAS_BACKCULL) { - m_rasterizer->SetCullFace(true); - } - else { - m_rasterizer->SetCullFace(false); - } - if (bucket->IsWire()) { SetLines(true); } bool wireframe = (drawingmode == RAS_Rasterizer::RAS_WIREFRAME); - if (material->GetFlag() & RAS_BLENDERGLSL) { + if (material->GetFlag() & RAS_IPolyMaterial::RAS_BLENDERGLSL) { // GetMaterialIndex return the original mface material index, // increment by 1 to match what derived mesh is doing current_blmat_nr = arrayBucket->GetMeshMaterial()->GetIndex() + 1; diff --git a/source/gameengine/Rasterizer/RAS_Rasterizer.cpp b/source/gameengine/Rasterizer/RAS_Rasterizer.cpp index 8ad656b7166f..ca87eafe7bce 100644 --- a/source/gameengine/Rasterizer/RAS_Rasterizer.cpp +++ b/source/gameengine/Rasterizer/RAS_Rasterizer.cpp @@ -1384,9 +1384,11 @@ bool RAS_Rasterizer::NeedRayCast(KX_ClientObjectInfo *UNUSED(info), void *UNUSED void RAS_Rasterizer::GetTransform(float *origmat, int objectdrawmode, float mat[16]) { - if (objectdrawmode & RAS_IPolyMaterial::BILLBOARD_SCREENALIGNED || - objectdrawmode & RAS_IPolyMaterial::BILLBOARD_AXISALIGNED) - { + if (objectdrawmode == RAS_IPolyMaterial::RAS_NORMAL) { + // 'normal' object + memcpy(mat, origmat, sizeof(float) * 16); + } + else if (ELEM(objectdrawmode, RAS_IPolyMaterial::RAS_HALO, RAS_IPolyMaterial::RAS_BILLBOARD)) { // rotate the billboard/halo //page 360/361 3D Game Engine Design, David Eberly for a discussion // on screen aligned and axis aligned billboards @@ -1410,7 +1412,7 @@ void RAS_Rasterizer::GetTransform(float *origmat, int objectdrawmode, float mat[ // get scaling of halo object const MT_Vector3& scale = MT_Vector3(len_v3(&origmat[0]), len_v3(&origmat[4]), len_v3(&origmat[8])); - if (objectdrawmode & RAS_IPolyMaterial::BILLBOARD_SCREENALIGNED) { + if (objectdrawmode & RAS_IPolyMaterial::RAS_HALO) { up = (up - up.dot(left) * left).safe_normalized(); } else { @@ -1434,7 +1436,7 @@ void RAS_Rasterizer::GetTransform(float *origmat, int objectdrawmode, float mat[ }; memcpy(mat, tmpmat, sizeof(float) * 16); } - else if (objectdrawmode & RAS_IPolyMaterial::SHADOW) { + else { // shadow must be cast to the ground, physics system needed here! const MT_Vector3 frompoint(&origmat[12]); KX_GameObject *gameobj = KX_GameObject::GetClientObject((KX_ClientObjectInfo *)m_clientobject); @@ -1466,10 +1468,6 @@ void RAS_Rasterizer::GetTransform(float *origmat, int objectdrawmode, float mat[ memcpy(mat, origmat, sizeof(float) * 16); } } - else { - // 'normal' object - memcpy(mat, origmat, sizeof(float) * 16); - } } void RAS_Rasterizer::DisableForText()