Sign in to follow this  
MasterWorks

Texture blending problem

Recommended Posts

MasterWorks    496
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 <cloudTexture> 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

Share this post


Link to post
Share on other sites
Trip99    577
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.

Share this post


Link to post
Share on other sites
S1CA    1418
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

Share this post


Link to post
Share on other sites
BlueChip    100
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
Quote:
Original post by 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


Quote:
Note that **DXTex** does not currently support...


i.e. that's talking about the DirectX Texture Tool which is used for manipulating *.DDS files. You can still create the file as one format and load as another format. DirectX itself DOES indeed support D3DFMT_A8 [smile].

However as Namethatnobodyelsetook points out, some graphics cards/drivers don't support that format (thus the "If your hardware supports it of course (use CheckDeviceFormat())." part of my original post [smile]). The Radeon 9800 does support D3DFMT_A8, the GeForce 3 doesn't for example.


If you only have a luminance texture format (e.g. D3DFMT_L8) available on your target hardware and don't want to use shaders, you could alternatively achieve the same result by:

1) use D3DFMT_L8 or some other colour only format.

2) omit the D3DTA_ALPHAREPLICATE stuff, and indeed the whole alpha part of the pipeline.

3) use a ONE:INVSRCCOLOR blend mode (the fact that the colour you're after is white is very useful :o)


Share this post


Link to post
Share on other sites
S1CA    1418
oops - that was me above - forgot to sign in and you can't edit/delete posts made as an AP bah [smile]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this