Skip to main content
GameDev.net gamedev.net
🔒 Locked

Texture blending problem

Started by MasterWorks Jul 8, 2004 at 1:13 AM 5 replies 2.9k views
Original Post
MasterWorks
MasterWorks
Hi, I've got a situation where I need to render the Earth's clouds on a sphere using transparency (since, obviously, the land/ocean were rendered beneath). I have no problems using a PNG file with transparency to do this. BUT, the interesting thing is that the PNG file is pure white in the RGB channels and only contains information in the alpha channel. So, what I would like to do is extract the alpha channel and save it as a grayscale JPG file. This would save significant space by letting me use lossy compression -- this is a large texture! I do NOT want to load a JPG file and then transfer its contents into the alpha channel of an otherwise empty (solid color) 32-bit texture. Is there some relatively easy way I can set the render states to instruct Direct3D to "draw white, but using to control the alpha of this white"? I'd really like to know how to do it for ANY color, not just white. Any advice? I have been using the standard D3DRS_SRCBLEND, D3DBLEND_SRCALPHA D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA combination to this point (except when using additive blend). Thanks! -Jay
Trip99
Trip99
I am not sure how to do this but have you tried using the MFCTex sample that comes with the SDK? It allows you to mess with all the blending states in 3 stages - dead useful.
------------------------See my games programming site at: www.toymaker.info
S1CA
S1CA
1) Use D3DFMT_A8 format (alpha only) for the texture. If your hardware supports it of course (use CheckDeviceFormat()).

2) In your SetTextureStageState() set up, use the D3DTA_ALPHAREPLICATE modifier to copy the alpha information into the R,G,B channels. Assuming your hardware supports it of course (check the caps).

3a) use a framebuffer blend of ONE:INVSRCALPHA

3b) The maths behind the blend:
- SRCALPHA:INVSRCALPHA = a*SRCrgb + (1-a)*DSTrgb
- if SRCrgb is WHITE = a*1,1,1 + (1-a)*DSTrgb
- so copying "a" into SRCrgb (alphareplicate), with ONE:INVSRCALPHA we get: a + (1-a)*DSTrgb

4) For white you could alternatively use the TFACTOR/TEXTUREFACTOR
Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site
BlueChip
BlueChip
D3DFMT_A8 format is not supported by DX...

from SDK
Quote:

Note that DXTex does not currently support textures with surface formats that do not contain at least an R, G, and B texture (such as D3DFMT_G16R16 and D3DFMT_A8), although D3DX can load and save such textures in DDS format.


byezzz
Namethatnobodyelsetook
Namethatnobodyelsetook
The only 8 bit format supported by nVidia DX9 drivers (on a GeForce 3) is L8. Using a shader and blue replicate you can get what you want. nVidia's DX8 drivers (on a GeForce3) support P8 which you can set to be r=g=b=a=index to get the effects of A8 L8 or AL8. In DX9 you can use A8L8, which will waste 8 bits, but won't require a shader to get your effect.

S1CA
S1CA
oops - that was me above - forgot to sign in and you can't edit/delete posts made as an AP bah [smile]
Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.