DirectX Greyscale that works

BlitzMax Forums/BlitzMax Beginners Area/DirectX Greyscale that works

TartanTangerine (was Indiepath)(Posted 2006) [#1]
This should work on all cards.

I'm going to put it in the Render 2 Texture Module.

'If you want more physically correct luminance (the eye is more receptive to some colour 
'components than others), the REC709 coefficients (For average PC monitor) are r=0.2125, 
'g=0.7154, b=0.0721. Converted To the TEXTUREFACTOR constant (multiply by 255 And convert To Hex) 
'it's: 0x0036B612 [since you have to round some of the coefficients, you lose some precision - 
'really the r,g,b parts of the constant should add up To 255 so I'd an extra 1 to the blue.

' Source Color Default is the Red Channel.


Function SetMono(state:Byte=True,dwFactor:Int = $0036B612,SourceCol:Int=$FF0000)
	If State
		SetColor((SourceCol Shr 16) & $FF,(SourceCol Shr 8) & $FF,SourceCol & $FF)
		PrimaryDevice.device.SetRenderState(D3DRS_TEXTUREFACTOR, dwFactor)
  		PrimaryDevice.device.SetTextureStageState(1, D3DTSS_COLOROP,D3DTOP_DOTPRODUCT3)
  		PrimaryDevice.device.SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE) 
  		PrimaryDevice.device.SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_TFACTOR)  
	Else
		PrimaryDevice.device.SetRenderState(D3DRS_TEXTUREFACTOR, $FFFFFFFF ) 
  		PrimaryDevice.device.SetTextureStageState(1,D3DTSS_COLOROP,D3DTOP_MODULATE)  
		PrimaryDevice.device.SetTextureStageState(1,D3DTSS_COLORARG1,D3DTA_TEXTURE)
		PrimaryDevice.device.SetTextureStageState(1,D3DTSS_COLORARG2,D3DTA_DIFFUSE)
		SetColor 255,255,255
	EndIf
End Function



