[英]How do I cut out a shape in a background sprite in Unity?
這是理想的效果: https : //gyazo.com/1e98ca2709282d0163702b8ce829480d
圓圈必須能夠在背景上移動並隨其移除背景。
我找到了較舊的教程,但他們似乎使用了無法繞過頭的着色器。 我也嘗試過模版着色器,但意識到它們不能滿足我的要求。
有簡單的方法嗎?
您可以編寫一個簡單的蒙版着色器。 在線上有許多解決方案和示例。 為了獲得想要的效果,可以使用如下所示的着色器:
Shader "MaskedTexture"
{
Properties
{
_MainTex ("Base (RGB)", 2D) = "white" {}
_Mask ("Culling Mask", 2D) = "white" {}
_Cutoff ("Alpha cutoff", Range (0,1)) = 0.1
}
SubShader
{
Tags {"Queue"="Transparent"}
Lighting Off
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
AlphaTest GEqual [_Cutoff]
Pass
{
SetTexture [_Mask] {combine texture}
SetTexture [_MainTex] {combine texture, previous}
}
}
}
要移動蒙版,只需更改其偏移量即可。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.