Commit 1aadbe16 authored by cutealien's avatar cutealien

EMT_TRANSPARENT_ALPHA_CHANNEL_REF working again like in older Irrlicht versions (1.4 or so):

It uses again SMaterial::MaterialTypeParam instead of a hardcoded values and makes an exception when MaterialTypeParam is 0 (using it like 0.5 instead) to ensure it works by default. See http://irrlicht.sourceforge.net/forum/viewtopic.php?f=7&t=48940 for new discussion.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@4569 dfc29bdd-3216-0410-991c-e03cc46cb475
parent a8867441
......@@ -101,7 +101,7 @@ namespace video
EMT_TRANSPARENT_ALPHA_CHANNEL,
//! Makes the material transparent based on the texture alpha channel.
/** If the alpha channel value is greater than 127, a
/** If the alpha channel value is greater than a certain value (default 127), a
pixel is written to the target, otherwise not. This
material does not use alpha blending and is a lot faster
than EMT_TRANSPARENT_ALPHA_CHANNEL. It is ideal for drawing
......@@ -109,7 +109,12 @@ namespace video
blurry but sharp. Only first texture is used. If you are
using this material with small textures and 3d object, it
is a good idea to load the texture in 32 bit mode
(video::IVideoDriver::setTextureCreationFlag()). */
(video::IVideoDriver::setTextureCreationFlag()).
By changing SMaterial::MaterialTypeParam you can control the value which is used
to seperate transparent and opaque pixels. The range is 0-1 (corresponding to 0-255 values
for the alpha-channel test). 0 is special and like 0.5 interpreted as 127
(if you really want no transparency at all use a very small value above 0)
*/
EMT_TRANSPARENT_ALPHA_CHANNEL_REF,
//! Makes the material transparent based on the vertex alpha value.
......
......@@ -350,7 +350,9 @@ public:
{
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
if (material.MaterialType != lastMaterial.MaterialType
|| material.MaterialTypeParam != lastMaterial.MaterialTypeParam
|| resetAllRenderstates)
{
setTextureColorStage(pID3DDevice, 0,
D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT);
......@@ -360,8 +362,7 @@ public:
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
// 127 is required by EMT_TRANSPARENT_ALPHA_CHANNEL_REF
pID3DDevice->SetRenderState(D3DRS_ALPHAREF, 127);
pID3DDevice->SetRenderState(D3DRS_ALPHAREF, material.MaterialTypeParam == 0 ? 127 : material.MaterialTypeParam * 255.f);
pID3DDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL);
pID3DDevice->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE);
}
......
......@@ -381,7 +381,9 @@ public:
{
services->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
if (material.MaterialType != lastMaterial.MaterialType
|| material.MaterialTypeParam != lastMaterial.MaterialTypeParam
|| resetAllRenderstates)
{
setTextureColorStage(pID3DDevice, 0,
D3DTA_TEXTURE, D3DTOP_MODULATE, D3DTA_CURRENT);
......@@ -391,8 +393,7 @@ public:
pID3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
// 127 is required by EMT_TRANSPARENT_ALPHA_CHANNEL_REF
pID3DDevice->SetRenderState(D3DRS_ALPHAREF, 127);
pID3DDevice->SetRenderState(D3DRS_ALPHAREF, material.MaterialTypeParam == 0 ? 127 : material.MaterialTypeParam * 255.f);
pID3DDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL);
pID3DDevice->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE);
}
......
......@@ -495,10 +495,12 @@ public:
Driver->disableTextures(1);
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
if (material.MaterialType != lastMaterial.MaterialType
|| material.MaterialTypeParam != lastMaterial.MaterialTypeParam
|| resetAllRenderstates)
{
Driver->getBridgeCalls()->setAlphaTest(true);
Driver->getBridgeCalls()->setAlphaFunc(GL_GREATER, 0.5f);
Driver->getBridgeCalls()->setAlphaFunc(GL_GREATER, material.MaterialTypeParam == 0 ? 0.5 : material.MaterialTypeParam);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
}
}
......@@ -506,7 +508,7 @@ public:
virtual void OnSetBaseMaterial(const SMaterial& material) _IRR_OVERRIDE_
{
Driver->getBridgeCalls()->setAlphaTest(true);
Driver->getBridgeCalls()->setAlphaFunc(GL_GREATER, 0.5f);
Driver->getBridgeCalls()->setAlphaFunc(GL_GREATER, material.MaterialTypeParam == 0 ? 0.5 : material.MaterialTypeParam);
}
virtual void OnUnsetMaterial() _IRR_OVERRIDE_
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment