Archived

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

Is there something possible with D3D !?!

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

My goal is to render textured and Gouraud-shaded triangles, with a second transparent texture applied to it. It''s the most basic way to simulate reflection of the environment on textured and lit triangles. The process must be done in ONE pass. My vertex format used contains diffuse color and 2 sets of textures coordinates (s0,t0) and (s1,t1). The current engine params are :
    
lpD3DDev->SetRenderState(D3DRENDERSTATE_COLORKEYENABLE,FALSE); 
lpD3DDev->SetRenderState(D3DRENDERSTATE_COLORKEYBLENDENABLE,FALSE);

lpD3DDev->SetRenderState(D3DRENDERSTATE_SRCBLEND,D3DBLEND_SRCALPHA);
lpD3DDev->SetRenderState(D3DRENDERSTATE_DESTBLEND,D3DBLEND_INVSRCALPHA);
lpD3DDev->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE,TRUE);

lpD3DDev->SetTextureStageState(0,D3DTSS_TEXCOORDINDEX,0);
lpD3DDev->SetTextureStageState(1,D3DTSS_TEXCOORDINDEX,1);

lpD3DDev->SetTexture(0,lpObjectTexture);
lpD3DDev->SetTexture(1,lpEnvironmentTexture);
[/source]


I don''t use special effects like trilinear filtering, or other.

Here are color and alpha combinaison to achieve my desired effect :

[source] 
lpD3DDev->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_MODULATE);
lpD3DDev->SetTextureStageState(0,D3DTSS_COLORARG1,D3DTA_TEXTURE);
lpD3DDev->SetTextureStageState(0,D3DTSS_COLORARG2,D3DTA_DIFFUSE);
lpD3DDev->SetTextureStageState(1,D3DTSS_COLOROP,D3DTOP_BLENDTEXTUREALPHA);
lpD3DDev->SetTextureStageState(1,D3DTSS_COLORARG1,D3DTA_TEXTURE);
lpD3DDev->SetTextureStageState(1,D3DTSS_COLORARG2,D3DTA_CURRENT);

lpD3DDev->SetTextureStageState(0,D3DTSS_ALPHAOP,D3DTOP_SELECTARG1);
lpD3DDev->SetTextureStageState(0,D3DTSS_ALPHAARG1,D3DTA_TEXTURE);
lpD3DDev->SetTextureStageState(1,D3DTSS_ALPHAOP,D3DTOP_MODULATE);
lpD3DDev->SetTextureStageState(1,D3DTSS_ALPHAARG1,D3DTA_DIFFUSE);
lpD3DDev->SetTextureStageState(1,D3DTSS_ALPHAARG2,D3DTA_CURRENT);
    
And the result is multitextured triangles with both textures, but WITHOUT DIFFUSE COLOR effect. In other words my triangles aren''t lit : diffuse color is ignored. And a call to lpD3DDev->ValidateDevice(&dwPasses) tells me this combinaison is not supported ! How could 3DFX forgot such a simple combinaison on it''s voodoo3, the board I own ? And I managed to make this effect in a single pass in my Glide3X engine ( I work on porting it to D3D ). I also have lastest drivers and lastest DirectX7 SDK. Tests make me think the problem is in color combinaison ( and not alpha ), and even using D3DTOP_MODULATE instead of D3DTOP_BLENDTEXTUREALPHA doesn''t work better... But what stroke me are these words in DirectX help ( in ValidateDevice topic ) : "Using diffuse iterated values, either as an argument or as an operation (D3DTA_DIFFUSE or D3DTOP_BLENDDIFFUSEALPHA) is rarely supported on current hardware. Most hardware can only introduce iterated color data at the LAST texture operation stage." But then what''s the use of texture stages when diffuse color can only be used in the last texture stage : with D3DTA_DIFFUSE as first parameter and D3DTA_CURRENT as second, where can texture colors be used ?!? Please show me I''m wrong, or I will finish by making a Glide-only game !

Share this post


Link to post
Share on other sites
All of you are OpenGl coders ?
It''s a real problem, I didn''t manage to answer myself...
Please again...
Did you use the same combinaison to achieve the same effect, or is there another way which is better ?...

Share this post


Link to post
Share on other sites
Maybe if you supply the code for how you did it in Glide?

Anyway, I looked at the texture states that you are using and it looks as if you are doing some unnecessary things. From what I understand you don't want the whole surface to be transparent, only the reflection.

