colormath: Desaturation

Started by
14 comments, last by S1CA 18 years, 2 months ago
In that case blend a little between the completely desaturated colour and the original colour. Do something like 0.9 * original_color + 0.1 * desaturated_color.
Advertisement
oh ok! i understand!

taht's working :) thanks!

just one mor question: perhaps there is a less accurate but (for small saturation changes) working formula with less operations?
For more colour manipulation ideas using interpolation/extrapolation, see the following: http://www.sgi.com/misc/grafica/interp/index.html

Quote:just one mor question: perhaps there is a less accurate but (for small saturation changes) working formula with less operations?


The linear interpolations posted above can be done with a single pixel shader 1.1 instruction, you won't find much less than 1![smile]

HLSL:
const float3 coef = {0.3, 0.59, 0.11};
out.rgb = lerp(in.rgb, coef.rgb, amount);

PS1.1:
def c0, amount, 0, 0, 0
def c1, 0.3, 0.59, 0.11, 1
lrp r0.rgb, c0.r, r0.rgb, c1.rgb ; r0=input and output

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

Quote:The linear interpolations posted above can be done with a single pixel shader 1.1 instruction, you won't find much less than 1!
Anonymous Poster: Not one instruction, you forgot to do the dot product:

(Without knowing exact HLSL syntax)

HLSL:
const float3 coef = {0.3, 0.59, 0.11};
out.rgb = lerp(in.rgb, dot3(coef.rgb, in.rgb), amount);


PS1.1:
def c0, amount, 0, 0, 0
def c1, 0.3, 0.59, 0.11, 1
; r0=input and output
dot3 r1.rgb, c1.rgb, r0.rgb
lrp r0.rgb, c0.r, r0.rgb, r1.rgb
Quote:Original post by Anonymous Poster
Anonymous Poster: Not one instruction, you forgot to do the dot product:

(Without knowing exact HLSL syntax)

HLSL:
const float3 coef = {0.3, 0.59, 0.11};
out.rgb = lerp(in.rgb, dot3(coef.rgb, in.rgb), amount);


PS1.1:
def c0, amount, 0, 0, 0
def c1, 0.3, 0.59, 0.11, 1
; r0=input and output
dot3 r1.rgb, c1.rgb, r0.rgb
lrp r0.rgb, c0.r, r0.rgb, r1.rgb


AP: Oops, my bad, yep you're quite right.


OP: So if you don't already have the luminance of the source image elsewhere in your shader, you'll have to dot the input colour against the coefficients to get it.

That said, luminance being scalar does open up some opportunities for co-issuing, so in most non-trivial pixel shaders, I'd still expect the whole desaturation operation to take only 1-1.5 effective instruction slots (or to be able to tag some extra functionality onto the operation to save elsewhere).

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

This topic is closed to new replies.

Advertisement