Change Alpha Color Without Recreating Polygon

Started by
1 comment, last by Psychopathetica 7 years ago

I found an awesome method to create a sphere polygon with normals, as well as texture coordinates for tu and tv, but I severely modified it to support changing its color / alpha as well and made it my own thing. That way I don't have to resort to using D3DXCreateSphere() which doesnt support texture coords. Works great, but I wanted to fade from one sphere into another, similar to fading from day sky to night sky. Is there a way to change alpha values of a color without recreating the entire object every frame with the new colors? Note I'm not using HLSL, and just DirectX9 and C++. Thanks.

Advertisement

If you wish to change all vertices of your sphere to the same alpha colour, you can do something with SetTextureStageState calls, but it's such a long time since I've done this style of programming that I would need to spend some time working out the correct calls.

However, what it sounds like you really want to do is interpolate between a "day" texture and a "night" texture, so it will be much simpler if you just draw a single sphere with two textures and D3DTOP_LERP - again, use a bunch of SetTextureStageState calls.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

I'll look into using some SetTextureStageState calls but I think it's messed up that after all these years, I've been setting colors and alphas to polygons upon its creation for years. And all this time if I ever needed to change anything, it involved SetTextureStageState's this whole time. Now alls I gotta do is figure out the right states.

[EDIT]

I fixed it after finding a similar post on gamedev:

DWORD AlphaValue;
AlphaValue = D3DCOLOR_ARGB(100,255,255,255);

mpDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
mpDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
mpDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
mpDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
mpDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);

mpDevice->SetTextureStageState(0, D3DTSS_CONSTANT, AlphaValue);
mpDevice->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_CONSTANT);
mpDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
mpDevice->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);

works like a charm and you can dynamically change the alphas WITHOUT recreating the polygons

This topic is closed to new replies.

Advertisement