Jump to content
  • Advertisement


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


This topic is 5823 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

Hellow My understanding of this code(three lines below) is that we want to select a color operation, the operation is a modulation where we multiply argument1 by argument2. Argument 1 is the color of this texture stage, and argument2 is the result of previous blending stage. However I do not understand what "this stage" means, what "previous blending stage" means nor I understand what the code is trying to acomplish. Can some one be patient and explain this in boring details? 1-SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE); 2-SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE); 3-SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_CURRENT); Well I said "boring" but I well settle for any reply, I can be greedy later. Best regards If love is illusion and hate is real, I would rather be crazy

Share this post

Link to post
Share on other sites
The first thing you should do is read up on the multi-texture cascade in the documentation which comes with the SDK:

DirectX 8.1 (C++) ->
DirectX Graphics ->
Programmers Guide ->
Using Direct3D ->
Textures ->
Texture Blending

Over simplified view:

The application of textures and colours to pixels of a rendered polygon happens in the pixel processing pipeline .

Each pixel in a polygon which is about to be rendered starts at one end of the pipeline, at the other end of the pipeline the pixel is output for display.

In between the start and end of this pipeline comes up to 8 "stages" where "processing" happens on the colour and alpha values of the pixel. These stages are sequentially linked - the idea is you pass the output of stage 0 as one input of stage 1, the output of stage 1 as the input of stage 2 and so on.

In the standard setup, each stage has 2 inputs (arguments - ARG1, ARG2), and an "operation". The result of the operation at the stage goes into "D3DTA_CURRENT" (if you''ve ever done any 8bit assembler or CPU theory you can think of CURRENT as being like the accumulator).

In reality, there are actually TWO pipelines, one for the RGB colour values (aka "the vector pipe") and one for alpha channel values (aka "the scalar pipe", in most situations you can control each pipe totally independently of the other.

At each stage along the pipeline, one of the inputs/arguments for that stage can be a texture map. To get the colour or alpha value for that input, the 3D hardware "samples" the texture depending on the texture coordinates of the vertices of the current polygon (which get interpolated across the polygon).

When sampling the texture, the hardware can also filter it on a per stage basis.

As well as textures, the per vertex colours DIFFUSE and SPECULAR(after interpolation) can be used as inputs. Often the colours in those values will have come from D3D lighting, but can also come from other sources (depending on the other states you''ve set up). There are other possible inputs too - read the documentation to discover them.

At stage 0, "CURRENT" doesn''t really have a sensible meaning as an input since it represents the current output value of the blending stage. For this reason if you use CURRENT as an input to stage 0, D3D/the driver will use DIFFUSE instead.

If you want to use an analogy, think of a water treatment plant:

Water comes in dirty at the start of the "pipe", and comes out clean and (alledgedly ) drinkable at the other end. The water always flows in one direction.

Between the start and end of its journey, the water goes through a number of processing "stages". At each stage, filtering happens, chemicals are mixed in with the current water, sometimes other things such as heating occur at the same time as the chemicals are mixed in.

Finally an example (think of this sequentially a stage at a time). Imagine we''re using D3D lighting:

[D3DTA_CURRENT is undefined at this point in the pipe]

A pixel from the texture set for this stage is sampled and the value is put into ARG1. The diffuse lighting value for the current pixel of the polygon is in DIFFUSE, this value is put into ARG2.

The output of stage 0 (D3DTA_CURRENT) is the texture pixel modulated (multiply) with the diffuse colour value.

If we only had one stage active in the pipeline, the value in D3DTA_CURRENT would be the colour drawn onto the screen. However we''ll do another:


In this case, ARG1 is the colour from sampled from the texture set for stage **1** (i.e. if required it can be a *different* texture than the one set for stage 0). ARG2 is set to CURRENT and so the value which comes into ARG2 is the **OUTPUT** from stage0.

The operation in this case is an addition, this adds the second texture to the current colour from the first.

Written (pseudo) mathematically (note the parenthesis):

RenderedPixel = (Texture1 * DiffuseLight) + Texture2

Now the gotcha:
Although the pipeline theoretically has 8 stages, the number you can use simultaneously, the number of textures you can assign and the operations you can apply are limited by the capabilities of your target 3D hardware.

Simon O''Connor
Creative Asylum Ltd

Share this post

Link to post
Share on other sites
This defenatly will save me tones of hours


If love is illusion and hate is real, I would rather be crazy

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!