Jump to content
  • Advertisement
Sign in to follow this  
The Parrot

Texturing / Alpha / Pixelshader

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

Hi, I'm currently working on an adventure-game (ref: the recent Myst IV) and I'm a bit stuck on a problem. In my background I want moving skies and the like, so I render out my scenes with an alpha mask to allow a moving background. Yet since I save my images as .jpg to save (disk)space (pre-rendered games get so terribly large), I have no way to save alpha in the same file. 2 things I have tried are either copying data from the Alpha-file to the rgb-texture on load time, thus making it a rgba texture, or using a simple pixel shader where I use 2 different textures, the RGB and the Alpha, to be combined at rendertime. Now, the 2nd method appears best to me, as it's proven to be faster as the first (terrible load times with the first, due to the locking/unlocking/etc. The real question is: what method is best - or is there a better solution? Additionaly, are pixelshaders v1.1 supported widely enough to use them (I presume they are, but I must admit I don't know for sure)?.. Looking forward for your input, thanks for reading.

Share this post


Link to post
Share on other sites
Advertisement
I would think it's safe to assume that the majority of gamers are running cards which at least support ps_v1_1, but there will still be those users out there that don't, and therefore you should implement some sort of software soultion to compensate for that. While it may be slower, I'm assuming any game designed using DirectX 9.0 running on a TNT2 or Geforce 1 are going to run slow as it is.

The major question you should ask is whether you'd prefer to support absolutely every type of hardware configuration out there, or created a realistic set of minimum requirements, and if the user doesn't meet it then it's either time to upgrade or find something else. I've taken the road with my engine if the user's device does not support v1_1 then I do have a software fallback but it is slow as all hell but it's a knock I'm willing to take for more advanced features in my engine.

Permafried-

Share this post


Link to post
Share on other sites
Quote:
Original post by The Parrot
Yet since I save my images as .jpg to save (disk)space (pre-rendered games get so terribly large), I have no way to save alpha in the same file.

Try PNGs. They support alpha, and compress well.

Quote:
2 things I have tried are either copying data from the Alpha-file to the rgb-texture on load time, thus making it a rgba texture, or using a simple pixel shader where I use 2 different textures, the RGB and the Alpha, to be combined at rendertime.

I believe you can do it without any pixel shaders, using some texture stage state magic. Basically, put the texture in stage 0, and the alpha texture in stage 1. Then do:
device->SetTextureStageState(0, D3DTSS_COLOROP, D3DTSS_SELECTARG1);
device->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
device->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTSS_SELECTARG1);
device->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_CURRENT);

device->SetTextureStageState(1, D3DTSS_COLOROP, D3DTSS_SELECTARG1);
// If the alpha texture has white color info (0xaaffffff), you can replace
// TFACTOR with TEXTURE. Otherwise you can set TFACTOR to 0xffffffff
// Also, if vertices have no diffuse, you could say DIFFUSE
// which would result in 0xffffffff
device->SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TFACTOR);
device->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTSS_SELECTARG1);
device->SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);

device->SetTextureStageState(2, D3DTSS_COLOROP, D3DTOP_DISABLE);
device->SetTextureStageState(2, D3DTSS_ALPHAOP, D3DTOP_DISABLE);

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!