Added alpha blending option to terrain lightings to allow alpha stencil textures. (#689)

Updated Terrain materials to allow diffuse textures with alpha
fix-456
NemesisMate 8 years ago committed by Rémy Bouquet
parent c6f1da0602
commit edd9a78291
  1. 36
      jme3-terrain/src/main/resources/Common/MatDefs/Terrain/SPTerrainLighting.frag
  2. 36
      jme3-terrain/src/main/resources/Common/MatDefs/Terrain/TerrainLighting.frag
  3. 7
      jme3-terrain/src/main/resources/Common/MatDefs/Terrain/TerrainLighting.j3md

@ -160,36 +160,60 @@ varying vec2 texCoord;
#endif #endif
#ifdef DIFFUSEMAP #ifdef DIFFUSEMAP
diffuseColor = texture2D(m_DiffuseMap, texCoord * m_DiffuseMap_0_scale); diffuseColor = texture2D(m_DiffuseMap, texCoord * m_DiffuseMap_0_scale);
#ifdef USE_ALPHA
alphaBlend.r *= diffuseColor.a;
#endif
diffuseColor *= alphaBlend.r; diffuseColor *= alphaBlend.r;
#endif #endif
#ifdef DIFFUSEMAP_1 #ifdef DIFFUSEMAP_1
vec4 diffuseColor1 = texture2D(m_DiffuseMap_1, texCoord * m_DiffuseMap_1_scale); vec4 diffuseColor1 = texture2D(m_DiffuseMap_1, texCoord * m_DiffuseMap_1_scale);
#ifdef USE_ALPHA
alphaBlend.g *= diffuseColor1.a;
#endif
diffuseColor = mix( diffuseColor, diffuseColor1, alphaBlend.g ); diffuseColor = mix( diffuseColor, diffuseColor1, alphaBlend.g );
#endif #endif
#ifdef DIFFUSEMAP_2 #ifdef DIFFUSEMAP_2
vec4 diffuseColor2 = texture2D(m_DiffuseMap_2, texCoord * m_DiffuseMap_2_scale); vec4 diffuseColor2 = texture2D(m_DiffuseMap_2, texCoord * m_DiffuseMap_2_scale);
#ifdef USE_ALPHA
alphaBlend.b *= diffuseColor2.a;
#endif
diffuseColor = mix( diffuseColor, diffuseColor2, alphaBlend.b ); diffuseColor = mix( diffuseColor, diffuseColor2, alphaBlend.b );
#endif #endif
#ifdef DIFFUSEMAP_3 #ifdef DIFFUSEMAP_3
vec4 diffuseColor3 = texture2D(m_DiffuseMap_3, texCoord * m_DiffuseMap_3_scale); vec4 diffuseColor3 = texture2D(m_DiffuseMap_3, texCoord * m_DiffuseMap_3_scale);
#ifdef USE_ALPHA
alphaBlend.a *= diffuseColor3.a;
#endif
diffuseColor = mix( diffuseColor, diffuseColor3, alphaBlend.a ); diffuseColor = mix( diffuseColor, diffuseColor3, alphaBlend.a );
#endif #endif
#ifdef ALPHAMAP_1 #ifdef ALPHAMAP_1
#ifdef DIFFUSEMAP_4 #ifdef DIFFUSEMAP_4
vec4 diffuseColor4 = texture2D(m_DiffuseMap_4, texCoord * m_DiffuseMap_4_scale); vec4 diffuseColor4 = texture2D(m_DiffuseMap_4, texCoord * m_DiffuseMap_4_scale);
#ifdef USE_ALPHA
alphaBlend1.r *= diffuseColor4.a;
#endif
diffuseColor = mix( diffuseColor, diffuseColor4, alphaBlend1.r ); diffuseColor = mix( diffuseColor, diffuseColor4, alphaBlend1.r );
#endif #endif
#ifdef DIFFUSEMAP_5 #ifdef DIFFUSEMAP_5
vec4 diffuseColor5 = texture2D(m_DiffuseMap_5, texCoord * m_DiffuseMap_5_scale); vec4 diffuseColor5 = texture2D(m_DiffuseMap_5, texCoord * m_DiffuseMap_5_scale);
#ifdef USE_ALPHA
alphaBlend1.g *= diffuseColor5.a;
#endif
diffuseColor = mix( diffuseColor, diffuseColor5, alphaBlend1.g ); diffuseColor = mix( diffuseColor, diffuseColor5, alphaBlend1.g );
#endif #endif
#ifdef DIFFUSEMAP_6 #ifdef DIFFUSEMAP_6
vec4 diffuseColor6 = texture2D(m_DiffuseMap_6, texCoord * m_DiffuseMap_6_scale); vec4 diffuseColor6 = texture2D(m_DiffuseMap_6, texCoord * m_DiffuseMap_6_scale);
#ifdef USE_ALPHA
alphaBlend1.b *= diffuseColor6.a;
#endif
diffuseColor = mix( diffuseColor, diffuseColor6, alphaBlend1.b ); diffuseColor = mix( diffuseColor, diffuseColor6, alphaBlend1.b );
#endif #endif
#ifdef DIFFUSEMAP_7 #ifdef DIFFUSEMAP_7
vec4 diffuseColor7 = texture2D(m_DiffuseMap_7, texCoord * m_DiffuseMap_7_scale); vec4 diffuseColor7 = texture2D(m_DiffuseMap_7, texCoord * m_DiffuseMap_7_scale);
#ifdef USE_ALPHA
alphaBlend1.a *= diffuseColor7.a;
#endif
diffuseColor = mix( diffuseColor, diffuseColor7, alphaBlend1.a ); diffuseColor = mix( diffuseColor, diffuseColor7, alphaBlend1.a );
#endif #endif
#endif #endif
@ -197,18 +221,30 @@ varying vec2 texCoord;
#ifdef ALPHAMAP_2 #ifdef ALPHAMAP_2
#ifdef DIFFUSEMAP_8 #ifdef DIFFUSEMAP_8
vec4 diffuseColor8 = texture2D(m_DiffuseMap_8, texCoord * m_DiffuseMap_8_scale); vec4 diffuseColor8 = texture2D(m_DiffuseMap_8, texCoord * m_DiffuseMap_8_scale);
#ifdef USE_ALPHA
alphaBlend2.r *= diffuseColor8.a;
#endif
diffuseColor = mix( diffuseColor, diffuseColor8, alphaBlend2.r ); diffuseColor = mix( diffuseColor, diffuseColor8, alphaBlend2.r );
#endif #endif
#ifdef DIFFUSEMAP_9 #ifdef DIFFUSEMAP_9
vec4 diffuseColor9 = texture2D(m_DiffuseMap_9, texCoord * m_DiffuseMap_9_scale); vec4 diffuseColor9 = texture2D(m_DiffuseMap_9, texCoord * m_DiffuseMap_9_scale);
#ifdef USE_ALPHA
alphaBlend2.g *= diffuseColor9.a;
#endif
diffuseColor = mix( diffuseColor, diffuseColor9, alphaBlend2.g ); diffuseColor = mix( diffuseColor, diffuseColor9, alphaBlend2.g );
#endif #endif
#ifdef DIFFUSEMAP_10 #ifdef DIFFUSEMAP_10
vec4 diffuseColor10 = texture2D(m_DiffuseMap_10, texCoord * m_DiffuseMap_10_scale); vec4 diffuseColor10 = texture2D(m_DiffuseMap_10, texCoord * m_DiffuseMap_10_scale);
#ifdef USE_ALPHA
alphaBlend2.b *= diffuseColor10.a;
#endif
diffuseColor = mix( diffuseColor, diffuseColor10, alphaBlend2.b ); diffuseColor = mix( diffuseColor, diffuseColor10, alphaBlend2.b );
#endif #endif
#ifdef DIFFUSEMAP_11 #ifdef DIFFUSEMAP_11
vec4 diffuseColor11 = texture2D(m_DiffuseMap_11, texCoord * m_DiffuseMap_11_scale); vec4 diffuseColor11 = texture2D(m_DiffuseMap_11, texCoord * m_DiffuseMap_11_scale);
#ifdef USE_ALPHA
alphaBlend2.a *= diffuseColor11.a;
#endif
diffuseColor = mix( diffuseColor, diffuseColor11, alphaBlend2.a ); diffuseColor = mix( diffuseColor, diffuseColor11, alphaBlend2.a );
#endif #endif
#endif #endif

@ -161,36 +161,60 @@ varying vec3 lightVec;
#endif #endif
#ifdef DIFFUSEMAP #ifdef DIFFUSEMAP
diffuseColor = texture2D(m_DiffuseMap, texCoord * m_DiffuseMap_0_scale); diffuseColor = texture2D(m_DiffuseMap, texCoord * m_DiffuseMap_0_scale);
#ifdef USE_ALPHA
alphaBlend.r *= diffuseColor.a;
#endif
diffuseColor *= alphaBlend.r; diffuseColor *= alphaBlend.r;
#endif #endif
#ifdef DIFFUSEMAP_1 #ifdef DIFFUSEMAP_1
vec4 diffuseColor1 = texture2D(m_DiffuseMap_1, texCoord * m_DiffuseMap_1_scale); vec4 diffuseColor1 = texture2D(m_DiffuseMap_1, texCoord * m_DiffuseMap_1_scale);
#ifdef USE_ALPHA
alphaBlend.g *= diffuseColor1.a;
#endif
diffuseColor = mix( diffuseColor, diffuseColor1, alphaBlend.g ); diffuseColor = mix( diffuseColor, diffuseColor1, alphaBlend.g );
#endif #endif
#ifdef DIFFUSEMAP_2 #ifdef DIFFUSEMAP_2
vec4 diffuseColor2 = texture2D(m_DiffuseMap_2, texCoord * m_DiffuseMap_2_scale); vec4 diffuseColor2 = texture2D(m_DiffuseMap_2, texCoord * m_DiffuseMap_2_scale);
#ifdef USE_ALPHA
alphaBlend.b *= diffuseColor2.a;
#endif
diffuseColor = mix( diffuseColor, diffuseColor2, alphaBlend.b ); diffuseColor = mix( diffuseColor, diffuseColor2, alphaBlend.b );
#endif #endif
#ifdef DIFFUSEMAP_3 #ifdef DIFFUSEMAP_3
vec4 diffuseColor3 = texture2D(m_DiffuseMap_3, texCoord * m_DiffuseMap_3_scale); vec4 diffuseColor3 = texture2D(m_DiffuseMap_3, texCoord * m_DiffuseMap_3_scale);
#ifdef USE_ALPHA
alphaBlend.a *= diffuseColor3.a;
#endif
diffuseColor = mix( diffuseColor, diffuseColor3, alphaBlend.a ); diffuseColor = mix( diffuseColor, diffuseColor3, alphaBlend.a );
#endif #endif
#ifdef ALPHAMAP_1 #ifdef ALPHAMAP_1
#ifdef DIFFUSEMAP_4 #ifdef DIFFUSEMAP_4
vec4 diffuseColor4 = texture2D(m_DiffuseMap_4, texCoord * m_DiffuseMap_4_scale); vec4 diffuseColor4 = texture2D(m_DiffuseMap_4, texCoord * m_DiffuseMap_4_scale);
#ifdef USE_ALPHA
alphaBlend1.r *= diffuseColor4.a;
#endif
diffuseColor = mix( diffuseColor, diffuseColor4, alphaBlend1.r ); diffuseColor = mix( diffuseColor, diffuseColor4, alphaBlend1.r );
#endif #endif
#ifdef DIFFUSEMAP_5 #ifdef DIFFUSEMAP_5
vec4 diffuseColor5 = texture2D(m_DiffuseMap_5, texCoord * m_DiffuseMap_5_scale); vec4 diffuseColor5 = texture2D(m_DiffuseMap_5, texCoord * m_DiffuseMap_5_scale);
#ifdef USE_ALPHA
alphaBlend1.g *= diffuseColor5.a;
#endif
diffuseColor = mix( diffuseColor, diffuseColor5, alphaBlend1.g ); diffuseColor = mix( diffuseColor, diffuseColor5, alphaBlend1.g );
#endif #endif
#ifdef DIFFUSEMAP_6 #ifdef DIFFUSEMAP_6
vec4 diffuseColor6 = texture2D(m_DiffuseMap_6, texCoord * m_DiffuseMap_6_scale); vec4 diffuseColor6 = texture2D(m_DiffuseMap_6, texCoord * m_DiffuseMap_6_scale);
#ifdef USE_ALPHA
alphaBlend1.b *= diffuseColor6.a;
#endif
diffuseColor = mix( diffuseColor, diffuseColor6, alphaBlend1.b ); diffuseColor = mix( diffuseColor, diffuseColor6, alphaBlend1.b );
#endif #endif
#ifdef DIFFUSEMAP_7 #ifdef DIFFUSEMAP_7
vec4 diffuseColor7 = texture2D(m_DiffuseMap_7, texCoord * m_DiffuseMap_7_scale); vec4 diffuseColor7 = texture2D(m_DiffuseMap_7, texCoord * m_DiffuseMap_7_scale);
#ifdef USE_ALPHA
alphaBlend1.a *= diffuseColor7.a;
#endif
diffuseColor = mix( diffuseColor, diffuseColor7, alphaBlend1.a ); diffuseColor = mix( diffuseColor, diffuseColor7, alphaBlend1.a );
#endif #endif
#endif #endif
@ -198,18 +222,30 @@ varying vec3 lightVec;
#ifdef ALPHAMAP_2 #ifdef ALPHAMAP_2
#ifdef DIFFUSEMAP_8 #ifdef DIFFUSEMAP_8
vec4 diffuseColor8 = texture2D(m_DiffuseMap_8, texCoord * m_DiffuseMap_8_scale); vec4 diffuseColor8 = texture2D(m_DiffuseMap_8, texCoord * m_DiffuseMap_8_scale);
#ifdef USE_ALPHA
alphaBlend2.r *= diffuseColor8.a;
#endif
diffuseColor = mix( diffuseColor, diffuseColor8, alphaBlend2.r ); diffuseColor = mix( diffuseColor, diffuseColor8, alphaBlend2.r );
#endif #endif
#ifdef DIFFUSEMAP_9 #ifdef DIFFUSEMAP_9
vec4 diffuseColor9 = texture2D(m_DiffuseMap_9, texCoord * m_DiffuseMap_9_scale); vec4 diffuseColor9 = texture2D(m_DiffuseMap_9, texCoord * m_DiffuseMap_9_scale);
#ifdef USE_ALPHA
alphaBlend2.g *= diffuseColor9.a;
#endif
diffuseColor = mix( diffuseColor, diffuseColor9, alphaBlend2.g ); diffuseColor = mix( diffuseColor, diffuseColor9, alphaBlend2.g );
#endif #endif
#ifdef DIFFUSEMAP_10 #ifdef DIFFUSEMAP_10
vec4 diffuseColor10 = texture2D(m_DiffuseMap_10, texCoord * m_DiffuseMap_10_scale); vec4 diffuseColor10 = texture2D(m_DiffuseMap_10, texCoord * m_DiffuseMap_10_scale);
#ifdef USE_ALPHA
alphaBlend2.b *= diffuseColor10.a;
#endif
diffuseColor = mix( diffuseColor, diffuseColor10, alphaBlend2.b ); diffuseColor = mix( diffuseColor, diffuseColor10, alphaBlend2.b );
#endif #endif
#ifdef DIFFUSEMAP_11 #ifdef DIFFUSEMAP_11
vec4 diffuseColor11 = texture2D(m_DiffuseMap_11, texCoord * m_DiffuseMap_11_scale); vec4 diffuseColor11 = texture2D(m_DiffuseMap_11, texCoord * m_DiffuseMap_11_scale);
#ifdef USE_ALPHA
alphaBlend2.a *= diffuseColor11.a;
#endif
diffuseColor = mix( diffuseColor, diffuseColor11, alphaBlend2.a ); diffuseColor = mix( diffuseColor, diffuseColor11, alphaBlend2.a );
#endif #endif
#endif #endif

@ -12,6 +12,9 @@ MaterialDef Terrain Lighting {
// Are we rendering TerrainGrid // Are we rendering TerrainGrid
Boolean isTerrainGrid Boolean isTerrainGrid
// Use diffuse alpha when mixing
Boolean useDiffuseAlpha
// Ambient color // Ambient color
Color Ambient Color Ambient
@ -160,6 +163,8 @@ MaterialDef Terrain Lighting {
DIFFUSEMAP_9_SCALE : DiffuseMap_9_scale DIFFUSEMAP_9_SCALE : DiffuseMap_9_scale
DIFFUSEMAP_10_SCALE : DiffuseMap_10_scale DIFFUSEMAP_10_SCALE : DiffuseMap_10_scale
DIFFUSEMAP_11_SCALE : DiffuseMap_11_scale DIFFUSEMAP_11_SCALE : DiffuseMap_11_scale
USE_ALPHA : useDiffuseAlpha
} }
} }
@ -223,6 +228,8 @@ MaterialDef Terrain Lighting {
DIFFUSEMAP_9_SCALE : DiffuseMap_9_scale DIFFUSEMAP_9_SCALE : DiffuseMap_9_scale
DIFFUSEMAP_10_SCALE : DiffuseMap_10_scale DIFFUSEMAP_10_SCALE : DiffuseMap_10_scale
DIFFUSEMAP_11_SCALE : DiffuseMap_11_scale DIFFUSEMAP_11_SCALE : DiffuseMap_11_scale
USE_ALPHA : useDiffuseAlpha
} }
} }

Loading…
Cancel
Save