📄 mapsplatter.cpp
字号:
i++;
SplatMap_index_pixel0 += SplatMapbpp0;
if ((i % SplatMapWidth0) == 0)
SplatMap_index_pixel0 -= SplatMapWidth0*SplatMapbpp0;
SplatMap_index_pixel1 += SplatMapbpp1;
if ((i % SplatMapWidth1) == 0)
SplatMap_index_pixel1 -= SplatMapWidth1*SplatMapbpp1;
SplatMap_index_pixel2 += SplatMapbpp2;
if ((i % SplatMapWidth2) == 0)
SplatMap_index_pixel2 -= SplatMapWidth2*SplatMapbpp2;
SplatMap_index_pixel3 += SplatMapbpp3;
if ((i % SplatMapWidth3) == 0)
SplatMap_index_pixel3 -= SplatMapWidth3*SplatMapbpp3;
}
j++;
SplatMap_index_pixel0 = (j % SplatMapHeight0) * SplatMapWidth0 * SplatMapbpp0;
SplatMap_index_pixel1 = (j % SplatMapHeight1) * SplatMapWidth1 * SplatMapbpp1;
SplatMap_index_pixel2 = (j % SplatMapHeight2) * SplatMapWidth2 * SplatMapbpp2;
SplatMap_index_pixel3 = (j % SplatMapHeight3) * SplatMapWidth3 * SplatMapbpp3;
}
// use bAlphaNotUsed to change coverage from 4 channel to less...
std::cout << "\n";
mAlreadyComputed = true;
}
//-----------------------------------------------------------------------
void MapSplatter::BuildPoint(ColourValue& out, int x, int z, Real& alpha1,
Real& alpha2, Real& alpha3, Real& alpha4)
{
// Init the colour
alpha1 = 0.0f;
alpha2 = 0.0f;
alpha3 = 0.0f;
alpha4 = 0.0f;
#ifndef _NORMALSLOPE
//The sloppy test
{
Vector3 Normal = MapUtil::getSingleton().getNormalAt (x, z);
Real Slope = std::max (Math::Abs (Normal.x),
Math::Abs (Normal.z)) / 2.0f;
Real height = MapUtil::getSingleton().getHeight (x, z);
// from http://www.tayloredmktg.com/rgb/
const ColourValue Sand (1.0f, 1.0f, 0.0f);
const ColourValue Grass (0.13f,0.545f,0.13f);
//const ColourValue Rock (0.7450f, 0.745f, 0.745f);
const ColourValue Rock (0.411764f, 0.411764f, 0.411764f);
const ColourValue Snow (1.0f, 0.98f, 0.98f);
if ( height < matHeight[0] )
{
// sand - grass interpolation
Real interpol = height / matHeight[0];
alpha1 = (1.0f - interpol);
alpha2 = interpol;
out = Sand * alpha1 + Grass * alpha2;
}
else if ( height < matHeight[1] )// && Height >=matHeight[0]
{
// grass - rock interpolation
Real interpol = (height - matHeight[0])/ (matHeight[1] - matHeight[0]);
alpha2 = (1.0f - interpol);
alpha3 = interpol;
out = Grass * alpha2 + Rock * alpha3;
}
else //Height >=matHeight[1]
{
// rock - snow interpolation
Real interpol = (height - matHeight[1])/ (MapUtil::getSingleton().getMaxTheoHeight () - matHeight[1]);
alpha3 = (1.0f - interpol);
alpha4 = interpol;
out = Rock * alpha3 + Snow * alpha4;
}
// color - rock interpolation
out = out * (1.0f - Slope) + Rock * Slope;
if (alpha3 + Slope < 1.0f)
alpha3 += Slope;
else
alpha3 = 1.0f;
}
#else //_NORMALSLOPE
#define SNOW 0
#define SAND 1
#define GRASS 2
#define ROCK 3
// Ask for the current height value and the 8 surrounding values
Real height[9];
if ( x == 0 )
{
x = 1;
}
else if (x == int (mWidth))
{
x = mWidth - 1;
}
if ( z == 0 )
{
z = 1;
}
else if (z == int (mHeight))
{
z = mHeight - 1;
}
// /*
// h1
// h0*---*---*h2
// |0 /|2 /|
// | / | / |
// |/ 1|/ 3|
// h3*---h4--*h5
// |7 /|4 /|
// | / | / |
// |/ 6|/ 5|
// h6*---*--*h8
// h7
// */
height[0] = MapUtil::getSingleton().getHeight( x - 1, z - 1 ); // Top-Left
height[1] = MapUtil::getSingleton().getHeight( x, z - 1 ); // Top-Center
height[2] = MapUtil::getSingleton().getHeight( x + 1, z - 1 ); // Top-Right
height[3] = MapUtil::getSingleton().getHeight( x - 1, z ); // Left
height[4] = MapUtil::getSingleton().getHeight( x, z ); // Current Point
height[5] = MapUtil::getSingleton().getHeight( x + 1, z ); // Right
height[6] = MapUtil::getSingleton().getHeight( x - 1, z + 1 ); // Bottom-Left
height[7] = MapUtil::getSingleton().getHeight( x, z + 1 ); // Bottom-Center
height[8] = MapUtil::getSingleton().getHeight( x + 1, z + 1 ); // Bottom-Right
// Weight( pt1 , pt2 ) = 1 - DistanceSquared(pt1,pt2) / (1.75)^2
//The sloppy test
Real dx = 1.0f / PagingLandScapeOptions::getSingleton().scale.x;
Real dz = 1.0f / PagingLandScapeOptions::getSingleton().scale.z;
Real dxdz = dx + dz;
Real sloppy[8];
sloppy[0] = Math::Abs ( height[0] - height[4] ) * dxdz;
sloppy[1] = Math::Abs ( height[1] - height[4] ) * dz;
sloppy[2] = Math::Abs ( height[2] - height[4] ) * dxdz;
sloppy[3] = Math::Abs ( height[3] - height[4] ) * dx;
sloppy[4] = Math::Abs ( height[5] - height[4] ) * dx;
sloppy[5] = Math::Abs ( height[6] - height[4] ) * dxdz;
sloppy[6] = Math::Abs ( height[7] - height[4] ) * dz;
sloppy[7] = Math::Abs ( height[8] - height[4] ) * dxdz;
out = ColourValue(0.0f, 0.0f, 0.0f, 0.0f);
for ( uint i = 0; i < 7; i++ )
{
if ( height[i] < matHeight[0] )
{
if ( sloppy[i] < 0.2f )
{
// grass-grass
InterpolateColour( out, 1.0f, GRASS, GRASS );
InterpolateAlpha( alpha1, alpha2, alpha3, alpha4, 1.0f, GRASS, GRASS );
}
if ( sloppy[i] >= 0.15f && sloppy[i] < 0.4f )
{
// sand-grass
InterpolateColour( out, 0.25f, SAND, GRASS );
InterpolateAlpha( alpha1, alpha2, alpha3, alpha4, 0.25f, SAND, GRASS );
}
if ( sloppy[i] >= 0.3f && sloppy[i] < 0.65f )
{
// sand-sand
InterpolateColour( out, 1.0f, SAND, SAND );
InterpolateAlpha( alpha1, alpha2, alpha3, alpha4, 1.0f, SAND, SAND );
}
if ( sloppy[i] >= 0.55f && sloppy[i] < 0.75f )
{
// sand-rock
InterpolateColour( out, 0.75f, SAND, ROCK );
InterpolateAlpha( alpha1, alpha2, alpha3, alpha4, 0.75f, SAND, ROCK );
}
if ( sloppy[i] >= 0.70 )
{
// rock-rock
InterpolateColour( out, 1.0, ROCK, ROCK );
InterpolateAlpha( alpha1, alpha2, alpha3, alpha4, 1.0f, ROCK, ROCK );
}
}
else if ( height[i] < matHeight[1] )
{
if ( sloppy[i] < 0.15 )
{
// grass-snow
InterpolateColour( out, 0.25f, GRASS, SNOW );
InterpolateAlpha( alpha1, alpha2, alpha3, alpha4, 0.25f, GRASS, SNOW );
}
if ( sloppy[i] >= 0.10 && sloppy[i] < 0.45 )
{
// snow-sand
InterpolateColour( out, 0.65f, SNOW, SAND );
InterpolateAlpha( alpha1, alpha2, alpha3, alpha4, 0.65f, SNOW, SAND );
}
if ( sloppy[i] >= 0.25f && sloppy[i] < 0.65f )
{
// snow-rock
InterpolateColour( out, 0.5, SNOW, ROCK );
InterpolateAlpha( alpha1, alpha2, alpha3, alpha4, 0.5f, SNOW, ROCK );
}
if ( sloppy[i] >= 0.50f && sloppy[i] < 0.75f )
{
// snow-rock
InterpolateColour( out, 0.75f, SNOW, ROCK );
InterpolateAlpha( alpha1, alpha2, alpha3, alpha4, 0.75f, SNOW, ROCK );
}
if ( sloppy[i] >= 0.70 )
{
// rock-rock
InterpolateColour( out, 1.0f, ROCK, ROCK );
InterpolateAlpha( alpha1, alpha2, alpha3, alpha4, 1.0f, ROCK, ROCK );
}
}
else
{
if ( sloppy[i] < 0.15f )
{
// snow-snow
InterpolateColour( out, 1.0f, SNOW, SNOW );
InterpolateAlpha( alpha1, alpha2, alpha3, alpha4, 1.0f, 0, 0 );
}
if ( sloppy[i] >= 0.1f && sloppy[i] < 0.45f )
{
// snow-sand
InterpolateColour( out, 0.35f, SNOW, SAND );
InterpolateAlpha( alpha1, alpha2, alpha3, alpha4, 0.35f, 0, 1 );
}
if ( sloppy[i] >= 0.25f && sloppy[i] < 0.65f )
{
// snow-rock
InterpolateColour( out, 0.5f, SNOW, ROCK );
InterpolateAlpha( alpha1, alpha2, alpha3, alpha4, 0.5f, 0, 3 );
}
if ( sloppy[i] >= 0.5f && sloppy[i] < 0.75f )
{
// snow-rock
InterpolateColour( out, 0.75f, SNOW, ROCK );
InterpolateAlpha( alpha1, alpha2, alpha3, alpha4, 0.75f, 0, 3 );
}
if ( sloppy[i] >= 0.7f )
{
// rock-rock
InterpolateColour( out, 1.0f, ROCK, ROCK );
InterpolateAlpha( alpha1, alpha2, alpha3, alpha4, 1.0f, 3, 3 );
}
}
}
#endif //_NORMALSLOPE
}
//-----------------------------------------------------------------------
void MapSplatter::InterpolateColour(ColourValue& out, const Real percentaje,
const int index1, const int index2)
{
Real tmp = 1 - percentaje;
if (percentaje < 1.0)
{
out.r = ( out.r + ( percentaje * matColor[index1].r + tmp * matColor[index2].r ) ) * 0.5f;
out.g = ( out.g + ( percentaje * matColor[index1].g + tmp * matColor[index2].g ) ) * 0.5f;
out.b = ( out.b + ( percentaje * matColor[index1].b + tmp * matColor[index2].b ) ) * 0.5f;
}
else if (index1 == index2)
{
out.r = matColor[index1].r;
out.g = matColor[index1].g;
out.b = matColor[index1].b;
}
}
//-----------------------------------------------------------------------
void MapSplatter::InterpolateAlpha(Real& alpha1, Real& alpha2, Real& alpha3,
Real& alpha4, const Real percentaje,
const int index1, const int index2)
{
if ( index1 == index2 )
{
if ( index1 == 0 )
{
alpha1 += 1.0;
}
else if ( index1 == 1 )
{
alpha2 += 1.0;
}
else if ( index1 == 2 )
{
alpha3 += 1.0;
}
else
{
alpha4 += 1.0;
}
}
else
{
if ( index2 == 0 )
{
alpha1 += percentaje;
}
else if ( index2 == 1 )
{
alpha2 += percentaje;
}
else if ( index2 == 2 )
{
alpha3 += percentaje;
}
else
{
alpha4 += percentaje;
}
if ( index1 == 0 )
{
alpha1 += 1.0 - percentaje;
}
else if ( index1 == 1 )
{
alpha2 += 1.0 - percentaje;
}
else if ( index1 == 2 )
{
alpha3 += 1.0 - percentaje;
}
else
{
alpha4 += 1.0 - percentaje;
}
}
//snow = 0
//sand = 1
//grass = 2
//rock = 3
alpha1 *= ( 4.0 * 0.2f);
alpha2 *= ( 3.0 * 0.2f);
alpha3 *= ( 4.0 * 0.2f);
alpha4 *= ( 2.0 * 0.2f);
// Normalize
Real total = 1.0f / ( alpha1 + alpha2 + alpha3 + alpha4 ) * 2.0;
alpha1 = alpha1 * total;
alpha2 = alpha2 * total;
alpha3 = alpha3 * total;
alpha4 = alpha4 * total;
}
}//namespace Ogre
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -