fixed function blendops for snow tex on ground tex?

Started by
2 comments, last by Norman Barrows 10 years, 7 months ago

anyone remember fixed function blend ops?

anyone any good with them?

in the past i resorted to writing my own 10 channel weighted texture blender because i couldn't seem to get the desired result (4 way weighted blending) with blendops.

i'm now faced with the challenge of drawing snow on the ground in Caveman (openworld rpg/person sim - fps interface).

in the previous version, i used a pre-blended 50-50 snow texture for each regular ground texture, and a single 100% snow texture.

but this time around, there are more types of terrain, and each type now has 4 seamless tiled textures (for the moment, may add more) instead of just one base texture that got mirrored in x and z to reduce moire`. so lots more textures to make a "half snow" version of.

obviously, variable alpha blending of a 100% snow texture would be ideal, but probably too much of a performance hit. basically drawing two complete ground meshes, the regular one, and a variably translucent snow one just above it.

on the other end of the scale, pre-blended textures would be fastest,but would be limited to the % blends done ahead of time, and memory could become a factor if a large number of textures was required.

i need a low overhead way to do this. so i was thinikng maybe a two stage blendop might not be so bad. and i'd only need one texture instead of pre-blending dozens.

any blendops come to mind? are they fast? i really can't afford anything like a true multipass algo.

Norm Barrows

Rockland Software Productions

"Building PC games since 1989"

rocklandsoftware.net

PLAY CAVEMAN NOW!

http://rocklandsoftware.net/beta.php

Advertisement

Which API are you using? D3D9?


Which API are you using? D3D9?

yep. 9.0c.

any ideas? any hope for something like a quick single pass two stage blend op?

Norm Barrows

Rockland Software Productions

"Building PC games since 1989"

rocklandsoftware.net

PLAY CAVEMAN NOW!

http://rocklandsoftware.net/beta.php

SOLVED

default blendops are as follows:

stage 0:

colorop: modulate arg1 texture arg2: diffuse

alphaop: select 1 arg1 texture/diffuse arg2: current (diffuse is used if no texture is set)

uses uv coordinate set 0

stages 1 through 7:

colorop: disable arg1: texture arg2: current

alphaop: disable arg1: texture/diffuse arg2: current (diffuse is used if no texture is set)

stages 1-7 use uv coordinate sets 1-7 respectively.

the blendop desired is blend factor alpha, which blends between two textures based on the value of a d3d color (the alpha channel most likely) passed to the system.

NOTE:

1. stage 1 uses uv set 1. unless you have two sets of uv's in your vertex data, you need to set stage 1 to use uv set 0. otherwise d3d uses 0.0f for all uv coords for stage 1.

this results in a blend to the color of the UL pixel of the second texture.

2. setting the texture for stage 1 increases the reference count on the texture used. you must set the texture in stage 1 to NULL when done, to decrement the reference count again.

here's the code to turn on and off snow blending:

 
 
void turnon_snowblending()
{
int i;
float f;
D3DCOLOR color;
f=snow_accumulation;        // calc blend factor.....
f*=255.0f;
if (f > 255.0f) f=255.0f;
i=(int)f;
color=D3DCOLOR_RGBA(i,i,i,i);
Zd3d_device_ptr->SetRenderState(D3DRS_TEXTUREFACTOR,color);          // set blend factor.....
Zd3d_device_ptr->SetTexture(1,Ztex[341].tex);        // TEX 341          // set the snow texture.....
Zd3d_device_ptr->SetTextureStageState(1,D3DTSS_COLOROP,D3DTOP_BLENDFACTORALPHA);     // tell it to blend
//Zd3d_device_ptr->SetTextureStageState(1,D3DTSS_COLORARG1,D3DTA_TEXTURE);                        // these commented out lines aren't required
///Zd3d_device_ptr->SetTextureStageState(1,D3DTSS_COLORARG2,D3DTA_CURRENT);                      // the arg values are the same as the default current sttings
//Zd3d_device_ptr->SetTextureStageState(1,D3DTSS_ALPHAOP,D3DTOP_BLENDFACTORALPHA);   // this apparently doesn't need to be turned on.
//Zd3d_device_ptr->SetTextureStageState(1,D3DTSS_ALPHAARG1,D3DTA_TEXTURE);
//Zd3d_device_ptr->SetTextureStageState(1,D3DTSS_ALPHAARG2,D3DTA_CURRENT);
Zd3d_device_ptr->SetTextureStageState(1,D3DTSS_TEXCOORDINDEX,0);              // use uv set 0, there is no uv set 1, so it uses 0.0 for all uv's!
}
 
 
 
 
 
 
 
 
void turnoff_snowblending()
{
//D3DCOLOR color;                                                  
 // again, commented out lines are not required. you know how d3d is - sometimes you have to try a few things until you get the right combo.
// texturefactor doesn't need to be reset, because snow blending is the only place its used.
//color=D3DCOLOR_RGBA(255,255,255,255);
Zd3d_device_ptr->SetTexture(1,NULL);            // set tex to null to decrement reference to snow tex
Zd3d_device_ptr->SetTextureStageState(1,D3DTSS_COLOROP,D3DTOP_DISABLE);     // turn off blending
//Zd3d_device_ptr->SetRenderState(D3DRS_TEXTUREFACTOR,color);
}
 
 

Norm Barrows

Rockland Software Productions

"Building PC games since 1989"

rocklandsoftware.net

PLAY CAVEMAN NOW!

http://rocklandsoftware.net/beta.php

This topic is closed to new replies.

Advertisement