post filter effect, need help

Started by
1 comment, last by bearanimations 15 years, 5 months ago
i havent gotten this far into proggramming yet, but i was wondering if someone could help me. basically this is a post filter effect, an xml file, its designed to be used in a program called dxtweaker(if you dont know what that is, which you probably do, it runs video games and adds a post filter effect to alter the final color using a shader). anyway, im trying to make this desaturate the final render a little bit, the code i have makes it completely desaturated(black and white), but i want only a small percent of saturation (about 20% wereas full black and white is 100 %), here is the code. <Effect Display="Greyscale"> <Pass Destination="Display"> <Source Sampler="0" Name="Backbuffer"/> <FConst Start="0"> <Vector X="0.30" Y="0.59" Z="0.11" W="1.0"/> </FConst> <PixelShader> <![CDATA[ ps_2_0 dcl_2d s0 dcl t0.xy texld r0, t0, s0 dp3 r0,r0,c0 mov oC0,r0 ]]> </PixelShader> </Pass> </Effect> like i said i havent gotten this far yet. is there anything i should alter or change (like number values) to get my desired effect. thanks.
Advertisement
Okay now what this shader here is doing (in ps_2_0 shader assembly) is it's sampling the source texture, and computing the luminance of the color value being sampled. The luminance is calculated by taking the dot product of the of the texture color with "Vector X", which is <0.3, 0.59, 0.11, 1.0>. This comes from the equations used to convert RGB to CIE Luv. Doing this will always give you a black and white value, since a dot product produces a scalar and not a vector.

What you can do however is use a lerp instruction. A lerp, short for "linearly interpolate", takes two vectors (color values) and gives you a mix of the two. The mixture depends on a third parameter, a scalar from 0 to 1. So let's say you had a lerp instruction like this:

lerp r2, c0, r0, r1

This would give you a blend of r0 and r1 and store it r2, using c1 to control the "mixture". A value of 0 for c0 would give you only r0, 1 would give you r1, and 0.5 would give a mix of the two.

So knowing this we can put a lerp at the end of the shader, and use a single parameter to control the saturation level. Modifying the script gives us this (I don't know the exact format for the script, so I might make a mistake here):
<Effect Display="Greyscale"><Pass Destination="Display"><Source Sampler="0" Name="Backbuffer"/><FConst Start="0"><Vector X="0.30" Y="0.59" Z="0.11" W="1.0"/><Vector X="0.5" Y="0.5" Z="0.5" W="0.5"/></FConst><PixelShader><![CDATA[ps_2_0dcl_2d s0dcl t0.xytexld r0, t0, s0dp3 r1,r0,c0lerp r0, c1, r0, r1mov oC0,r0]]></PixelShader></Pass></Effect>

With that, you should be able to control the saturation level by setting values of the second vector declaration. 1.0 should give you full color, and 0 should give you black and white. At least, if I'm declaring that second constant right. [smile]
ok, i have very little knowledge of this, but i think i might get what your saying. So you added <Vector X="0.5" Y="0.5" Z="0.5" W="0.5"/>
into this and used lerp to mix the two together? or is this how much you want the lerp to mix? also you said "A value of 0 for c0 would give you only r0" which r0 gets the value of c0, (i think theres about four in there). or are they all just the same r0 just being changed? sorry for all the questions, but i still havent gotten into shaders and such yet. im very confuesed.

This topic is closed to new replies.

Advertisement