Terrain specular mapping: use a "_diffusespec" postfix to indicate specular information is present in the alpha channel. Use alpha directly instead of 1-alpha.

actorid
scrawl 11 years ago
parent d01f89b153
commit c64dc2c831

@ -281,6 +281,7 @@ namespace Terrain
// normal map (optional)
bool useNormalMap = mNormalMapping && !mLayerList[layerOffset+i].mNormalMap.empty() && !renderCompositeMap;
bool useParallax = useNormalMap && mParallaxMapping && layer.mParallax;
bool useSpecular = layer.mSpecular;
if (useNormalMap)
{
anyNormalMaps = true;
@ -292,6 +293,8 @@ namespace Terrain
sh::makeProperty (new sh::BooleanValue(useNormalMap)));
p->mShaderProperties.setProperty ("use_parallax_" + Ogre::StringConverter::toString(i),
sh::makeProperty (new sh::BooleanValue(useParallax)));
p->mShaderProperties.setProperty ("use_specular_" + Ogre::StringConverter::toString(i),
sh::makeProperty (new sh::BooleanValue(useSpecular)));
boost::hash_combine(normalMaps, useNormalMap);
boost::hash_combine(normalMaps, useNormalMap && layer.mParallax);

@ -475,6 +475,7 @@ namespace Terrain
LayerInfo info;
info.mParallax = false;
info.mSpecular = false;
info.mDiffuseMap = "textures\\" + texture;
std::string texture_ = texture;
boost::replace_last(texture_, ".", "_nh.");
@ -491,6 +492,14 @@ namespace Terrain
info.mNormalMap = "textures\\" + texture_;
}
texture_ = texture;
boost::replace_last(texture_, ".", "_diffusespec.");
if (Ogre::ResourceGroupManager::getSingleton().resourceExistsInAnyGroup("textures\\" + texture_))
{
info.mDiffuseMap = "textures\\" + texture_;
info.mSpecular = true;
}
mLayerInfoMap[texture] = info;
return info;

@ -16,6 +16,7 @@ namespace Terrain
std::string mDiffuseMap;
std::string mNormalMap;
bool mParallax; // Height info in normal map alpha channel?
bool mSpecular; // Specular info in diffuse map alpha channel?
};
/// We keep storage of terrain data abstract here since we need different implementations for game and editor

@ -337,6 +337,7 @@ float2 blendUV = (UV - 0.5) * (16.0 / (16.0+1.0)) + 0.5;
float2 layerUV = float2(UV.x, 1.f-UV.y) * 16; // Reverse Y, required to get proper tangents
float2 thisLayerUV;
float4 normalTex;
float4 diffuseTex;
float3 eyeDir = normalize(cameraPos.xyz - worldPos);
#if PARALLAX
@ -358,19 +359,18 @@ float2 blendUV = (UV - 0.5) * (16.0 / (16.0+1.0)) + 0.5;
thisLayerUV += TSeyeDir.xy * ( normalTex.a * PARALLAX_SCALE + PARALLAX_BIAS );
#endif
#if IS_FIRST_PASS
#if @shIterator == 0
// first layer of first pass is the base layer and doesn't need a blend map
albedo = shSample(diffuseMap0, layerUV);
#else
albedo = shLerp(albedo, shSample(diffuseMap@shIterator, thisLayerUV), blendValues@shPropertyString(blendmap_component_@shIterator));
#endif
diffuseTex = shSample(diffuseMap@shIterator, layerUV);
#if !@shPropertyBool(use_specular_@shIterator)
diffuseTex.a = 0;
#endif
#if @shIterator == 0
albedo = diffuseTex;
#else
#if @shIterator == 0
albedo = shSample(diffuseMap@shIterator, layerUV);
#else
albedo = shLerp(albedo, shSample(diffuseMap@shIterator, thisLayerUV), blendValues@shPropertyString(blendmap_component_@shIterator));
#endif
albedo = shLerp(albedo, diffuseTex, blendValues@shPropertyString(blendmap_component_@shIterator));
#endif
#if !IS_FIRST_PASS
previousAlpha *= 1.f-blendValues@shPropertyString(blendmap_component_@shIterator);
#endif
@ -448,7 +448,7 @@ float2 blendUV = (UV - 0.5) * (16.0 / (16.0+1.0)) + 0.5;
float3 halfVec = normalize (light0Dir + eyeDir);
float3 specular = pow(max(dot(normal, halfVec), 0), 32) * lightSpec0;
shOutputColour(0).xyz += specular * (1.f-albedo.a) * shadow;
shOutputColour(0).xyz += specular * (albedo.a) * shadow;
#endif
#if FOG

Loading…
Cancel
Save