Adjusting Reflection - Cube Maps (OMG SCREEN SHOTS!!!)

Started by
4 comments, last by Namethatnobodyelsetook 18 years, 8 months ago
Hey All, I just got enviroment maps working in DX9 with the FFP, so I'm pretty excited about that. However, hit a bit of a snag when it comes to adjusting the reflectiveness of the enviroment map: meaning I can't figure out how. I thought I could do it by basing the blend arguments on the alpha component of the material, but that leads to problems because then the whole object becomes transparent. Another option I thought of was changing the alpha values of the actual cube texture but: a) I don't actually know how to make cube texture files yet (just using a .dds from another project) b) I would like to be able to change the reflection amount in real time. Any suggestions would be great. If you need to see any code, let me know! And here is a screen shot, simply cause it gets me more views :) Don't hate the playah, hate the game. Matt Hughson [Edited by - matthughson on August 27, 2005 4:48:57 PM]
__________________________________[ Website ] [ Résumé ] [ [email=contact[at]matthughson[dot]com]Contact[/email] ][ Have I been Helpful? Hook me up! ]
Advertisement
bump.
__________________________________[ Website ] [ Résumé ] [ [email=contact[at]matthughson[dot]com]Contact[/email] ][ Have I been Helpful? Hook me up! ]
You should be able to use the alpha in the material, (or TFACTOR, or the per stage CONSTANT). Since you don't need alphablending enabled to mix colors in texture stages, make sure you turn it off. That's what's making your entire object transparent, and it's making your draw slower too.

In these case you need to change your texture stage states. The easiest way to blend between diffuse and reflection would be D3DTOP_BLENDxALPHA (x can be DIFFUSE, CURRENT, FACTOR). So your setup would be like this:

material.Diffuse.A = blendingpercent;
or
pDev->SetRenderState(D3DRS_TEXTUREFACTOR, ((long)(blendingpercent*255))<<25);

then

// Diffuse texture * lighting
pDev->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
pDev->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
pDev->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
// and get an alpha
pDev->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
pDev->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE);

// Blend between reflection and lit diffuse
pDev->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_BLENDCURRENTALPHA);
pDev->SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
pDev->SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT);
// and get an alpha
pDev->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
pDev->SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE);

// End
pDev->SetTextureStageState(2, D3DTSS_COLOROP, D3DTOP_DISABLE);
pDev->SetTextureStageState(2, D3DTSS_ALPHAOP, D3DTOP_DISABLE);

Other common options would be adding reflection, where stage 1 setup is:
colorop=multiplyadd
colorarg0=current
colorarg1=texture
colorarg2=current | alphareplicate
(note args may be in wrong order. The docs refer to args1-3, while code refers to 1,2, and then 0). I'm assuming you want to multiply the cube texture by the reflectivity (current alpha), then add to the current color.
Nothing to add about the problem (i've only implemented this with shaders) - but if you want to make your own cubemaps simply use the DirectX Texture Tool (utilities/DxTex.exe) which comes with the SDK - its pretty self explanatory.
Quote:Original post by Namethatnobodyelsetook
You should be able to use the alpha in the material, (or TFACTOR, or the per stage CONSTANT). Since you don't need alphablending enabled to mix colors in texture stages, make sure you turn it off. That's what's making your entire object transparent, and it's making your draw slower too.


Yeah, the problem is that I use the alpha component of the diffuse material to fade out objects (something I want to be able to do). So if I use the alpha component as the reflection amount as well, I can't turn down the reflectivness without fading out the object as a whole.

That make sense? Can you think of a way around it? I haven't had a chance yet, but I will compare your code you posted with my own later today and see what I can find. Thanks!

Quote:Original post by Source
Nothing to add about the problem (i've only implemented this with shaders) - but if you want to make your own cubemaps simply use the DirectX Texture Tool (utilities/DxTex.exe) which comes with the SDK - its pretty self explanatory.


Yeah, I actually took a couple minutes yesterday and figured that out. Thanks for the help though!

Matt Hughson
__________________________________[ Website ] [ Résumé ] [ [email=contact[at]matthughson[dot]com]Contact[/email] ][ Have I been Helpful? Hook me up! ]
You'll just need a second source of alpha. TFACTOR should be fine. If you're using the blending method, just use BLENDFACTORALPHA.

If you use the multiplyadd method, put the cube in stage 0, multiplied by TFACTOR. Set the alpha op to anything (selectarg1 diffuse for example)
In stage 1, put your diffuse texture, multiplyadd such that you get texture*diffuse+current, and set the alpha op to fetch the alpha you want for blending (selectarg1 diffuse, or modulate diffuse, texture if your texture has alpha too)

This topic is closed to new replies.

Advertisement