如何使用 MixedRealityToolkit 着色器和圆角平铺纹理?

How to tile texture with MixedRealityToolkit shader and Round Corners?

我正在尝试使用 Unity 中的 MRTK 制作动画 material。目标是使效果看起来像从一个圆开始并将纹理传播到平面的其余部分。

现在我使用 MixedRealityToolkit 标准着色器并使用圆角选项。我制作了一个动画:

我的问题是我无法平铺纹理以减小纹理的大小并重复它。同样对于非方形物体,纹理被拉伸并且不是很好。

如果我尝试更改平铺设置,纹理不会重复(纹理在“重复模式”下效果很好,当我取消勾选“圆角”选项时它会起作用)

(如果我显示Unity选择轮廓,我得到了重复的纹理,但是没有显示...)

有没有人知道使用 MRTK 着色器或如何为此效果编写特定着色器的好主意?

我找到了解决方案,编写自己的着色器:

Shader "Custom/testShader"
{

Properties
{
    _Color ("Color", Color) = (1,1,1,1)
    _MainTex ("Albedo (RGB)", 2D) = "white" {}
    _ForegroundMask("Foreground Mask", 2D) = "white" {}
    _RadiusSize("Radius size", Range(0,2)) = 0
    _BorderWidth("Smooth Edge width", Range(0,1)) = 0.5
    _Glossiness ("Smoothness", Range(0,1)) = 0.5
    _Metallic ("Metallic", Range(0,1)) = 0.0
}
SubShader
{
    Tags {"Queue"="Transparent" "RenderType"="Transparent" }
    LOD 200

    ZWrite Off
    Blend SrcAlpha OneMinusSrcAlpha

    CGPROGRAM
    // Physically based Standard lighting model, and enable shadows on all light types
    #pragma surface surf Standard fullforwardshadows alpha:fade

    // Use shader model 3.0 target, to get nicer looking lighting
    #pragma target 3.0

    sampler2D _MainTex;
    sampler2D _ForegroundMask;

    struct Input
    {
        float2 uv_MainTex;
        float2 uv_ForegroundMask;
    };


    half _Glossiness;
    half _Metallic;
    fixed4 _Color;
    float _RadiusSize;
    float _BorderWidth;

    // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
    // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
    // #pragma instancing_options assumeuniformscaling
    UNITY_INSTANCING_BUFFER_START(Props)
        // put more per-instance properties here
    UNITY_INSTANCING_BUFFER_END(Props)

    void surf (Input IN, inout SurfaceOutputStandard o)
    {

        fixed2 dist;
        dist.x = IN.uv_ForegroundMask.x - 0.5;
        dist.y = IN.uv_ForegroundMask.y - 0.5;

        fixed circle=  1.0 - smoothstep(_RadiusSize-(_RadiusSize * _BorderWidth),_RadiusSize+(_RadiusSize * _BorderWidth), dot(dist,dist)*4.0);

       
        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 * circle;


    }
    ENDCG
}
FallBack "Diffuse"
}