Now parsing additional alpha modes in KRMaterial
--HG-- extra : convert_revision : svn%3A7752d6cf-9f14-4ad2-affc-04f1e67b81a5/trunk%4070
This commit is contained in:
@@ -66,7 +66,7 @@ KRMaterial::KRMaterial(const char *szName) : KRResource(szName) {
|
|||||||
m_reflectionMapOffset = KRVector2(0.0f, 0.0f);
|
m_reflectionMapOffset = KRVector2(0.0f, 0.0f);
|
||||||
m_reflectionMapScale = KRVector2(1.0f, 1.0f);
|
m_reflectionMapScale = KRVector2(1.0f, 1.0f);
|
||||||
m_reflectionFactor = 0.0f;
|
m_reflectionFactor = 0.0f;
|
||||||
m_bAlphaTest = false;
|
m_alpha_mode = KRMATERIAL_ALPHA_MODE_OPAQUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
KRMaterial::~KRMaterial() {
|
KRMaterial::~KRMaterial() {
|
||||||
@@ -105,8 +105,19 @@ bool KRMaterial::save(const std::string& path) {
|
|||||||
if(m_reflectionMap.size()) {
|
if(m_reflectionMap.size()) {
|
||||||
fprintf(f, "map_Reflection %s.pvr -s %f %f -o %f %f\n", m_reflectionMap.c_str(), m_reflectionMapScale.x, m_reflectionMapScale.y, m_reflectionMapOffset.x, m_reflectionMapOffset.y);
|
fprintf(f, "map_Reflection %s.pvr -s %f %f -o %f %f\n", m_reflectionMap.c_str(), m_reflectionMapScale.x, m_reflectionMapScale.y, m_reflectionMapOffset.x, m_reflectionMapOffset.y);
|
||||||
}
|
}
|
||||||
if(m_bAlphaTest) {
|
switch(m_alpha_mode) {
|
||||||
fprintf(f, "alpha_mode test");
|
case KRMATERIAL_ALPHA_MODE_OPAQUE:
|
||||||
|
fprintf(f, "alpha_mode opaque");
|
||||||
|
break;
|
||||||
|
case KRMATERIAL_ALPHA_MODE_TEST:
|
||||||
|
fprintf(f, "alpha_mode test");
|
||||||
|
break;
|
||||||
|
case KRMATERIAL_ALPHA_MODE_BLENDONESIDE:
|
||||||
|
fprintf(f, "alpha_mode blendoneside");
|
||||||
|
break;
|
||||||
|
case KRMATERIAL_ALPHA_MODE_BLENDTWOSIDE:
|
||||||
|
fprintf(f, "alpha_mode blendtwoside");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
fclose(f);
|
fclose(f);
|
||||||
return true;
|
return true;
|
||||||
@@ -143,8 +154,8 @@ void KRMaterial::setReflectionMap(std::string texture_name, KRVector2 texture_sc
|
|||||||
m_reflectionMapOffset = texture_offset;
|
m_reflectionMapOffset = texture_offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KRMaterial::setAlphaTest(bool bAlphaTest) {
|
void KRMaterial::setAlphaMode(KRMaterial::alpha_mode_type alpha_mode) {
|
||||||
m_bAlphaTest = bAlphaTest;
|
m_alpha_mode = alpha_mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KRMaterial::setAmbient(const KRVector3 &c) {
|
void KRMaterial::setAmbient(const KRVector3 &c) {
|
||||||
@@ -207,7 +218,7 @@ void KRMaterial::bind(KRMaterial **prevBoundMaterial, char *szPrevShaderKey, KRC
|
|||||||
bool bNormalMap = m_pNormalMap != NULL && pCamera->bEnableNormalMap;
|
bool bNormalMap = m_pNormalMap != NULL && pCamera->bEnableNormalMap;
|
||||||
bool bSpecMap = m_pSpecularMap != NULL && pCamera->bEnableSpecMap;
|
bool bSpecMap = m_pSpecularMap != NULL && pCamera->bEnableSpecMap;
|
||||||
bool bReflectionMap = m_pReflectionMap != NULL && pCamera->bEnableReflectionMap;
|
bool bReflectionMap = m_pReflectionMap != NULL && pCamera->bEnableReflectionMap;
|
||||||
bool bAlphaTest = m_bAlphaTest && bDiffuseMap;
|
bool bAlphaTest = (m_alpha_mode == KRMATERIAL_ALPHA_MODE_TEST) && bDiffuseMap;
|
||||||
|
|
||||||
KRShader *pShader = pContext->getShaderManager()->getShader("ObjectShader", pCamera, bDiffuseMap, bNormalMap, bSpecMap, cShadowBuffers, bLightMap, m_diffuseMapScale != default_scale && bDiffuseMap, m_specularMapScale != default_scale && bSpecMap, m_normalMapScale != default_scale && bNormalMap, m_diffuseMapOffset != default_offset && bDiffuseMap, m_specularMapOffset != default_offset && bSpecMap, m_normalMapOffset != default_offset && bNormalMap, bAlphaTest, renderPass);
|
KRShader *pShader = pContext->getShaderManager()->getShader("ObjectShader", pCamera, bDiffuseMap, bNormalMap, bSpecMap, cShadowBuffers, bLightMap, m_diffuseMapScale != default_scale && bDiffuseMap, m_specularMapScale != default_scale && bSpecMap, m_normalMapScale != default_scale && bNormalMap, m_diffuseMapOffset != default_offset && bDiffuseMap, m_specularMapOffset != default_offset && bSpecMap, m_normalMapOffset != default_offset && bNormalMap, bAlphaTest, renderPass);
|
||||||
|
|
||||||
|
|||||||
@@ -55,6 +55,13 @@ class KRContext;
|
|||||||
|
|
||||||
class KRMaterial : public KRResource {
|
class KRMaterial : public KRResource {
|
||||||
public:
|
public:
|
||||||
|
typedef enum {
|
||||||
|
KRMATERIAL_ALPHA_MODE_OPAQUE, // Non-transparent materials
|
||||||
|
KRMATERIAL_ALPHA_MODE_TEST, // Alpha in diffuse texture is interpreted as punch-through when < 0.5
|
||||||
|
KRMATERIAL_ALPHA_MODE_BLENDONESIDE, // Blended alpha with backface culling
|
||||||
|
KRMATERIAL_ALPHA_MODE_BLENDTWOSIDE // Blended alpha rendered in two passes. First pass renders backfaces; second pass renders frontfaces.
|
||||||
|
} alpha_mode_type;
|
||||||
|
|
||||||
KRMaterial(const char *szName);
|
KRMaterial(const char *szName);
|
||||||
~KRMaterial();
|
~KRMaterial();
|
||||||
|
|
||||||
@@ -74,7 +81,7 @@ public:
|
|||||||
void setTransparency(GLfloat a);
|
void setTransparency(GLfloat a);
|
||||||
void setShininess(GLfloat s);
|
void setShininess(GLfloat s);
|
||||||
void setReflectionFactor(GLfloat r);
|
void setReflectionFactor(GLfloat r);
|
||||||
void setAlphaTest(bool bAlphaTest);
|
void setAlphaMode(alpha_mode_type blend_mode);
|
||||||
|
|
||||||
|
|
||||||
bool isTransparent();
|
bool isTransparent();
|
||||||
@@ -85,6 +92,8 @@ public:
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
char m_szName[64];
|
char m_szName[64];
|
||||||
|
|
||||||
@@ -124,7 +133,7 @@ private:
|
|||||||
GLfloat m_ns; // Shininess
|
GLfloat m_ns; // Shininess
|
||||||
GLfloat m_reflectionFactor; // Level of reflectivity
|
GLfloat m_reflectionFactor; // Level of reflectivity
|
||||||
|
|
||||||
bool m_bAlphaTest; // When true, alpha in diffuse texture is interpreted as punch-through when < 0.5
|
alpha_mode_type m_alpha_mode;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -118,7 +118,15 @@ bool KRMaterialManager::loadFile(const char *szPath) {
|
|||||||
if(pMaterial != NULL) {
|
if(pMaterial != NULL) {
|
||||||
if(strcmp(szSymbol[0], "alpha_mode") == 0) {
|
if(strcmp(szSymbol[0], "alpha_mode") == 0) {
|
||||||
if(cSymbols == 2) {
|
if(cSymbols == 2) {
|
||||||
pMaterial->setAlphaTest(strcmp(szSymbol[1], "test") == 0);
|
if(strcmp(szSymbol[1], "test") == 0) {
|
||||||
|
pMaterial->setAlphaMode(KRMaterial::KRMATERIAL_ALPHA_MODE_TEST);
|
||||||
|
} else if(strcmp(szSymbol[1], "blendoneside") == 0) {
|
||||||
|
pMaterial->setAlphaMode(KRMaterial::KRMATERIAL_ALPHA_MODE_BLENDONESIDE);
|
||||||
|
} else if(strcmp(szSymbol[1], "blendtwoside") == 0) {
|
||||||
|
pMaterial->setAlphaMode(KRMaterial::KRMATERIAL_ALPHA_MODE_BLENDONESIDE);
|
||||||
|
} else {
|
||||||
|
pMaterial->setAlphaMode(KRMaterial::KRMATERIAL_ALPHA_MODE_OPAQUE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if(strcmp(szSymbol[0], "Ka") == 0) {
|
} else if(strcmp(szSymbol[0], "Ka") == 0) {
|
||||||
char *pScan2 = szSymbol[1];
|
char *pScan2 = szSymbol[1];
|
||||||
|
|||||||
Reference in New Issue
Block a user