Exception Posted December 27, 2012 Author Share Posted December 27, 2012 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 More sharing options...
Ryo Posted December 28, 2012 Share Posted December 28, 2012 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 clearerAre 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 mapsok 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 usedD3DDevice.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_POINTEnd Withthen 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 More sharing options...
Exception Posted December 28, 2012 Author Share Posted December 28, 2012 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 More sharing options...
Exception Posted December 28, 2012 Author Share Posted December 28, 2012 OK, I'm on my computer. Both are already set like that, so, I don't imagine it's that. Any other suggestion? Link to comment Share on other sites More sharing options...
Ryo Posted December 28, 2012 Share Posted December 28, 2012 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 = 252Private 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 +HLSMAXif hue > HLSMAX then hue = hue - HLSMAX' /* return r,g, or b value from this tridrant */if hue < (HLSMAX/6) thenHueToRGB= n1 + (((n2-n1)*hue+(HLSMAX/12))/(HLSMAX/6)) )Elseif (hue < (HLSMAX/2)) thenHueToRGB = n2ElseIf hue < ((HLSMAX*2)/3) ThenHueToRGB = n1 + (((n2-n1)*(((HLSMAX*2)/3)-hue)+(HLSMAX/12))/(HLSMAX/6))ElseHueToRGB = n1End IfEnd FunctionPrivate Function HLS2RGB(byval Hue as integer, byval Lum as integer, byval Sat as integer) as longDim R%,G%,B% ' /* RGB component values */Dim Magic1%,Magic2% ' /* calculated magic numbers (really!) */If sat = 0 Then ' /* achromatic case */R = lum * 255/HLSMAXG = R: B=RElse ' /* chromatic case */'/* set up magic numbers */if (lum <= (HLSMAX/2))Magic2 = (lum*(HLSMAX + sat) + (HLSMAX/2))/HLSMAXelseMagic2 = lum + sat - ((lum*sat) + (HLSMAX/2))/HLSMAXEnd ifMagic1 = 2*lum-Magic2' /* get RGB, change units from HLSMAX to RGBMAX */R = (HueToRGB(Magic1,Magic2,hue+(HLSMAX/3))*RGBMAX +(HLSMAX/2))/HLSMAXG = (HueToRGB(Magic1,Magic2,hue)*RGBMAX + (HLSMAX/2)) / HLSMAXB = (HueToRGB(Magic1,Magic2,hue-(HLSMAX/3))*RGBMAX +(HLSMAX/2))/HLSMAXEnd IfHLS2RGB = RGB(R,G,B )End Function Link to comment Share on other sites More sharing options...
Exception Posted December 28, 2012 Author Share Posted December 28, 2012 Ah, I'll see what I have to make of that. Thanks for that, it's pretty helpful! ![^_^](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/happy.png) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now