其他分享
首页 > 其他分享> > URP(一)

URP(一)

作者:互联网

https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@10.8/manual/writing-shaders-urp-unlit-color.html
只有外部一个颜色输入的着色器
tags添加"RenderPipeline" = "UniversalPipeline"
include文件改成#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
顶点着色器之前添加CBUFFER代码,基本逻辑和内置管线一样

CBUFFER_START(UnityPerMaterial)
    half4 _BaseColor;
CBUFFER_END
// This shader fills the mesh shape with a color that a user can change using the
// Inspector window on a Material.
Shader "Example/URPUnlitShaderColor"
{
    // The _BaseColor variable is visible in the Material's Inspector, as a field
    // called Base Color. You can use it to select a custom color. This variable
    // has the default value (1, 1, 1, 1).
    Properties
    {
        _BaseColor("Base Color", Color) = (1, 1, 1, 1)
    }

    SubShader
    {
        Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline" }

        Pass
        {
            HLSLPROGRAM
            #pragma vertex vert
            #pragma fragment frag

            #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"

            struct Attributes
            {
                float4 positionOS   : POSITION;
            };

            struct Varyings
            {
                float4 positionHCS  : SV_POSITION;
            };

            // To make the Unity shader SRP Batcher compatible, declare all
            // properties related to a Material in a a single CBUFFER block with
            // the name UnityPerMaterial.
            CBUFFER_START(UnityPerMaterial)
                // The following line declares the _BaseColor variable, so that you
                // can use it in the fragment shader.
                half4 _BaseColor;
            CBUFFER_END

            Varyings vert(Attributes IN)
            {
                Varyings OUT;
                OUT.positionHCS = TransformObjectToHClip(IN.positionOS.xyz);
                return OUT;
            }

            half4 frag() : SV_Target
            {
                // Returning the _BaseColor value.
                return _BaseColor;
            }
            ENDHLSL
        }
    }
}

标签:BaseColor,CBUFFER,Material,URP,include,com,UnityPerMaterial
来源: https://www.cnblogs.com/melttt/p/15816174.html