Archived

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

C Coder

SetTextureStageState ALPHA BLENDS?

Recommended Posts

C Coder    122
Anyone know what I should be setting these to. I want to have 2 textures (for now!) one say grass the other say rock. Using the diffuse alpha value at each vertex I want the two textures to go from grass to rock! final texture = (grass * 1-alpha) + (rock * alpha); ok, below is what I came up with, but this just does this:- final texture = grass * (rock * alpha); ... // TEST OPS lpDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE ); lpDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); lpDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE ); lpDevice->SetTextureStageState(1,D3DTSS_COLOROP, D3DTOP_BLENDDIFFUSEALPHA ); lpDevice->SetTextureStageState(1,D3DTSS_COLORARG1, D3DTA_TEXTURE ); lpDevice->SetTextureStageState(1,D3DTSS_COLORARG2, D3DTA_CURRENT ); // END TEST OPS ... how can I fix this? any ideas! thx.

Share this post


Link to post
Share on other sites
quote:
Original post by C Coder
final texture = (grass * 1-alpha) + (rock * alpha);

ok, below is what I came up with, but this just does this:-

final texture = grass * (rock * alpha);



It does blend correctly, and not as you describe. The SDK says so, quite clearly. The entry for BLENDDIFFUSEALPHA says:
Srgba = ARG1 x (Alpha) + ARG22 x (1 - Alpha)

The only thing I can see wrong is that you''re modulating diffuse color before the blend, such that one texture is affected by light, and the other is not.

Share this post


Link to post
Share on other sites
C Coder    122
Yes you are right it is blending correctly! Just didnt look right because my alpha values were not ranging from 0.0f - 1.0f, they were 0.0f to (i dont know!) 0.5f or something! therefor it didnt look right!

thanks anyway!

I now have three textures sand,grass,rock blending between them ok - ish!

Im using alpha values again 0.0-0.5 for sand to grass and then 0.5 - 1.0 for rock (scaling up to 0-1 values) and just changing the texture set im using!

Im sure there must be a better way! any ideas!

some code...

where c1-c4 are height values 0-255

ic1 = 255; // temp test variable to alter diffuse value!

GLOBAL_land_vert[vert_count+0].diffuse = RGB(ic1,ic1,ic1) + ((c1-128)*2 * 0x01000000);
GLOBAL_land_vert[vert_count+1].diffuse = RGB(ic1,ic1,ic1) + ((c2-128)*2 * 0x01000000);
GLOBAL_land_vert[vert_count+2].diffuse = RGB(ic1,ic1,ic1) + ((c3-128)*2 * 0x01000000);
GLOBAL_land_vert[vert_count+3].diffuse = RGB(ic1,ic1,ic1) + ((c4-128)*2 * 0x01000000);

if ( (c1<128) | (c2<128) | (c3<128) | (c4<128) )
{
GLOBAL_land_vert[vert_count+0].diffuse = RGB(ic1,ic1,ic1) + (c1*2 * 0x01000000);
GLOBAL_land_vert[vert_count+1].diffuse = RGB(ic1,ic1,ic1) + (c2*2 * 0x01000000);
GLOBAL_land_vert[vert_count+2].diffuse = RGB(ic1,ic1,ic1) + (c3*2 * 0x01000000);
GLOBAL_land_vert[vert_count+3].diffuse = RGB(ic1,ic1,ic1) + (c4*2 * 0x01000000);
lpDevice->SetTexture( 0,lpTextures[1] ); //sand
lpDevice->SetTexture( 1,lpTextures[2] ); //grass
}
else
{
lpDevice->SetTexture( 0,lpTextures[2] ); //grass
lpDevice->SetTexture( 1,lpTextures[3] ); //rock
}


ps what should that diffuse be replaced with in the texturestaging!


[edited by - C Coder on March 27, 2004 8:33:28 PM]

Share this post


Link to post
Share on other sites
Frankesk    122
I think you''d better to focus rendering at the best one triangle in which you could have a maximum of *two* textures blending toghether, using the technique described in your first post.

This happens (I suppose, dont know for sure) into a Quake3 terrain style. I know quake3 terrain because I made a terrain editor for it(easygen, you can find it with google). I was lame and I textured the terrain in the 3D preview window using multipass :| but the game engine uses another technique.

In Quake3 triangles that made up a terrain entity couldnt have more than two textures blending togheter. Three textures in a triangle caused an "error" and the traingle was not rendered. For every possibile combination of grass-rock , grass-snow, snow-rock (combinations increasing with the increase of overall texture count used) a shader was created and, eventually, applied to the triangle were a particular blend occurred.

I dont have quake3 isntalled anymore, but I have ET that uses an enanched q3 terrain engine, I post a shader it uses for a particular meeting of two textures blending. This code doesnt make sense in C++, it is a shader script interpreted by the map compiler.

textures/goldrush/lmterrain_0to1
{
q3map_baseshader textures/goldrush/lmterrain_base
{
map textures/temperate_sd/sand_bubbles_bright.tga
tcMod scale 1.75 1.75
}
{
map textures/desert_sd/pavement_quad_sandy.tga
blendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA
alphaGen vertex
tcMod scale 1.75 1.75
}
// I dont post other lightmap and detail stuff
}

Share this post


Link to post
Share on other sites
C Coder    122
"Frankest"

U miss understand I am only using 2 textures per triangle (it just that I am calculating 4 points at a time, 2 triangles!) each is then processed separatly!

Anyway it seems that I am doing the right thing, but im setting the diffuse alpha value at each vertex to determine the blend between 2 textures!

{Rock) diffuse alpha 1.0f (texture 2)
.
.
.
. diffuse alpha 0.5f (texture1 + texture 2)/2
.
.
.
(grass) diffuse alpha 0.0f (texture 1)

depending on the general height of the polygon I set Texture 1+2 to either say (SAND/GRASS) or (GRASS/ROCK) etc etc..


this DOES work but if anyone knows of a better way then please say so.

Also im doing all this in real time on a realtime generated planet the size of Earth using 3D Perlin Noise routines I made!

The idea is that U can fly from outer space down to the planets surface!

NB: The textures look realy rubbish from a far distance! (just lots of dithering dots!)

Share this post


Link to post
Share on other sites