Archived

This topic is now archived and is closed to further replies.

Tom

Direct3DTexture8 - change color to black&white?

Recommended Posts

I suspect there's a way to do this with a vertex shader. I want to add a low-light feature to my 3D game that turns the world into shades of gray. I've seen such things accomplished several times in various games on various platforms, but I hadn't thought much about how they did it. Well, now I need to think about it, and quite frankly, I'm still stumped. The problem is that I really have no clue how to use vertex shaders, because the SDK docs don't really go into that. I'd rather use a vertex shader than a pixel shader because the latter requires hardware support for acceptable performance, and the former does not. (Most of the systems running my game will have GF2's or less. I'm using a V770 Ultra for development, which is a TNT2.) Of course, this assumes that it's possible to neutralize a texture's color by changing the color of an object's vertices. That may in fact be impossible, and pixel shaders may be my only solution. In that case, I need a technique that is fast and does not require advanced hardware. Something along the lines of color correction (although that generally requires hardware support). Advice is greatly appreciated. [edited by - Tom on May 3, 2003 4:40:20 PM]

Share this post


Link to post
Share on other sites
I believe I got this from a post from S1CA:

D3DRS_TEXTUREFACTOR = 0xFF4C961D

At the end of the texture blend cascade:
D3DTSS_COLORARG1 = D3DTA_CURRENT (TEXTURE if this the only stage)
D3DTSS_COLOROP = D3DTOP_DOTPRODUCT3
D3DTSS_COLORARG2 = D3DTA_TFACTOR

You can play with the texture factor to get different effects (sepia tone, etc) too.


Stay Casual,

Ken
Drunken Hyena

Share this post


Link to post
Share on other sites


BTW: the coefficients in the TFACTOR are roughly the NTSC/YCbCr ones - a value such as 0xFF555555 (1, 1/3, 1/3, 1/3) would be less visually correct, but might be more what you''d expect.

Unfortunately though the TNT/TNT2 is now pretty old so only has two texture units and a very limited number of operations possible - from what I remember of that chip it doesn''t support the DOTPRODUCT3 operation (IIRC the 3DLabs Permedia 3 was the first to offer that support - it was later popularised by the GeForce256).

Which leaves the problem of making your scene grey scale - it''s a difficult one, all that springs to mind at the moment:

1) Special version of the textures which are already greyscale.

2) If all of your textures don''t need an alpha channel you could put a luminance value into that and then use the REPLICATEALPHA modifier in your TextureStageStates to force it into the R,G and B channels. You might even be able to find a way to propagate one of your colour channels (say the green) into the alpha and then REPLICATEALPHA to move it back (a reasonable hack).

3) Palettised textures. Change the palette.

4) TNT* specific: you might be able to use the nVidia 8 stage hack^H^H^H^H"technique" to expose the register combiners and use those to perform the dot product on the components or some approximation (e.g. two channels and change the weighting).

5) Multi-pass to perform the dot product or similar - though the TNTs being older chips might not have the fillrate to do that too heavily.

6) A combination of render to texture, the COMPLEMENT mode, ALPHAREPLICATE and multipass might just be usable (it feels like it should - just an idea - not worked it through or tested).

--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com

Share this post


Link to post
Share on other sites