为什么着色器不在地形上工作?它应该画一个圆圈

问题描述 投票:0回答:1

我试图从本教程中学习:Writing Shaders In Unity

着色器代码:

Shader "Custom/TerrainCircle"
{
    Properties
    {
       _MainTex("Texture", 2D) = "white" {}
       _MainColor("Main Color", Color) = (0, 1, 0)
       _CircleColor("Circle Color", Color) = (1, 0, 0)
       _Center("Center", Vector) = (0,0,0,0)
       _Radius("Radius", Range(0, 100)) = 10
       _Thickness("Thickness", Range(0, 100)) = 5
    }
        SubShader
       {
            CGPROGRAM
            #pragma surface surfaceFunc Lambert

            sampler2D _MainTex;
            fixed3 _MainColor;
            fixed3 _CircleColor;
            float3 _Center;
            float _Thickness;
            float _Radius;

            struct Input {
                float2 uv_MainTex;
                float3 worldPos;
            };

            void surfaceFunc(Input IN, inout SurfaceOutput o) {
                half4 c = tex2D(_MainTex, IN.uv_MainTex);
                float dist = distance(_Center, IN.worldPos);

                if (dist > _Radius && dist < (_Radius + _Thickness))
                    o.Albedo = _CircleColor;
                else
                    o.Albedo = c.rgb;

                o.Alpha = c.a;
            }
            ENDCG
       }
}

然后,我使用代码和材质创建了一个Shader文件。将明暗器添加到材质中。然后将材质拖到地形。

两个问题:

  1. 将材质拖到地形时,它仅将材质放在白色岩石上地形的一小部分。为什么没有在整个地形上应用材质?

  2. 完全没有显示圆。什么都没画。甚至与该链接中的教程视频都不一样。

Material is not over all the terrain and the shader is not working no circle at all

我将地形移至一侧,因为岩石和悬崖来自另一处资产。但是现在我无法将材质拖到地形上。地形完全不接受材料。

The terrain is now on the side but I an't drag the material over it

c# unity3d shader material
1个回答
0
投票

像这样将材料添加到地形中:

© www.soinside.com 2019 - 2024. All rights reserved.