3

So I'm trying to do some shader work and I want use one color variable for two things: I want it to blend with the texture based on the "intensity" of the color, and I want the alpha of the color to blend the entirety of the image.

So:

fixed4(tex.rgb * (1 - intensity) + color.rgb * (intensity), tex.a * color.a)

Now my idea is to use the highest RGB value of color for it's intensity. using color.a is more intuitive, but since I want to use that for the transparency of the entire object, this doesn't work.

So the question now is, how do I get intensity?

Comparing RGB individually seems clumsy. That would be:

r > b > g?

And result in this uglyness:

max(r, max(g, b) )

Is there a better solution?

genpfault
  • 51,148
  • 11
  • 85
  • 139
MNerurkar
  • 31
  • 2

1 Answers1

0

Physical intensity is usually (r+g+b)/3. (or weighted variant to account for eye sensibility). Here you are getting the "value" of painters, which is perceptually not an intensity ( because white = R+G+B is more watts/st that R alone). But if you really want the value, yes, max(max()). (Not that much a big deal :-) )

Fabrice NEYRET
  • 644
  • 4
  • 16