Add shader implementation of alpha test

loadfix
scrawl 10 years ago
parent 5f11ccc298
commit 6d7f4085a5

@ -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");

@ -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

@ -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;

Loading…
Cancel
Save