Sign in to follow this  
Pooya65

color saturation filter in HLSL

Recommended Posts

Pooya65    127
i cant translate this effect to the HLSL, plz help me ps.1.1 def c0, 1.0, 1.0, 1.0, 1.0 def c1, 0.3, 0.59, 0.11, 0.5 tex t0 // sample the source image mov_x4_sat r0.rgb, t0_bx2 // saturate dp3_sat r1.rgba, r0, c0 // do we have any bright colors? dp3 r1.rgb, t0, c1 // greyscale lrp r0.rgb, r1.a, r0, r1 // interpolate between color and greyscale + mov r0.a, t0.a // output alpha

Share this post


Link to post
Share on other sites
MJP    19786
Never really worked with ps_1_1 asm, but from looking at the documentation I think the HLSL would look like this...


sampler2D texSampler : register (s0);

static const float3 greyScaleConversion = {0.3f, 0.59f, 0.11f};

float PS( in texCoord : TEXCOORD0 ) : COLOR0
{
float4 sampleColor = tex2D(texSampler, texCoord)
float3 saturated = clamp(sampleColor.rgb * 4.0f);
float bright = saturate(saturated, float3(1, 1, 1));
float3 greyScale = dot(sampleColor.rgb, greyScaleConversion);
float3 lerped = lerp(saturated, greyscale, bright);
return float4(lerped, sampleColor.a);
}



Share this post


Link to post
Share on other sites
MJP    19786
Quote:
Original post by Namethatnobodyelsetook
Quote:
Original post by MJP
float3 saturated = clamp(sampleColor.rgb * 4.0f);

I think you need *8 - 4 to simulate the _BX2 modifier.


Shoot, you're right. Nice catch.

Share this post


Link to post
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

Sign in to follow this