【发布时间】:2020-10-01 21:32:24
【问题描述】:
我编写了一个着色器,它将 RGB 相机值转换为 HSV,然后对绿色铬应用一些过滤。 当前问题
-
如果前景(玩家)的物体有绿色像素,它将被切掉。
-
我已经有了深度相机,如何使用该属性制作更好的切出镀铬键?
frag (v2f i) : SV_Target { fixed4 col = tex2D(_MainTex, i.uv);
if (_ShowBackground) { fixed4 col2 = tex2D(_TexReplacer, i.uv); col = col2; } else if (!_ShowOriginal) { fixed4 col2 = tex2D(_TexReplacer, i.uv); float maskY = 0.2989 * _GreenColor.r + 0.5866 * _GreenColor.g + 0.1145 * _GreenColor.b; float maskCr = 0.7132 * (_GreenColor.r - maskY); float maskCb = 0.5647 * (_GreenColor.b - maskY); float Y = 0.2989 * col.r + 0.5866 * col.g + 0.1145 * col.b; float Cr = 0.7132 * (col.r - Y); float Cb = 0.5647 * (col.b - Y); float alpha = smoothstep(_Sensitivity, _Sensitivity + _Smooth, distance(float2(Cr, Cb), float2(maskCr, maskCb))); col = (alpha * col) + ((1 - alpha) * col2); } return col; }
【问题讨论】:
-
请注意,您应该避免在着色器中使用
if else语句。为此,您可以使用step(...)。
标签: unity3d gpu shader fragment-shader