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

This commit is contained in:
scrawl 2014-01-11 00:51:03 +01:00
parent d01f89b153
commit c64dc2c831
4 changed files with 26 additions and 13 deletions

View file

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

View file

@ -475,6 +475,7 @@ namespace Terrain
LayerInfo info; LayerInfo info;
info.mParallax = false; info.mParallax = false;
info.mSpecular = false;
info.mDiffuseMap = "textures\\" + texture; info.mDiffuseMap = "textures\\" + texture;
std::string texture_ = texture; std::string texture_ = texture;
boost::replace_last(texture_, ".", "_nh."); boost::replace_last(texture_, ".", "_nh.");
@ -491,6 +492,14 @@ namespace Terrain
info.mNormalMap = "textures\\" + texture_; 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; mLayerInfoMap[texture] = info;
return info; return info;

View file

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

View file

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