diff --git a/components/nifogre/material.cpp b/components/nifogre/material.cpp index 5ca58da3b..517f29f4e 100644 --- a/components/nifogre/material.cpp +++ b/components/nifogre/material.cpp @@ -355,11 +355,17 @@ Ogre::String NIFMaterialLoader::getMaterial(const Nif::ShapeData *shapedata, if((alphaFlags>>9)&1) { +#ifndef ANDROID std::string reject; reject += getTestMode((alphaFlags>>10)&0x7); reject += " "; reject += Ogre::StringConverter::toString(alphaTest); instance->setProperty("alpha_rejection", sh::makeProperty(new sh::StringValue(reject))); +#else + // alpha test not supported in OpenGL ES 2, use manual implementation in shader + instance->setProperty("alphaTestMode", sh::makeProperty(new sh::IntValue((alphaFlags>>10)&0x7))); + instance->setProperty("alphaTestValue", sh::makeProperty(new sh::FloatValue(alphaTest/255.f))); +#endif } else instance->getMaterial()->setShadowCasterMaterial("openmw_shadowcaster_noalpha"); diff --git a/files/materials/objects.mat b/files/materials/objects.mat index 2281226b0..932c7e25f 100644 --- a/files/materials/objects.mat +++ b/files/materials/objects.mat @@ -29,6 +29,9 @@ material openmw_objects_base env_map false env_map_color 1 1 1 + alphaTestMode 0 + alphaTestValue 0 + pass { vertex_program openmw_objects_vertex @@ -50,6 +53,8 @@ material openmw_objects_base env_map $env_map env_map_color $env_map_color use_parallax $use_parallax + alphaTestMode $alphaTestMode + alphaTestValue $alphaTestValue } diffuse $diffuse diff --git a/files/materials/objects.shader b/files/materials/objects.shader index bacf3f912..87330e34e 100644 --- a/files/materials/objects.shader +++ b/files/materials/objects.shader @@ -23,6 +23,8 @@ #define DARK_MAP @shPropertyHasValue(darkMap) #define SPEC_MAP @shPropertyHasValue(specMap) && SPECULAR +#define ALPHATEST_MODE @shPropertyString(alphaTestMode) + #define PARALLAX @shPropertyBool(use_parallax) #define PARALLAX_SCALE 0.04 #define PARALLAX_BIAS -0.02 @@ -354,6 +356,10 @@ #endif #endif +#if ALPHATEST_MODE != 0 + shUniform(float, alphaTestValue) @shUniformProperty1f(alphaTestValue, alphaTestValue) +#endif + SH_START_PROGRAM { float4 newUV = UV; @@ -399,6 +405,29 @@ float4 diffuse = float4(1,1,1,1); #endif +#if ALPHATEST_MODE == 1 + if (diffuse.a >= alphaTestValue) + discard; +#elif ALPHATEST_MODE == 2 + if (diffuse.a != alphaTestValue) + discard; +#elif ALPHATEST_MODE == 3 + if (diffuse.a > alphaTestValue) + discard; +#elif ALPHATEST_MODE == 4 + if (diffuse.a <= alphaTestValue) + discard; +#elif ALPHATEST_MODE == 5 + if (diffuse.a == alphaTestValue) + discard; +#elif ALPHATEST_MODE == 6 + if (diffuse.a < alphaTestValue) + discard; +#elif ALPHATEST_MODE == 7 + discard; +#endif + + #if DETAIL_MAP #if @shPropertyString(detailMapUVSet) diffuse *= shSample(detailMap, newUV.zw)*2;