Sign in to follow this  

DX TextureStageStates

Recommended Posts

Lord_Taren    130
I am having trouble figuring out all of the TextureStageStates and how they work. Does anyone know of a good tutorial or guide that goes into detail on what each one does and how they work in conjunction I figured out how to add a detail texture to my terrain, buy beyond that I am quite lost. Here's how I did the detail texture: dxDevice.setTextureStage(0, TextureStageStates.ColorArgument1, (int)TextureArgument.TextureColor); dxDevice.setTextureStage(0, TextureStageStates.ColorOperation, (int)TextureOperation.SelectArg1); dxDevice.setTextureStage(1, TextureStageStates.ColorArgument1, (int)TextureArgument.Current); dxDevice.setTextureStage(1, TextureStageStates.ColorArgument2, (int)TextureArgument.TextureColor); dxDevice.setTextureStage(1, TextureStageStates.ColorOperation, (int)TextureOperation.AddSigned); I'm not even 100% clear on how this works. Any help would be appreciated. Thanks.

Share this post

Link to post
Share on other sites
Texture stage states are like a program (almost exactly pixel shader 1.1). First stage 0 runs, then stage 1, then stage 2, until a stage set to disable is found. Think of the stages as line numbers. On each stage you have two operations, one for color, and one for alpha, and you must always specify both.

One commands need only 1 argument, such as SELECTARG1, or SELECTARG2.

color = arg1
color = arg2

Some commands need two arguments, such as MODULATE or ADD

color = arg1 * arg2
color = arg1 + arg2

Some commands require 3 arguments, such as lerp or multiplyadd. The documentation and SDK disagree a bit here, one calling arguments 1, 2, and 3, the other calling them 0, 1, and 2. I can never remember if 3 is 0, or if 1 is 0, and 2 is 1, and 3 is 2.

You can also specify modifiers to some arguments, such as ALPHAREPLICATE, which will take the alpha of the source and treat it as a grey level, or COMPLEMENT which inverts the color. You can combine the two, effectively saying color = (1-arg1.alpha).

A stage may also write to a temporary output, then refer to that temporary value later, via D3DTSS_RESULTARG (write to "current" or "temp") and D3DTA_TEMP (read temp).

For simplicity (because I don't feel like looking up if addsigned treats both arguments as signed), I'll pretend your example just used add in stage 1. It translates to this:

color.rgb = texture.rgb;
color.rgb = color.rgb + texture.rgb;

or more correctly, it translates to this:

color.rgb = texture.rgb;
color.a = (whatever was last set, or the default, you really should specify something)

color.rgb = color.rgb + texture.rgb;
color.a = (whatever was last set, or the default, you really should specify something. The default is disabled, which is invalid as you have a color op.)

Stage 2 is probably set to disabled by default, but you really should set that too, otherwise more operations may continue to occur.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this