Hi
Can one access channels from a texture (photoshop R,G,B channels) within a shader using Unity Shader language or would this need to be done in GC/GLSL?
Hi
Can one access channels from a texture (photoshop R,G,B channels) within a shader using Unity Shader language or would this need to be done in GC/GLSL?
Yes, you can.
If 'theTexture' is defined as a Sampler2D, you can do this:
half4 pixelColor = tex2D (theTexture, uv); // sample the texture at position 'uv'
and then read the r, g, b or a values using:
pixelColor.r
pixelColor.g
pixelColor.b
pixelColor.a
Read more about "Texture Samplers" on the nvidia cg tutorial, here: http://http.developer.nvidia.com/CgTutorial/cg_tutorial_chapter03.html
You can also use 'swizzles' to pull out custom combinations of components of the color array (or other 3 or 4 item vector), eg:
pixelColor.rgb // would create a new half3
pixelColor.aaaa // same as half4(pixelColor.a,pixelColor.a,pixelColor.a,pixelColor.a)
uv.yx // same as half2(u.x,v.x)
...etc
For more information on swizzling, read here (about one third the way down the page): http://http.developer.nvidia.com/CgTutorial/cg_tutorial_chapter05.html
For more on Unity, ShaderLab, Cg, GLSL and HLSL - please read:
Unity Answers - Can I use HLSL or GLSL shaders in Unity?
And, of course, the docs.