Implement NiTexturingProperty::DecalTexture

pull/911/head
scrawl 9 years ago
parent 414c19f717
commit 6e7c6fdd7e

@ -1374,6 +1374,7 @@ namespace NifOsg
case Nif::NiTexturingProperty::DarkTexture:
case Nif::NiTexturingProperty::BumpTexture:
case Nif::NiTexturingProperty::DetailTexture:
case Nif::NiTexturingProperty::DecalTexture:
break;
case Nif::NiTexturingProperty::GlossTexture:
{
@ -1382,11 +1383,6 @@ namespace NifOsg
std::cerr << "NiTexturingProperty::GlossTexture in " << mFilename << " not currently used." << std::endl;
continue;
}
case Nif::NiTexturingProperty::DecalTexture:
{
std::cerr << "NiTexturingProperty::DecalTexture in " << mFilename << " not currently used." << std::endl;
continue;
}
default:
{
std::cerr << "Warning: unhandled texture stage " << i << " in " << mFilename << std::endl;
@ -1454,6 +1450,21 @@ namespace NifOsg
// Set this texture to Off by default since we can't render it with the fixed-function pipeline
stateset->setTextureMode(texUnit, GL_TEXTURE_2D, osg::StateAttribute::OFF);
}
else if (i == Nif::NiTexturingProperty::DecalTexture)
{
osg::TexEnvCombine* texEnv = new osg::TexEnvCombine;
texEnv->setCombine_RGB(GL_INTERPOLATE);
texEnv->setSource0_RGB(GL_TEXTURE);
texEnv->setOperand0_RGB(GL_SRC_COLOR);
texEnv->setSource1_RGB(GL_PREVIOUS_ARB);
texEnv->setOperand1_RGB(GL_SRC_COLOR);
texEnv->setSource2_RGB(GL_TEXTURE);
texEnv->setOperand2_RGB(GL_SRC_ALPHA);
texEnv->setCombine_Alpha(GL_REPLACE);
texEnv->setSource0_Alpha(GL_PREVIOUS);
texEnv->setOperand0_Alpha(GL_SRC_ALPHA);
stateset->setTextureAttributeAndModes(texUnit, texEnv, osg::StateAttribute::ON);
}
switch (i)
{
@ -1472,6 +1483,9 @@ namespace NifOsg
case Nif::NiTexturingProperty::DetailTexture:
texture2d->setName("detailMap");
break;
case Nif::NiTexturingProperty::DecalTexture:
texture2d->setName("decalMap");
break;
default:
break;
}

@ -88,11 +88,11 @@ namespace Shader
return newStateSet.get();
}
const char* defaultTextures[] = { "diffuseMap", "normalMap", "emissiveMap", "darkMap", "detailMap", "envMap", "specularMap" };
const char* defaultTextures[] = { "diffuseMap", "normalMap", "emissiveMap", "darkMap", "detailMap", "envMap", "specularMap", "decalMap" };
bool isTextureNameRecognized(const std::string& name)
{
for (unsigned int i=0; i<sizeof(defaultTextures)/sizeof(defaultTextures[0]); ++i)
if (name.c_str() == defaultTextures[i])
if (name == defaultTextures[i])
return true;
return false;
}

@ -15,6 +15,11 @@ uniform sampler2D detailMap;
varying vec2 detailMapUV;
#endif
#if @decalMap
uniform sampler2D decalMap;
varying vec2 decalMapUV;
#endif
#if @emissiveMap
uniform sampler2D emissiveMap;
varying vec2 emissiveMapUV;
@ -67,6 +72,11 @@ void main()
gl_FragData[0].xyz *= texture2D(darkMap, darkMapUV).xyz;
#endif
#if @decalMap
vec4 decalTex = texture2D(decalMap, decalMapUV);
gl_FragData[0].xyz = mix(gl_FragData[0].xyz, decalTex.xyz, decalTex.a);
#endif
vec3 viewNormal = passViewNormal;
#if @normalMap

@ -12,6 +12,10 @@ varying vec2 darkMapUV;
varying vec2 detailMapUV;
#endif
#if @decalMap
varying vec2 decalMapUV;
#endif
#if @emissiveMap
varying vec2 emissiveMapUV;
#endif
@ -71,6 +75,10 @@ void main(void)
detailMapUV = (gl_TextureMatrix[@detailMapUV] * gl_MultiTexCoord@detailMapUV).xy;
#endif
#if @decalMap
decalMapUV = (gl_TextureMatrix[@decalMapUV] * gl_MultiTexCoord@decalMapUV).xy;
#endif
#if @emissiveMap
emissiveMapUV = (gl_TextureMatrix[@emissiveMapUV] * gl_MultiTexCoord@emissiveMapUV).xy;
#endif

Loading…
Cancel
Save