float to vector and back

   4539   3   0
User Avatar
Member
2624 posts
Joined: Aug. 2006
Offline
In a vex shader If color is a vector and a function is a float that requires an input of a float how in vex do you change change your input value from a vector to a float ? A simple example would be really useful as theres nothing in the help that I can find

R
Gone fishing
User Avatar
Staff
2675 posts
Joined: July 2005
Offline
circusmonkey
In a vex shader If color is a vector and a function is a float that requires an input of a float how in vex do you change change your input value from a vector to a float ? A simple example would be really useful as theres nothing in the help that I can find

R

It might be helpful to understand the context… But you can convert a vector to a color in several different ways

1) Use a single component
2) Use the maximum/minimum or average values
3) Use some other combination of the values (i.e. luminance)


vector clr;
float f;
f= clr.r; // Use red
f = max(clr); // Use maximum component
f = min(clr); // Minimum component
f = avg(clr); // Average of 3 components
f = luminance(clr); // Luminance of color
f = clr.r*.5 + clr.g*.2 + clr.b*.3; // Some odd weighting
f = dot(clr, {.5, .2, .3}); // Different way of writing above code
User Avatar
Member
2624 posts
Joined: Aug. 2006
Offline
Thanks that clears up some confusion for me.

R
Gone fishing
User Avatar
Member
665 posts
Joined: July 2005
Offline
sweet mark!

I never knew about the max(), min() bit.

cheers,
-j
  • Quick Links