Advertisement Jump to content


This topic is now archived and is closed to further replies.

C Coder

Texture blending in 3d landscapes

This topic is 5395 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi Im using alpha blending to try and blend my textures ie SAND, GRASS, ROCK etc etc... Now the problem I can blend say SAND + GRASS or GRASS & ROCK etc etc but if I want to use SAND GRASS & ROCK on my planet then the SAND & GRASS blend lovely but the rock just appears blocky and crap! (doesnt blen from grass to rock very well!) hmm that doesnt explain it very well but hopefullly u guys know what I mean!!

Share this post

Link to post
Share on other sites
how about some pieces of code

btw do you use single pass texturing or multipass

sounds like you didn t setup you register combiners correctly

this a Cg shader from my old engine, but i skipped it cause my gf4 ti doesn t support enough operations, i had to hack a few things to get it to work

can t wait for the nv45 cards, finally some decent hardware to go on with my engine
float3 main(float2 co0 : TEXCOORD0,
float2 co1: TEXCOORD1,
float2 co2: TEXCOORD2,
float2 co3: TEXCOORD3,
float4 blend : COLOR0,
uniform sampler2D aunit0 : TEXUNIT0,
uniform sampler2D aunit1 : TEXUNIT1,
uniform sampler2D aunit2 : TEXUNIT2,
uniform sampler2D aunit3 : TEXUNIT3): COLOR
float3 col0 = tex2D(aunit0, co0).rgb;//base
float3 col1 = tex2D(aunit1, co1).rgb;//grass
float3 col2 = tex2D(aunit2, co2).rgb;//rock
float3 col3 = tex2D(aunit3, co3).rgb;//sand
float3 final=col1*blend.r+col0*(blend.a);
return final;


Share this post

Link to post
Share on other sites
thx, Im using a single pass using multitexturing.

this is my setup for the blending...

lpDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
lpDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
lpDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, FALSE );
lpDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG2 );
lpDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE );

lpDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_BLENDDIFFUSEALPHA );
lpDevice->SetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE );
lpDevice->SetTextureStageState( 1, D3DTSS_COLORARG2, D3DTA_CURRENT );
lpDevice->SetTextureStageState( 1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
lpDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 );

lpDevice->SetTextureStageState( 2, D3DTSS_COLOROP, D3DTOP_MODULATE );
lpDevice->SetTextureStageState( 2, D3DTSS_COLORARG1, D3DTA_DIFFUSE );
lpDevice->SetTextureStageState( 2, D3DTSS_COLORARG2, D3DTA_CURRENT );


problem is when I want more than two textures on my landscape!

Im setting the vertex alpha value depending on height, and also changing the two textures im using depend on the


height 0-100 = texture SAND & GRASS; alpha blended 0-1 (0=SAND, 1=GRASS)

height 100-200 = texture grass to rock...
height 200-300 = rock to snow... ect etc...

I then set the alpha values at each vertex to belnd between the relavant two textures!


Share this post

Link to post
Share on other sites
Consider using 3D textures. Use the texture-w-coordinate to blend between the different texture types.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!