Skip to content

Commit

Permalink
UPBGE: Cleanup face orientation management.
Browse files Browse the repository at this point in the history
The managment of face orientation is done only by the material drawing mode
now and use a list of item incremented instead of power of two value.
  • Loading branch information
panzergame committed Sep 27, 2017
1 parent 0a3eb94 commit 9dc8173
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 80 deletions.
2 changes: 1 addition & 1 deletion source/gameengine/Converter/BL_BlenderDataConversion.cpp
Expand Up @@ -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;
}
Expand Down
27 changes: 24 additions & 3 deletions source/gameengine/Ketsji/KX_BlenderMaterial.cpp
Expand Up @@ -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),
Expand Down Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion source/gameengine/Ketsji/KX_BlenderMaterial.h
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion source/gameengine/Ketsji/KX_TextMaterial.cpp
Expand Up @@ -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;
Expand Down
26 changes: 3 additions & 23 deletions source/gameengine/Rasterizer/RAS_IPolygonMaterial.cpp
Expand Up @@ -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;
}
Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand Down
64 changes: 31 additions & 33 deletions source/gameengine/Rasterizer/RAS_IPolygonMaterial.h
Expand Up @@ -36,43 +36,51 @@
#include "RAS_MeshObject.h"
#include "RAS_Rasterizer.h"

#include <string>

#include "MT_Vector4.h"

#include <string>
#include <map>

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;
Expand All @@ -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();

Expand Down
Expand Up @@ -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;
Expand Down
16 changes: 7 additions & 9 deletions source/gameengine/Rasterizer/RAS_Rasterizer.cpp
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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);
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 9dc8173

Please sign in to comment.