Archived

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

flareman

How can I render to grayscale w/ DX8.0? - nt-

Recommended Posts

there is probably a simple algorithm that you can use at run time to change textures to grayscale, not sure about speed, but if its like a "switch" type of thing, it wont be that bad, you do it once and they are all grayscale, no prob. but if you need to switch back and forth, speed will be an issue.

--Fireking

Owner/Leader
Genetics 3rd Dimension Development

Share this post


Link to post
Share on other sites
I''m sure I answered this old question when it first came up

D3DRS_TEXTUREFACTOR = 0xFF4C961D

At the end of the texture blend cascade:
D3DTSS_COLORARG1 = D3DTA_CURRENT
D3DTSS_COLOROP = D3DTOP_DOTPRODUCT3
D3DTSS_COLORARG2 = D3DTA_TFACTOR


The weightings I''ve used are the NTSC ones (rather than CRT) and are quantised so not 100% correct, but fine for the "effect".



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

Share this post


Link to post
Share on other sites
Uhhh... you did? in any case, thx for taking the trouble to re-post

yep, I just want that "de-colorization" for effect (as in, wow, a flashback, etc ), so I guess it will do

gonna go and try it
if I have any more questions i''ll come back w/ them

thanks again!
flare

-----------<<>>-----------
Ga1adaN, Primus ante Adein
flareman@freemail.gr
-----------<<>>------------

Share this post


Link to post
Share on other sites
And to add to what S1CA said, that could be applied to each texture when rendering or to the whole scene after it has been rendered in color. Applying it to the whole scene would require you to render your whole scene to a renderable texture and using the code snipplets from S1CA render the texture to the back buffer. This would allow you to modify the colors of non-textured objects such as filled polygons and lines and also if you wanted achieve without much work effects like fading from color to grayscale and motion blur sinse you're already rendering to a seperate texture. Just an idea...

---
Brent Gunning | My Site

[edited by - RapidStunna on November 3, 2002 1:14:10 PM]

Share this post


Link to post
Share on other sites
So there isn''t a way to "command" dx to render to b&w? That''s bad, cause I tried S1CA''s code (thanks again, anyway!), and it didn''t work (something which didn''t take me as much of a surprise, as the gfx engine is being built for a 2d rpg game, and it uses ID3DXSprite8 blitting, lines, no-texture polygons mainly - to be truthful, only the particles are fully textured polygons in their natural sense). In any case, how do glayscale-ize the entire rendering? (I''d appreciate some detailed instructions on how to render to another surface, etc etc etc, as I''m not in for a heavy deal of researching - I''ve gotten rather PO by the subject and am close to ditching it entirely

Hey, help me out here!
Flare

-----------<<>>-----------
Ga1adaN, Primus ante Adein
flareman@freemail.gr
-----------<<>>------------

Share this post


Link to post
Share on other sites
Yeah, the idea occured to me as well, but I have two arguments against it: first, inefficient (from many aspects - not only because the essential texture volume is doubled, but because not all is tile-based in my engine), second because I might want to render whole scenes under a tinted color, which may not necessarily be shades of gray - e.g. yellow tinting (like Locke''s memories in FF6, etc.)

So, back to our subject

-----------<<>>-----------
Ga1adaN, Primus ante Adein
flareman@freemail.gr
-----------<<>>------------

Share this post


Link to post
Share on other sites
To render all the scene as greyscale:

for(UINT y=0; y{
for(UINT x=0; x {
char Luminance;
char newR, newG, newB;
char oldR, oldG, oldB;
..... //Get the old RGB of the current pixel
Luminance = (oldR+oldG+oldB)/3;
newR = newG = newB = Luminance;
}
}

Hope this helps

Kamikaze

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Why not using a pixel shader like this ?

ps.1.1
def c0, 0.30, 0.59, 0.11, 0.0 ; luminance
dp3 r0, v0, c0

Share this post


Link to post
Share on other sites