- Home /
I don't get how Colormask is supposed to work
On my long road to attempt to reproduce portal effect within an Oculus Rift, I am trying to understand Colormask in ShaderLab, but its behaviour doesn't make sense to me.
I have created a Standard Surface Shader, to which I have two things :
"Queue" = "Geometry+10" in Tags ( I put this in because I was having different behaviour depending on the camera position otherwise )
and
ColorMask R
Shader "Custom/Test2" {
Properties {
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_Glossiness ("Smoothness", Range(0,1)) = 0.5
_Metallic ("Metallic", Range(0,1)) = 0.0
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
ColorMask R
CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard fullforwardshadows
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
sampler2D _MainTex;
struct Input {
float2 uv_MainTex;
};
half _Glossiness;
half _Metallic;
fixed4 _Color;
void surf (Input IN, inout SurfaceOutputStandard o) {
// Albedo comes from a texture tinted by color
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
// Metallic and smoothness come from slider variables
o.Metallic = _Metallic;
o.Smoothness = _Glossiness;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
I have created one material with this shader on ( color white, so R and everything else = 255 ), and put a bunch of cube with standard material on them, one white, one red and one cyan ( r=0 ), as a reference .
Here is the result :

So, if I was to guess here, I would say that putting a shader with colormask R, with a red channel at 255, add its red channel to everything behind it. If it's red, it stays, if its white, same, and if it's cyan, it becomes white, because now its red channel = 255 like the other two.
Except the ground is white. Same material as the white cube. And appears cyan through the colormasking cube. Which means its red channel has been ... well ... masked ... which is what I was expecting in the first place, but is not coherent with what I am seeing on the three cubes.
Also why does the skybox appear solid red through the mask ?
So, in short, I don't get it and I am probably using this incorrectly.
If someone could explain to me how this is supposed to work, I would very much appreciate it.
Thanks.
Your answer
Follow this Question
Related Questions
calculating 1 Answer
How to access another sprite's texture from a 2D shader 0 Answers
Pass ShaderLab properties to Standard cginc 2 Answers
[Unity Free]Add textures to existing Unity DOF Shader 0 Answers
tex2D(_texture, float2(col/(width-1), row/(height-1))) is not returning correct values 1 Answer