Added cull_hardware setting to material scripts, make bow string visible

By not culling it. See Bug #120.
stable-5.2
Armin Burgmeier 2010-01-29 15:58:33 +01:00
parent 81d85ab6d9
commit 5101d10e37
6 changed files with 59 additions and 20 deletions

View File

@ -5,6 +5,8 @@ material Leather
{
pass
{
cull_hardware none
ambient 0.500000 0.500000 0.500000 1.000000
diffuse 0.203922 0.175686 0.012549 1.000000
specular 0.500000 0.500000 0.500000 1.000000 12.500000

View File

@ -682,7 +682,7 @@ namespace
glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, Color);
}
void RenderSubMeshImpl(StdMeshInstance& instance, unsigned int submesh_index, DWORD dwModClr, DWORD dwPlayerColor)
void RenderSubMeshImpl(StdMeshInstance& instance, unsigned int submesh_index, DWORD dwModClr, DWORD dwPlayerColor, bool parity)
{
const StdSubMesh& submesh = instance.Mesh.GetSubMesh(submesh_index);
const StdMeshMaterial& material = submesh.GetMaterial();
@ -724,6 +724,21 @@ namespace
glMaterialfv(GL_FRONT, GL_EMISSION, pass.Emissive);
glMaterialf(GL_FRONT, GL_SHININESS, pass.Shininess);
switch(pass.CullHardware)
{
case StdMeshMaterialPass::CH_Clockwise:
glEnable(GL_CULL_FACE);
glCullFace(parity ? GL_FRONT : GL_BACK);
break;
case StdMeshMaterialPass::CH_CounterClockwise:
glEnable(GL_CULL_FACE);
glCullFace(parity ? GL_BACK : GL_FRONT);
break;
case StdMeshMaterialPass::CH_None:
glDisable(GL_CULL_FACE);
break;
}
// TODO: Use vbo if available.
// Note that we need to do this before we do glTexCoordPointer for the
// texture units below, otherwise the texcoordpointer is reset by this
@ -855,13 +870,13 @@ namespace
}
}
void RenderMeshImpl(StdMeshInstance& instance, DWORD dwModClr, DWORD dwPlayerColor)
void RenderMeshImpl(StdMeshInstance& instance, DWORD dwModClr, DWORD dwPlayerColor, bool parity)
{
const StdMesh& mesh = instance.Mesh;
// Render each submesh
for(unsigned int i = 0; i < mesh.GetNumSubMeshes(); ++i)
RenderSubMeshImpl(instance, i, dwModClr, dwPlayerColor);
RenderSubMeshImpl(instance, i, dwModClr, dwPlayerColor, parity);
#if 0
// Draw attached bone
@ -895,9 +910,10 @@ namespace
iter->FinalTrans(0,3), iter->FinalTrans(1,3), iter->FinalTrans(2,3), 1
};
// TODO: Take attach transform's parity into account
glPushMatrix();
glMultMatrixf(attach_trans_gl);
RenderMeshImpl(*iter->Child, dwModClr, dwPlayerColor);
RenderMeshImpl(*iter->Child, dwModClr, dwPlayerColor, parity);
glPopMatrix();
#if 0
@ -934,6 +950,8 @@ namespace
OgreToClonk(0,2), OgreToClonk(1,2), OgreToClonk(2,2), 0,
OgreToClonk(0,3), OgreToClonk(1,3), OgreToClonk(2,3), 1
};
const bool OgreToClonkParity = OgreToClonk.Determinant() > 0.0f;
}
void CStdGL::PerformMesh(StdMeshInstance &instance, float tx, float ty, float twdt, float thgt, DWORD dwPlayerColor, CBltTransform* pTransform)
@ -944,7 +962,7 @@ void CStdGL::PerformMesh(StdMeshInstance &instance, float tx, float ty, float tw
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_BLEND); // TODO: Shouldn't this always be enabled? - blending does not work for meshes without this though.
glEnable(GL_CULL_FACE);
//glEnable(GL_CULL_FACE);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
@ -956,7 +974,7 @@ void CStdGL::PerformMesh(StdMeshInstance &instance, float tx, float ty, float tw
glTranslatef(-ZoomX, -ZoomY, 0.0f);
// TODO: Initialize with OgreToClonk matrix parity
bool parity = true;
bool parity = OgreToClonkParity;
if(pTransform)
{
const GLfloat transform[16] = { pTransform->mat[0], pTransform->mat[3], 0, pTransform->mat[6], pTransform->mat[1], pTransform->mat[4], 0, pTransform->mat[7], 0, 0, 1, 0, pTransform->mat[2], pTransform->mat[5], 0, pTransform->mat[8] };
@ -970,14 +988,9 @@ void CStdGL::PerformMesh(StdMeshInstance &instance, float tx, float ty, float tw
- transform[0]*transform[13]*transform[7]
- transform[4]*transform[1]*transform[15]
- transform[12]*transform[5]*transform[3];
if(det < 0) parity = false;
if(det < 0) parity = !parity;
}
if(parity)
glCullFace(GL_BACK);
else
glCullFace(GL_FRONT);
// Convert bounding box to clonk coordinate system
// (TODO: We should cache this, not sure where though)
const StdMeshBox& box = mesh.GetBoundingBox();
@ -1047,7 +1060,7 @@ void CStdGL::PerformMesh(StdMeshInstance &instance, float tx, float ty, float tw
CClrModAddMap* ClrModMap = fUseClrModMap ? pClrModMap : NULL;
#endif
RenderMeshImpl(instance, dwModClr, dwPlayerColor);
RenderMeshImpl(instance, dwModClr, dwPlayerColor, parity);
glActiveTexture(GL_TEXTURE0); // switch back to default
glClientActiveTexture(GL_TEXTURE0); // switch back to default

View File

@ -330,8 +330,7 @@ StdMeshMatrix StdMeshMatrix::Inverse(const StdMeshMatrix& mat)
{
StdMeshMatrix m;
const float det = mat.a[0][0]*mat.a[1][1]*mat.a[2][2] + mat.a[0][1]*mat.a[1][2]*mat.a[2][0] + mat.a[0][2]*mat.a[1][0]*mat.a[2][1]
- mat.a[0][0]*mat.a[1][2]*mat.a[2][1] - mat.a[0][1]*mat.a[1][0]*mat.a[2][2] - mat.a[0][2]*mat.a[1][1]*mat.a[2][0];
const float det = mat.Determinant();
assert(det != 0.0f);
m.a[0][0] = (mat.a[1][1]*mat.a[2][2] - mat.a[1][2]*mat.a[2][1]) / det;
@ -475,6 +474,12 @@ StdMeshMatrix StdMeshMatrix::TransformInverse(const StdMeshTransformation& trans
return m;
}
float StdMeshMatrix::Determinant() const
{
return a[0][0]*a[1][1]*a[2][2] + a[0][1]*a[1][2]*a[2][0] + a[0][2]*a[1][0]*a[2][1]
- a[0][0]*a[1][2]*a[2][1] - a[0][1]*a[1][0]*a[2][2] - a[0][2]*a[1][1]*a[2][0];
}
StdMeshMatrix operator*(const StdMeshMatrix& lhs, const StdMeshMatrix& rhs)
{
StdMeshMatrix m;

View File

@ -118,6 +118,8 @@ public:
float& operator()(int i, int j) { return a[i][j]; }
float operator()(int i, int j) const { return a[i][j]; }
float Determinant() const;
private:
// 3x3 orthogonal + translation in last column
float a[3][4];

View File

@ -107,6 +107,12 @@ namespace
{ "src_manual", StdMeshMaterialTextureUnit::BOS_Manual },
{ NULL }
};
const Enumerator<StdMeshMaterialPass::CullHardwareType> CullHardwareEnumerators[] = {
{ "clockwise", StdMeshMaterialPass::CH_Clockwise },
{ "anticlockwise", StdMeshMaterialPass::CH_CounterClockwise },
{ "none", StdMeshMaterialPass::CH_None }
};
}
StdMeshMaterialError::StdMeshMaterialError(const StdStrBuf& message, const char* file, unsigned int line)
@ -573,7 +579,7 @@ void StdMeshMaterialTextureUnit::Load(StdMeshMaterialParserCtx& ctx)
}
StdMeshMaterialPass::StdMeshMaterialPass():
DepthWrite(true)
DepthWrite(true), CullHardware(CH_Clockwise)
{
Ambient[0] = Ambient[1] = Ambient[2] = 1.0f; Ambient[3] = 1.0f;
Diffuse[0] = Diffuse[1] = Diffuse[2] = 1.0f; Diffuse[3] = 1.0f;
@ -631,6 +637,10 @@ void StdMeshMaterialPass::Load(StdMeshMaterialParserCtx& ctx)
{
DepthWrite = ctx.AdvanceBoolean();
}
else if(token_name == "cull_hardware")
{
CullHardware = ctx.AdvanceEnum(CullHardwareEnumerators);
}
else
ctx.ErrorUnexpectedIdentifier(token_name);
}

View File

@ -64,10 +64,10 @@ public:
};
enum FilteringType {
F_None,
F_Point,
F_Linear,
F_Anisotropic
F_None,
F_Point,
F_Linear,
F_Anisotropic
};
enum BlendOpType {
@ -160,6 +160,12 @@ private:
class StdMeshMaterialPass
{
public:
enum CullHardwareType {
CH_Clockwise,
CH_CounterClockwise,
CH_None
};
StdMeshMaterialPass();
void Load(StdMeshMaterialParserCtx& ctx);
@ -172,6 +178,7 @@ public:
float Shininess;
bool DepthWrite;
CullHardwareType CullHardware;
};
class StdMeshMaterialTechnique