Unity3d 采用Unity HDRP的三面纹理

Unity3d 采用Unity HDRP的三面纹理,unity3d,shader,Unity3d,Shader,我使用默认渲染管道编写了一个曲面着色器,在没有UV的网格上使用三平面纹理,效果很好,代码如下: Shader "Custom/TerrainShader" { // These properties can be modified from the material inspector. Properties{ _MainTex("Ground Texture", 2D) = "white" {} _WallTex("Wall Texture", 2D) = "white" {

我使用默认渲染管道编写了一个曲面着色器,在没有UV的网格上使用三平面纹理,效果很好,代码如下:

Shader "Custom/TerrainShader"
{
// These properties can be modified from the material inspector.
Properties{

    _MainTex("Ground Texture", 2D) = "white" {}
    _WallTex("Wall Texture", 2D) = "white" {}
    _TexScale("Texture Scale", Float) = 1

}

    // You can have multiple subshaders with different levels of complexity. Unity will pick the first one
    // that works on whatever machine is running the game.
        SubShader{

            Tags { "RenderType" = "Opaque" } // None of our terrain is going to be transparent so Opaque it is.
            LOD 200 // We only need diffuse for now so 200 is fine. (higher includes bumped, specular, etc)

            CGPROGRAM
            #pragma surface surf Standard fullforwardshadows // Use Unity's standard lighting model
            #pragma target 3.0 // Lower target = fewer features but more compatibility.

        // Declare our variables (above properties must be declared here)
        sampler2D _MainTex;
        sampler2D _WallTex;
        float _TexScale;

        // Say what information we want from our geometry.
        struct Input {

            float3 worldPos;
            float3 worldNormal;

        };

        // This function is run for every pixel on screen.
        void surf(Input IN, inout SurfaceOutputStandard o) {

            float3 scaledWorldPos = IN.worldPos / _TexScale; // Get a the world position modified by scale.
            float3 pWeight = abs(IN.worldNormal); // Get the current normal, using abs function to ignore negative numbers.
            pWeight /= pWeight.x + pWeight.y + pWeight.z; // Ensure pWeight isn't greater than 1.

            // Get the texture projection on each axes and "weight" it by multiplying it by the pWeight.
            float3 xP = tex2D(_WallTex, scaledWorldPos.yz) * pWeight.x;
            float3 yP = tex2D(_MainTex, scaledWorldPos.xz) * pWeight.y;
            float3 zP = tex2D(_WallTex, scaledWorldPos.xy) * pWeight.z;

            // Return the sum of all of the projections.
            o.Albedo = xP + yP + zP;

        }
        ENDCG
    }
        FallBack "Diffuse"
}

但是,当切换到新RP(HD或LW)时,使用它的材质将变为粉红色。我知道这是因为Unity不再支持曲面着色器,所以我的问题是,如何使用新RP实现三平面纹理?

通过着色器图形支持三平面纹理。只需点击图形编辑器中的空格并搜索“triplanar”,它就会显示出来

HDRP着色器使用延迟渲染,因此其着色器看起来根本不同。如果您想学习,我建议您在着色器图中创建一个基本着色器,然后右键单击主节点并选择“复制着色器”。然后,可以将着色器代码粘贴到文本编辑器中,并尝试对其进行反向工程。SRP GitHub也是一个很好的参考:

对于LWRP,我发现这个模板着色器非常有用:


通过着色器图形支持三平面纹理。只需点击图形编辑器中的空格并搜索“triplanar”,它就会显示出来

HDRP着色器使用延迟渲染,因此其着色器看起来根本不同。如果您想学习,我建议您在着色器图中创建一个基本着色器,然后右键单击主节点并选择“复制着色器”。然后,可以将着色器代码粘贴到文本编辑器中,并尝试对其进行反向工程。SRP GitHub也是一个很好的参考:

对于LWRP,我发现这个模板着色器非常有用: