Terrain Problem
-
- Posts: 15
- Joined: Sat Mar 08, 2008 3:15 pm
- Location: Shanghai
Terrain Problem
I want to known how to blend different textures on each material's edge. There's many source code on Internet. But they are three or four texture types blend by pixel shader. I mean how can I blend any number of textures on each texture's edge.
The effect like this:
[img]http://www.azure.com.cn/uploads/200802/ ... scene4.jpg
[/img]
The effect like this:
[img]http://www.azure.com.cn/uploads/200802/ ... scene4.jpg
[/img]
Re: Terrain Problem
please show me what material?locosoftware wrote:I want to known how to blend different textures on each material's edge.
Can you share your url or source code? I need them too.locosoftware wrote: There's many source code on Internet. But they are three or four texture types blend by pixel shader.
-
- Posts: 15
- Joined: Sat Mar 08, 2008 3:15 pm
- Location: Shanghai
There's a good example in http://www.gameprojects.com/project/?id=8fc946fc5f with XNA Framework 2.0. But it's only support four texture blending. I want to make a terrain editor and can paint many textures on the terrain with irrlicht.
-
- Posts: 15
- Joined: Sat Mar 08, 2008 3:15 pm
- Location: Shanghai
I'm working on something very similar:
It can blend up to 32 different kinds of textures on a terrain's surface.
It can blend up to 32 different kinds of textures on a terrain's surface.
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
It's look like Terrain Texture Splatting
It's look like Terrain Texture Splatting, isn't it?:
http://irrlicht.sourceforge.net/phpBB2/ ... rain+splat
http://irrlicht.sourceforge.net/phpBB2/ ... rain+splat
I've been trying to do the texture splatting on terrain using a pixel shader but none of the details in my textures come out. It does use the blend map to determine where the textures are to be placed on the terrain, however the textures lose all of their details. For example, instead of having a dirt road that has cracks, twigs, and other detail like it does in the .jpg texture file, it just comes up as a brown color on the terrain with no detail at all. This gives my terrain a very smooth look that does not look realistic. I was wondering if anyone could tell me, why I'm losing the detail in my textures.
I add a terrain Scene Node and set the material textures and the material type with the following code:
My pixel Shader looks like this:
Any help with this would be much appreciated. Thanks!
I add a terrain Scene Node and set the material textures and the material type with the following code:
Code: Select all
scene::ITerrainSceneNode* terrain = smgr->addTerrainSceneNode(
"media/terrain-heightmap.bmp",
0, // parent node
-1, // node id
core::vector3df(0.f, 0.f, 0.f), // position
core::vector3df(0.f, 0.f, 0.f), // rotation
core::vector3df(40.0f, 4.4f, 40.0f), // scale
video::SColor ( 255, 255, 255, 255 ), // vertexColor,
5, // maxLOD
scene::ETPS_17, // patchSize
5 // smoothFactor
);
terrain->setMaterialTexture(0,driver->getTexture("media/blend_hm17.jpg")); terrain->setMaterialTexture(1,driver->getTexture("media/grass.jpg"));
terrain->setMaterialTexture(2,driver->getTexture("media/dirt.jpg"));
terrain->setMaterialTexture(3,driver->getTexture("media/stone.jpg"));
s32 newMaterialType = driver->getGPUProgrammingServices()->addHighLevelShaderMaterialFromFiles( 0,0,video::EVST_VS_2_0,"TerrainPS.psh","ps_main",video::EPST_PS_2_0,0video::EMT_SOLID);
terrain->setMaterialType((video::E_MATERIAL_TYPE)newMaterialType);
Code: Select all
float4x4 matViewProjection : ViewProjection;
float texScale = 10.0;
sampler AlphaMap = sampler_state
{
MinFilter = LINEAR;
MagFilter = LINEAR;
MipFilter = LINEAR;
ADDRESSU = WRAP;
ADDRESSV = WRAP;
ADDRESSW = WRAP;
};
sampler TextureOne = sampler_state
{
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
ADDRESSU = WRAP;
ADDRESSV = WRAP;
ADDRESSW = WRAP;
};
sampler TextureTwo = sampler_state
{
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
ADDRESSU = WRAP;
ADDRESSV = WRAP;
ADDRESSW = WRAP;
};
sampler TextureThree = sampler_state
{
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
ADDRESSU = WRAP;
ADDRESSV = WRAP;
ADDRESSW = WRAP;
};
struct PS_OUTPUT
{
float4 diffuse : COLOR0;
};
PS_OUTPUT ps_main(float shade : TEXCOORD0,
float2 tiledTexC : TEXCOORD1,
float2 nonTiledTexC : TEXCOORD0) : COLOR
{
PS_OUTPUT output = (PS_OUTPUT)0;
// Layer maps are tiled
float3 c0 = tex2D(TextureOne, mul(tiledTexC,texScale));
float3 c1 = tex2D(TextureTwo, mul(tiledTexC,texScale));
float3 c2 = tex2D(TextureThree, mul(tiledTexC,texScale));
// Blendmap is not tiled.
float3 B = tex2D(AlphaMap, nonTiledTexC);
// Find the inverse of all the blend weights so that we can
// scale the total color to the range [0, 1].
float totalInverse = 1.0f / (B.r + B.g + B.b);
c0 *= B.r * totalInverse;
c1 *= B.g * totalInverse;
c2 *= B.b * totalInverse;
float3 final = (c0 + c1 + c2);//* shade;
output.diffuse = float4(final,1.0f);
return output;
}
technique Default_DirectX_Effect
{
pass Pass_0
{
PixelShader = compile ps_2_0 ps_main();
}
}
Both of those can only combine 3 or 4 texture types on a terrain surface. Mine can theoretically do up to 256 different textures (But doing that much would cost quality/performance, the recommended amount is 8-32).
Cheers
@KTrain: You need to scale your texture coordinates, try setting texScale to a higher number.
Cheers
@KTrain: You need to scale your texture coordinates, try setting texScale to a higher number.
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
Lets see your vertex shader, I bet your not setting the second set of texcoords correctly.
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
Okay here's my vertex shader:
Hope this helps. Thanks!
Code: Select all
float4x4 matViewProjection : ViewProjection;
float texScale = 100.0;
uniform extern float2 gTexScale;
uniform extern float3 gDirToSunW; // Assumed to be unit length.
sampler AlphaMap = sampler_state
{
ADDRESSU = WRAP;
ADDRESSV = WRAP;
ADDRESSW = WRAP;
};
sampler TextureOne = sampler_state
{
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
ADDRESSU = WRAP;
ADDRESSV = WRAP;
ADDRESSW = WRAP;
};
sampler TextureTwo = sampler_state
{
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
ADDRESSU = WRAP;
ADDRESSV = WRAP;
ADDRESSW = WRAP;
};
sampler TextureThree = sampler_state
{
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
ADDRESSU = WRAP;
ADDRESSV = WRAP;
ADDRESSW = WRAP;
};
struct VS_OUTPUT
{
float4 Position : POSITION0;
float2 alphamap : TEXCOORD0;
float2 tex : TEXCOORD1;
float2 nonTex : TEXCOORD2;
};
VS_OUTPUT vs_main( float4 posL : POSITION0,
float3 normalL: NORMAL0,
float2 tiledTexC : TEXCOORD1,
float2 nonTiledTexC : TEXCOORD2,
float2 alpha : TEXCOORD0)
{
VS_OUTPUT Output = (VS_OUTPUT)0;
Output.alphamap = alpha;
// Project position homogeneous clip space.
Output.Position = mul(posL, matViewProjection);
// Scale tiled tex-coords.
Output.tex.x = tiledTexC.x * texScale;
Output.tex.y = tiledTexC.y * texScale;
// Forward non-tiled tex-coords to pixel shader.
Output.nonTex = nonTiledTexC;
return( Output );
}
technique Default_DirectX_Effect
{
pass Pass_0
{
VertexShader = compile vs_2_0 vs_main();
}
}
-
- Posts: 15
- Joined: Sat Mar 08, 2008 3:15 pm
- Location: Shanghai
Yes! This effect is exactly I want. But I didn't figure out how to implement it.BlindSide wrote:I'm working on something very similar:
It can blend up to 32 different kinds of textures on a terrain's surface.
May you share your solution with Irrlicht engine?
Last edited by locosoftware on Wed Mar 26, 2008 6:47 am, edited 1 time in total.
-
- Posts: 15
- Joined: Sat Mar 08, 2008 3:15 pm
- Location: Shanghai
-
- Posts: 15
- Joined: Sat Mar 08, 2008 3:15 pm
- Location: Shanghai
I found same article:
http://www.gamedev.net/reference/articl ... le2238.asp
http://www.cbloom.com/3d/techdocs/splatting.txt
And I'll try it.
http://www.gamedev.net/reference/articl ... le2238.asp
http://www.cbloom.com/3d/techdocs/splatting.txt
And I'll try it.