Texturing / Alpha / Pixelshader

Started by
1 comment, last by Muhammad Haggag 19 years, 1 month ago
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.
--Jeroen Stout - WebsiteCreator of-Divided
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-
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);

This topic is closed to new replies.

Advertisement