如何将半透明的白色应用于圆形擦除的轮廓

发布于 2025-01-20 11:21:58 字数 2707 浏览 0 评论 0原文

这个问题的一个目标是,我的圆圈擦拭大纲在下图中的左exmple进行了改进。到目前为止,我的圆形擦拭仪没有两个清晰的半透明戒指。如果您知道如何像左图一样渲染它们,您会给我一些建议吗?

我想实施的理想圆擦拭。

理想的圆圈擦除视频

这是我使用的着色器。

Shader "Unlit/CircleWipe"
 {
     Properties
     {
         _MainTex ("Texture", 2D) = "white" {}
         _FadeTex("Fade Texture", 2D) = "white" {}
         _Radius("Wipe Radius", Float) = 0
         _Horizontal("Horizontal ratio", Float) = 1
         _Vertical("Vertical ratio", Float) = 1
         _RadiusSpeed("Radius Speed", Float) = 1
         _CenterX("Center X",  Range(0.0, 1.0)) = 0.5
         _CenterY("Center Y",  Range(0.0, 1.0)) = 0.5
         [HDR]_FadeColour("Fade Colour", Color) = (1,1,1,0)
         _Offset("Offset", Vector) = (0,0,0,0)
     }
     SubShader
     {
         Tags { "RenderType" = "Transparent" "Queue" = "Transparent" }
         Blend SrcAlpha OneMinusSrcAlpha


     Pass
     {
         CGPROGRAM
         #pragma vertex vert
         #pragma fragment frag
         #pragma multi_compile_fog

         #include "UnityCG.cginc"

         struct appdata
         {
             float4 vertex : POSITION;
             float2 uv : TEXCOORD0;
         };

         struct v2f
         {
             float2 uv : TEXCOORD0;
             UNITY_FOG_COORDS(1)
             float4 vertex : SV_POSITION;
         };

         sampler2D _MainTex;
         sampler2D _FadeTex;
         float4 _MainTex_ST;
         float _Radius;
         float _Horizontal;
         float _Vertical;
         float _RadiusSpeed;
         float _CenterX;
         float _CenterY;
         fixed4 _FadeColour : COLOR;
         float4 _Offset;

         v2f vert (appdata v)
         {
             v2f o;
             o.vertex = UnityObjectToClipPos(v.vertex);
             o.uv = TRANSFORM_TEX(v.uv, _MainTex);
             UNITY_TRANSFER_FOG(o,o.vertex);
             return o;
         }

         fixed4 frag(v2f i) : SV_Target
         {
             fixed4 topCol = tex2D(_MainTex , i.uv);
             fixed4 fadeCol = _FadeColour * tex2D(_FadeTex , i.uv);
             float2 center = float2(_CenterX , _CenterY);
             float2 pos = i.uv.xy;
             float dist = length((pos - center) * float2(_Vertical , _Horizontal));
             return lerp(fadeCol , topCol , smoothstep(_Radius , _Radius + 1.1 , dist));
         }
         ENDCG
     }
 }
 }

比较

“

环境
Unity2020.3f
项目类型:通用渲染管道
目标:iOS& Android

A goal for this question is that outline of my circle wipe improves like left exmple in the image below. So far outline of my circle wipe does not have two clear semi-transparent rings. If you know how to render them like the left image, would you give me some advice?

An ideal circle wipe I would like to implement.

Ideal circle wipe video

Here's the shader I use.

Shader "Unlit/CircleWipe"
 {
     Properties
     {
         _MainTex ("Texture", 2D) = "white" {}
         _FadeTex("Fade Texture", 2D) = "white" {}
         _Radius("Wipe Radius", Float) = 0
         _Horizontal("Horizontal ratio", Float) = 1
         _Vertical("Vertical ratio", Float) = 1
         _RadiusSpeed("Radius Speed", Float) = 1
         _CenterX("Center X",  Range(0.0, 1.0)) = 0.5
         _CenterY("Center Y",  Range(0.0, 1.0)) = 0.5
         [HDR]_FadeColour("Fade Colour", Color) = (1,1,1,0)
         _Offset("Offset", Vector) = (0,0,0,0)
     }
     SubShader
     {
         Tags { "RenderType" = "Transparent" "Queue" = "Transparent" }
         Blend SrcAlpha OneMinusSrcAlpha


     Pass
     {
         CGPROGRAM
         #pragma vertex vert
         #pragma fragment frag
         #pragma multi_compile_fog

         #include "UnityCG.cginc"

         struct appdata
         {
             float4 vertex : POSITION;
             float2 uv : TEXCOORD0;
         };

         struct v2f
         {
             float2 uv : TEXCOORD0;
             UNITY_FOG_COORDS(1)
             float4 vertex : SV_POSITION;
         };

         sampler2D _MainTex;
         sampler2D _FadeTex;
         float4 _MainTex_ST;
         float _Radius;
         float _Horizontal;
         float _Vertical;
         float _RadiusSpeed;
         float _CenterX;
         float _CenterY;
         fixed4 _FadeColour : COLOR;
         float4 _Offset;

         v2f vert (appdata v)
         {
             v2f o;
             o.vertex = UnityObjectToClipPos(v.vertex);
             o.uv = TRANSFORM_TEX(v.uv, _MainTex);
             UNITY_TRANSFER_FOG(o,o.vertex);
             return o;
         }

         fixed4 frag(v2f i) : SV_Target
         {
             fixed4 topCol = tex2D(_MainTex , i.uv);
             fixed4 fadeCol = _FadeColour * tex2D(_FadeTex , i.uv);
             float2 center = float2(_CenterX , _CenterY);
             float2 pos = i.uv.xy;
             float dist = length((pos - center) * float2(_Vertical , _Horizontal));
             return lerp(fadeCol , topCol , smoothstep(_Radius , _Radius + 1.1 , dist));
         }
         ENDCG
     }
 }
 }

Comparison

Comparison

Environment
Unity2020.3f
Project type: Universal render pipeline
Target: IOS & Android

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谈情不如逗狗 2025-01-27 11:21:58
float a = smoothstep(_Radius - 1.1, _Radius, dist);
float b = smoothstep(_Radius, _Radius + 1.1, dist);
float t = a - b;
fixed4 col = lerp(fadeCol , topCol , b);
return lerp(col, _FadeColour, t);

您也可以尝试

return col + _FadeColour * t;

用以下方式将最后一行替换为以下方式:

“

float a = smoothstep(_Radius - 1.1, _Radius, dist);
float b = smoothstep(_Radius, _Radius + 1.1, dist);
float t = a - b;
fixed4 col = lerp(fadeCol , topCol , b);
return lerp(col, _FadeColour, t);

You may also try to replace the last line with:

return col + _FadeColour * t;

Effect achieved with 2 pictures:

Effect with 2 pics
Without the circle
Large circle

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文