blender/source/gameengine/Ketsji/KX_BlenderMaterial.h
Brecht Van Lommel 908337bee1 Game Engine: alpha blending and sorting
=======================================

Alpha blending + sorting was revised, to fix bugs and get it
to work more predictable.

* A new per texture face "Sort" setting defines if the face
  is alpha sorted or not, instead of abusing the "ZTransp"
  setting as it did before.
* Existing files are converted to hopefully match the old
  behavior as much as possible with a version patch.
* On new meshes the Sort flag is disabled by the default, to
  avoid unexpected and hard to find slowdowns.
* Alpha sorting for faces was incredibly slow. Sorting faces
  in a mesh with 600 faces lowered the framerate from 200 to
  70 fps in my test.. the sorting there case goes about 15x
  faster now, but it is still advised to use Clip Alpha if
  possible instead of regular Alpha.
* There still various limitations in the alpha sorting code,
  I've added some comments to the code about this.

Some docs at the bottom of the page:
http://www.blender.org/development/current-projects/changes-since-246/realtime-glsl-materials/

Merged some fixes from the apricot branch, most important
change is that  tangents are now exactly the same as the rest
of Blender, instead of being computed in the game engine with a
different algorithm.

Also, the subversion was bumped to 1.
2008-07-29 15:48:31 +00:00

136 lines
2.9 KiB
C++

#ifndef __KX_BLENDER_MATERIAL_H__
#define __KX_BLENDER_MATERIAL_H__
#include <vector>
#include "RAS_IPolygonMaterial.h"
#include "BL_Material.h"
#include "BL_Texture.h"
#include "BL_Shader.h"
#include "BL_BlenderShader.h"
#include "PyObjectPlus.h"
#include "MT_Vector3.h"
#include "MT_Vector4.h"
struct MTFace;
class KX_Scene;
class KX_BlenderMaterial : public PyObjectPlus, public RAS_IPolyMaterial
{
Py_Header;
public:
// --------------------------------
KX_BlenderMaterial(
class KX_Scene* scene,
BL_Material* mat,
bool skin,
int lightlayer,
void* clientobject,
PyTypeObject* T=&Type
);
virtual ~KX_BlenderMaterial();
// --------------------------------
virtual TCachingInfo GetCachingInfo(void) const {
return (void*) this;
}
virtual
bool Activate(
RAS_IRasterizer* rasty,
TCachingInfo& cachingInfo
) const;
virtual
void ActivateMeshSlot(
const KX_MeshSlot & ms,
RAS_IRasterizer* rasty
) const;
void ActivateMat(
RAS_IRasterizer* rasty,
TCachingInfo& cachingInfo
)const;
void ActivatShaders(
RAS_IRasterizer* rasty,
TCachingInfo& cachingInfo
)const;
void ActivateBlenderShaders(
RAS_IRasterizer* rasty,
TCachingInfo& cachingInfo
)const;
MTFace* GetMTFace(void) const;
unsigned int* GetMCol(void) const;
// for ipos
void UpdateIPO(
MT_Vector4 rgba, MT_Vector3 specrgb,
MT_Scalar hard, MT_Scalar spec,
MT_Scalar ref, MT_Scalar emit, MT_Scalar alpha
);
// --------------------------------
virtual PyObject* _getattr(const STR_String& attr);
virtual int _setattr(const STR_String& attr, PyObject *pyvalue);
KX_PYMETHOD_DOC( KX_BlenderMaterial, getShader );
KX_PYMETHOD_DOC( KX_BlenderMaterial, getMaterialIndex );
KX_PYMETHOD_DOC( KX_BlenderMaterial, getTexture );
KX_PYMETHOD_DOC( KX_BlenderMaterial, setTexture );
KX_PYMETHOD_DOC( KX_BlenderMaterial, setBlending );
// --------------------------------
// pre calculate to avoid pops/lag at startup
virtual void OnConstruction( );
static void EndFrame();
private:
BL_Material* mMaterial;
BL_Shader* mShader;
BL_BlenderShader* mBlenderShader;
KX_Scene* mScene;
BL_Texture mTextures[MAXTEX]; // texture array
bool mUserDefBlend;
unsigned int mBlendFunc[2];
bool mModified;
bool mConstructed; // if false, don't clean on exit
void SetBlenderGLSLShader();
void ActivatGLMaterials( RAS_IRasterizer* rasty )const;
void ActivateTexGen( RAS_IRasterizer *ras ) const;
bool UsesLighting(RAS_IRasterizer *rasty) const;
// message centers
void setTexData( bool enable,RAS_IRasterizer *ras);
void setBlenderShaderData( bool enable, RAS_IRasterizer *ras);
void setShaderData( bool enable, RAS_IRasterizer *ras);
void setObjectMatrixData(int i, RAS_IRasterizer *ras);
void setTexMatrixData(int i);
void setLightData();
// cleanup stuff
void OnExit();
// shader chacing
static BL_BlenderShader *mLastBlenderShader;
static BL_Shader *mLastShader;
mutable int mPass;
};
#endif