TartanTangerine (was Indiepath)(Posted 2006) [#2]
Can someone convert this to OGL?


xlsior(Posted 2006) [#3]
OK... This converts the entire pic by default to shades of red, at least for me... Can it also do the B&W?

(Tweaking the SourceCol field will make the picture red, green of blue tinted, or a combination of the above... But not monochrome?)

ATI Radeon 9600 Pro


TartanTangerine (was Indiepath)(Posted 2006) [#4]
This :

Gives :



Bremer(Posted 2006) [#5]


Thats how it looks on both my computers, one with onboard gfx, the other with n6600GT.


TartanTangerine (was Indiepath)(Posted 2006) [#6]
Lol Crazy Man!

I've tested on

- Windows XP nVidia FX5200
- Windows XP nVidia GForce 3D thingie (crap old card)
- Windows 98 Matrox G400

And it works!


tonyg(Posted 2006) [#7]
I get the same as Zawran on my W2K S3 laptop.


xlsior(Posted 2006) [#8]
Same here:



Radeon 9600 Pro


Yan(Posted 2006) [#9]
I get the same as xlsior and zawran here.

If I use 'D3DTA_CURRENT', as per Mr O'Conner's original post, I end up with an inverted greyscale image.


Grisu(Posted 2006) [#10]
Doesn't work for a x850xt-pe as well. See Zawran.


hub(Posted 2006) [#11]
Doesn't work on radeon 9200, winxp ! same as zawran.


TartanTangerine (was Indiepath)(Posted 2006) [#12]
I'm gonna check under the hood and make sure I did not change anything there :)


TartanTangerine (was Indiepath)(Posted 2006) [#13]
I rebuilt BMAX from scratch and I still get Greyscale!!!


TartanTangerine (was Indiepath)(Posted 2006) [#14]
I had an idea... Change all the "1"'s to "0"'s

PrimaryDevice.device.SetTextureStageState(1, D3DTSS_COLOROP,D3DTOP_DOTPRODUCT3)

Change to :
PrimaryDevice.device.SetTextureStageState(0, D3DTSS_COLOROP,D3DTOP_DOTPRODUCT3)[/code]


xlsior(Posted 2006) [#15]
If I change the 1's to 0's, it gets green-shaded instead:



Any non-zero value I tried returns the same half-bright image, both positive and negative numbers.

When using 0, I notice the following: if I change the dwFactor to a different value, it affects the shade of the color directly: e.g. $00B63612 will give it a red hue, $000000FF will make it blue, etc... Using $00777777 for the dwFactor will make it full color, half-bright as well... I tseems like it is taking the RGB rather than luminecense?


tonyg(Posted 2006) [#16]
Same on my S3 but it all works fine on my 9800Pro


Bremer(Posted 2006) [#17]
Its green-shaded on both an onboard SiS 661FX and a n6600GT.


Grisu(Posted 2006) [#18]
(still) doesn't work here...


TartanTangerine (was Indiepath)(Posted 2006) [#19]
Nah, you guys are winding me up. This has worked on every machine I have tested on.


TartanTangerine (was Indiepath)(Posted 2006) [#20]
Nah, you guys are winding me up. This has worked on every machine I have tested on.


xlsior(Posted 2006) [#21]
the odd thing is that a wide range of cards all seem to misbehave in the same way - different manufacturers, chipset, etc.
Yet others apparently are OK.

Could there be any other factors, such as DirectX revision that play a role here? I'm using DX9c myself (of course that doesn't reaslly narrow it down either, considering that there are multiple different releases of that as well)


Space_guy(Posted 2006) [#22]
Mm. i wish there was alil 2xmodulate blend mode in there somewhere :) that would have been swell


TartanTangerine (was Indiepath)(Posted 2006) [#23]
:) Oh you people, you'll want blood next.


Rimmsy(Posted 2006) [#24]
we want the moon on a stick.

Not to sound rude but have you done anything on the OpenGL version of the texturedPoly lib? I get an "unhandled exception:Attempt to access field or method of Null object" when trying to run your example code in OpenGL. Works fine as a cake in DX.


TartanTangerine (was Indiepath)(Posted 2006) [#25]
Yeah I have fixed that rimmsy but not released it.


Yan(Posted 2006) [#26]
To rule out any module meddling, I've re-installed 1.16 and I'm getting the same thing.

I do have the latest version of DX9c (Dec 2005) and DXDiag reports it as being version 4.09.0000.0904, If that helps any.


tonyg(Posted 2006) [#27]
I have DX9.0c on my Radeon 9800Pro where this works and 9.0b on the S3 that doesn't.


TartanTangerine (was Indiepath)(Posted 2006) [#28]
This is crazy!

It works on some version of DX9 and not others! This is DX7 Code!


TartanTangerine (was Indiepath)(Posted 2006) [#29]
MODULATE2X
PrimaryDevice.device.SetTextureStageState(0, D3DTSS_COLOROP,D3DTOP_MODULATE2X)

MODULATE4X
PrimaryDevice.device.SetTextureStageState(0, D3DTSS_COLOROP,D3DTOP_MODULATE4X)

NormalMode
PrimaryDevice.device.SetTextureStageState(0, D3DTSS_COLOROP,D3DTOP_MODULATE)



tonyg(Posted 2006) [#30]
MOD2X and MOD4X work nice.


Space_guy(Posted 2006) [#31]
Thank you for the effort im trying arround with the Modulate Modes but im just wondering how to use it the way that it was used in blitz3d. i mean that it wont erase whats behind. Just multiply so darker gets darker and lighter lighter. Its just what i need. can someone aim me in the right direction?


Grisu(Posted 2006) [#32]
"latest version of DX9c (Dec 2005)"

Ahm, I use directx9.0c (Feb 2006)... :P

MS seems to hate version numbers lately... ;)


Yan(Posted 2006) [#33]
Take it up with Microsoft...

http://www.microsoft.com/windows/directx/default.aspx