Skip to content

Commit

Permalink
UPBGE: Fix shader used for all transparency material in shadow render.
Browse files Browse the repository at this point in the history
Only the alpha clip and alpha to coverage transparency should be allowed
to use theirs shader for the shadow render because these both mode do
binary test which can be made also in the depth map.
But previously the test which added a material in the list of materials
allowed to use their shader was wrong because it only chacked if any
transparency mode were enabled.
To fix this issue KX_BlenderMaterial add the flag RAS_ALPHA_SHADOW to m_rasMode
when alpha clip or alpha to coverage is detected.

Test with 20*20 objects of 2 meshes:
Before: 6.10ms
After: 5.70ms (6.5%)
  • Loading branch information
panzergame committed Jul 9, 2017
1 parent 9864f03 commit 4cc1ecb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
5 changes: 4 additions & 1 deletion source/gameengine/Ketsji/KX_BlenderMaterial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,11 @@ KX_BlenderMaterial::KX_BlenderMaterial(
m_rasMode |= (mat->material_type == MA_TYPE_WIRE) ? RAS_WIRE : 0;
m_rasMode |= (mat->mode2 & MA_DEPTH_TRANSP) ? RAS_DEPTH_ALPHA : 0;

if (ELEM(m_alphablend, GEMAT_CLIP, GEMAT_ALPHA_TO_COVERAGE)) {
m_rasMode |= RAS_ALPHA_SHADOW;
}
// always zsort alpha + add
if (ELEM(m_alphablend, GEMAT_ALPHA, GEMAT_ALPHA_SORT, GEMAT_ADD) && (m_alphablend != GEMAT_CLIP)) {
else if (ELEM(m_alphablend, GEMAT_ALPHA, GEMAT_ALPHA_SORT, GEMAT_ADD)) {
m_rasMode |= RAS_ALPHA;
m_rasMode |= (mat && (mat->game.alpha_blend & GEMAT_ALPHA_SORT)) ? RAS_ZSORT : 0;
}
Expand Down
2 changes: 1 addition & 1 deletion source/gameengine/Rasterizer/RAS_IPolygonMaterial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ int RAS_IPolyMaterial::ConvertFaceMode(struct GameSettings *game) const

bool RAS_IPolyMaterial::IsAlphaShadow() const
{
return m_alphablend != GEMAT_SOLID;
return (m_rasMode & RAS_ALPHA_SHADOW);
}

bool RAS_IPolyMaterial::IsWire() const
Expand Down
14 changes: 7 additions & 7 deletions source/gameengine/Rasterizer/RAS_IPolygonMaterial.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ enum MaterialProps

enum MaterialRasterizerModes
{
RAS_COLLIDER = 2,
RAS_ZSORT = 4,
RAS_ALPHA = 8,
RAS_DEPTH_ALPHA = 16,
RAS_WIRE = 64,
RAS_TEXT = 128,
RAS_TWOSIDED = 512,
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),
};

/**
Expand Down

0 comments on commit 4cc1ecb

Please sign in to comment.