I think that you should be able to get this effect like this:

        
lpD3DDev->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_MODULATE);
lpD3DDev->SetTextureStageState(0,D3DTSS_COLORARG1,D3DTA_TEXTURE);
lpD3DDev->SetTextureStageState(0,D3DTSS_COLORARG2,D3DTA_DIFFUSE);
lpD3DDev->SetTextureStageState(0,D3DTSS_ALPHAOP,D3DTOP_DISABLE);


lpD3DDev->SetTextureStageState(1,D3DTSS_COLOROP,D3DTOP_BLENDTEXTUREALPHA);
lpD3DDev->SetTextureStageState(1,D3DTSS_COLORARG1,D3DTA_TEXTURE);
lpD3DDev->SetTextureStageState(1,D3DTSS_COLORARG2,D3DTA_CURRENT);
lpD3DDev->SetTextureStageState(1,D3DTSS_ALPHAOP,D3DTOP_DISABLE);


I haven't tested this but I think it should work. If it doesn't then I need to do some testing at home. I'm certain that if it can be done in Glide it can also be done in D3D.

Also, from your comments about what the SDK Docs says it sounds as if it is possible to introduce the diffuse color in a third texture stage (without texture):

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


- WitchLord

Edited by - WitchLord on July 18, 2000 7:20:40 AM

Share this post


Link to post
Share on other sites
If you are interested in, there is my combinaison in Glide :

    
grTexCombine( GR_TMU0, GR_COMBINE_FUNCTION_BLEND, GR_COMBINE_FACTOR_OTHER_ALPHA, GR_COMBINE_FUNCTION_LOCAL, GR_COMBINE_FACTOR_ONE, FXFALSE, FXFALSE );

grTexCombine( GR_TMU1, GR_COMBINE_FUNCTION_LOCAL, GR_COMBINE_FACTOR_NONE, GR_COMBINE_FUNCTION_LOCAL, GR_COMBINE_FACTOR_ONE, FXFALSE, FXFALSE );

grAlphaCombine(GR_COMBINE_FUNCTION_SCALE_OTHER, GR_COMBINE_FACTOR_LOCAL, GR_COMBINE_LOCAL_ITERATED, GR_COMBINE_OTHER_TEXTURE, FXFALSE );

grColorCombine(GR_COMBINE_FUNCTION_SCALE_OTHER, GR_COMBINE_FACTOR_LOCAL, GR_COMBINE_LOCAL_ITERATED, GR_COMBINE_OTHER_TEXTURE, FXFALSE );


Sure that my alpha combinaison wasn''t needed to achieve the mentioned effect, but I would like to keep active vertex alpha and primary alpha.
In my game, any object can be tranparent ( they disappear slowly when they hide the player ), and reflexion is just added as an option.
In fact, with this color combinaison, there is no relationship with alpha combinaison, then removing it with the DISABLE operation don''t change anything, except the loss of vertex and first texture alpha...

BUT your idea of using the third texture stage to get diffuse color works perfectly : the result is nearly ( if not ) identical to glide rendering !
I didn''t think about it because for me "new texture stage = new pass" ( certainly because I began with Glide and its TMUs... ). Then for a device that don''t accept more than 2 textures for a simgle pass, I wouldn''t use more than 2 stages...
But recent tests motived by your remark made me understand better texture stages... thank you !

( but the fact that my first combinaison isn''t supported by my voodoo3 still appears strange to me : have you heard of a particular rule about combinaisons in multiple texture stages, or a detailed tutorial about it ? )

Share this post


Link to post
Share on other sites
If I remember my Glide correctly then the Direct3D code you are using now should do exactly the same thing as you Glide code, thus producing the same result.

This is what happens in you Glide code:


1. TMU1 uses the texture color with no modification
2. TMU0 blends texture color with color from TMU1 using alpha from TMU1
3. Color from TMU0 is modulated with iterated color
Alpha from TMU0 is modulated with iterated alpha


So this is exactly what is happening in the D3D code.

It seems that the Voodoo brand can only multiply iterated color with textures at the very last stage (grColorCombine()).

And no, unfortunately I haven''t seen any such tutorial. I have no interest in writing any either because it would require knowledge about all the major 3D accelerators and how the do their colorcombinations.


- WitchLord

Share this post


Link to post
Share on other sites