Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Desaturating through code in Direct3D8?


Exception
 Share

Recommended Posts

Hey guys,

I'm currently working on a lighting system for my game, and my way of making things look realistic really depends on the ability to desaturate graphics. I'm at an impasse at that I don't actually know how I can do this through rendering in D3D8.

I've looked up various things, and I've been experimenting with various "SetTextureStageState" and "SetRenderState" arguments, but I can't find anything that works. Search engines have also been rather unhelpful, as they all provide usage for Direct3D9 or Direct3D10, and I can't find/make an equivalent use for it, from those examples.

I've also read through the rather cryptic Object Library, and feel like I've missed something.

Do you think you could help me out? I want to release the lighting when I'm done, and show how it can be used effectively, so, do help if you do know!
Link to comment
Share on other sites

Selling that too ![:P](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/tongue.png) (just kidding)

Well you need to be a lot clearer

Are you Making dynamic or static lights?

D3D Lights are good for doing dynamic lights, but for static lighting it's better to use lightmaps or vertex lighting.

personnaly I'll use both the first for players and projectiles , the second for maps

ok first i'm posting this from my phone and so from my memory, i may forget a thing or too or make some synthax errors.

Anyway for the desaturation you need to use alphablending,

i don't have your render function(neither do i know if you're rendering this in the render_screen function) so i'll assume declarations where done as they should :

the most important ones and those i remember…

With D3DDevice

'Set the shader to be used

D3DDevice.SetVertexShader FVF

'Set the render states

**.SetRenderState D3DRS_LIGHTING, True**

.SetRenderState D3DRS_SRCBLEND, D3DBLEND_SRCALPHA

.SetRenderState D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA

**.SetRenderState D3DRS_ALPHABLENDENABLE, True**

.SetTextureStageState 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE

'Set the texture stage stats (filters)

.SetTextureStageState 0, D3DTSS_MAGFILTER, D3DTEXF_POINT

.SetTextureStageState 0, D3DTSS_MINFILTER, D3DTEXF_POINT

End With

then change the alpha channel value through calculations it depends if you're using lightening per tile, vertex etc…
Link to comment
Share on other sites

Uh, the current thing I'm doing is just a tint over the picscreen, but how well the tint looks depends on being able to desaturate. The point lights, directional lights, etc, have all been done already, I'm just trying to finish it off,

I can't try that yet, as I'm on an iPad, and won't be on until later, but what difference would " .SetRenderState D3DRS_ALPHABLENDENABLE, True" make, when I'm trying to change the colour, not blend the alpha? I imagine there's a similar blending state for RGB, under COLORBLENDABLE?

(You do know what I mean by desaturating, right? There was a similar state of confusion yesterday from misunderstanding, so I just want to make sure)
Link to comment
Share on other sites

ah i get you now,

Desaturating an image works by converting an RGB triplet to an HSL triplet, then forcing the saturation to zero.

Private Const HLSMAX = 252

Private Function HueToRGB(Byval n1%,byval n2%,Byval hue%) as Integer

' /* range check: note values passed add/subtract thirds of range */

if hue < 0 then hue = hue +HLSMAX

if hue > HLSMAX then hue = hue - HLSMAX

' /* return r,g, or b value from this tridrant */

if hue < (HLSMAX/6) then

HueToRGB= n1 + (((n2-n1)*hue+(HLSMAX/12))/(HLSMAX/6)) )

Elseif (hue < (HLSMAX/2)) then

HueToRGB = n2

ElseIf hue < ((HLSMAX*2)/3) Then

HueToRGB = n1 + (((n2-n1)*(((HLSMAX*2)/3)-hue)+(HLSMAX/12))/(HLSMAX/6))

Else

HueToRGB = n1

End If

End Function

Private Function HLS2RGB(byval Hue as integer, byval Lum as integer, byval Sat as integer) as long

Dim R%,G%,B% ' /* RGB component values */

Dim Magic1%,Magic2% ' /* calculated magic numbers (really!) */

If sat = 0 Then ' /* achromatic case */

R = lum * 255/HLSMAX

G = R: B=R

Else ' /* chromatic case */

'/* set up magic numbers */

if (lum <= (HLSMAX/2))

Magic2 = (lum*(HLSMAX + sat) + (HLSMAX/2))/HLSMAX

else

Magic2 = lum + sat - ((lum*sat) + (HLSMAX/2))/HLSMAX

End if

Magic1 = 2*lum-Magic2

' /* get RGB, change units from HLSMAX to RGBMAX */

R = (HueToRGB(Magic1,Magic2,hue+(HLSMAX/3))*RGBMAX +

(HLSMAX/2))/HLSMAX

G = (HueToRGB(Magic1,Magic2,hue)*RGBMAX + (HLSMAX/2)) / HLSMAX

B = (HueToRGB(Magic1,Magic2,hue-(HLSMAX/3))*RGBMAX +

(HLSMAX/2))/HLSMAX

End If

HLS2RGB = RGB(R,G,B )

End Function
Link to comment
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
 Share

×
×
  • Create New...