Shader cg program questions hsl rgb individual channels magnitude of builtin vectors

Hello,

I’ve read the shader reference Unity - Manual: ShaderLab, particularly the surface shader reference, but I didn’t find the answer to some questions:

  1. how can I obtain the individual channels of the hsl (hue, saturation, lightness) model from a color vector? Alternatively the individual rgb channels.

  2. what’s the magnitude of the built-in vectors like lightDir and viewDir and Normal? If viewDir is a unit vector, what’s the actual distance from the pixel to the camera?

  3. viewDir and such are part of the lighting models function arguments, yet what about the “pixel” part (typically “surf”). How can I use them there?

  4. How do I multiply a vector (eg half3) with a scalar (eg. half) ? Simply half * half3 ?

The program probably uses Cg as the shading language (the same as in the examples of the reference and tutorials on the Website :slight_smile: )

This is all for now, thank you and have fun!

HSV doesnt compute in shaders, there are example around for converting to and from HSV>RGB
As for getting component vales from a color, you can just use someColor.r for red, etc. Note: you can equally use someColor.xyz in place of rgb

I would be surprised if dir vectors aren’t normalized (unit length).

half3 * half should be fine.