Unity URP Shader(HLSL)踩坑日记(一)

这篇具有很好参考价值的文章主要介绍了Unity URP Shader(HLSL)踩坑日记(一)。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

最近开始转TA,刚开始学习,资料比较杂乱,其中遇到的问题和一些计算方式,记录一下,后续会一直完善补充。

1.urp中基础不受光shader

Shader "Example/URPUnlitShaderColor"
{
    Properties
    {
        [MainColor] _BaseColor("Base Color", Color) = (1, 1, 1, 1)
        [MainTexture] _BaseMap("Base Map", 2D) = "white"{}
    }

    SubShader
    {
        // SubShader Tags 定义何时以及在何种条件下执行某个 SubShader 代码块或某个通道。
        Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline" }

        Pass
        {
            // 声明Pass名称,方便调用与识别
            Name "ForwardUnlit"
            // HLSL 代码块。Unity SRP 使用 HLSL 语言。
            HLSLPROGRAM
            // 此行定义顶点着色器的名称。
            #pragma vertex vert
            // 此行定义片元着色器的名称。
            #pragma fragment frag

            // Core.hlsl 文件包含常用的 HLSL 宏和函数的定义,还包含对其他 HLSL 文件(例如Common.hlsl、SpaceTransforms.hlsl 等)的 #include 引用。
            #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"

            // 结构定义将定义它包含哪些变量。此示例使用 Attributes 结构作为顶点着色器中的输入结构。
            struct Attributes
            {
                // positionOS 变量包含对象空间中的顶点
                float4 positionOS   : POSITION;
                // uv 变量包含给定顶点的纹理上的
                float2 uv           : TEXCOORD0;
                // 声明包含每个顶点的法线矢量的
                half3 normal        : NORMAL;
            };

            struct Varyings
            {
                // 此结构中的位置必须具有 SV_POSITION 语义。
                float4 positionHCS  : SV_POSITION;
                float2 uv           : TEXCOORD0;
                half3 normal        : NORMAL;
                
            };
            // 材质单独声明,使用DX11风格的新采样方法
            // 此宏将 _BaseMap 声明为 Texture2D 对象。
            TEXTURE2D(_BaseMap);
            // This macro declares the sampler for the _BaseMap texture.
            SAMPLER(sampler_BaseMap);

            // 要使 Unity 着色器 SRP Batcher 兼容,请在名为 UnityPerMaterial 的单个 CBUFFER 代码块中声明与材质相关的所有属性。
            // 有关 SRP Batcher 的更多信息 https://docs.unity3d.com/Manual/SRPBatcher.html
            CBUFFER_START(UnityPerMaterial)
                // 以下行声明了 _BaseColor 变量,以便可以在片元着色器中使用它。
                half4 _BaseColor;
                // 以下行声明 _BaseMap_ST 变量,以便可以在片元着色器中使用 _BaseMap 变量。为了使平铺和偏移有效,有必要使用 _ST 后缀。
                float4 _BaseMap_ST;
            CBUFFER_END

            // 顶点着色器定义具有在 Varyings 结构中定义的属性。vert 函数的类型必须与它返回的类型(结构)匹配。
            Varyings vert(Attributes IN)
            {
                // // 使用 Varyings 结构声明输出对象 (OUT)。
                Varyings OUT;
                //方法一
                // TransformObjectToHClip 函数将顶点位置从对象空间变换到齐次裁剪空间。
                OUT.positionHCS = TransformObjectToHClip(IN.positionOS.xyz);
                //方法二
                //GetVertexPositionInputs方法根据使用情况自动生成各个坐标系下的定点信息。
                //#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderVariablesFunctions.hlsl"
                // VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz);
                // OUT.positionHCS = vertexInput.positionCS;
                
                // TRANSFORM_TEX 宏执行平铺和偏移
                OUT.uv = TRANSFORM_TEX(IN.uv, _BaseMap);
                // 使用 TransformObjectToWorldNormal 函数将法线从对象空间变换到世界空间。此函数来自 Core.hlsl 中引用的SpaceTransforms.hlsl 文件。
                OUT.normal = TransformObjectToWorldNormal(IN.normal);
                return OUT;
            }

            half4 frag(Varyings IN) : SV_Target
            {
                // SAMPLE_TEXTURE2D 宏使用给定的采样器对纹理进行
                half4 color = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, IN.uv);
                color*=_BaseColor;
                return color;
            }
            ENDHLSL
        }
    }
}

注意此时Properties中的属性,如果要开启SRP合批,需要放到CBUFFER代码块中。

2.从代码块中可以看出渲染的流程:

com.unity.render-pipelines.universal,unity,游戏引擎,图形渲染应用阶段准备的数据---->com.unity.render-pipelines.universal,unity,游戏引擎,图形渲染

顶点着色处理数据(返回值为处理后的数据)---->com.unity.render-pipelines.universal,unity,游戏引擎,图形渲染------>com.unity.render-pipelines.universal,unity,游戏引擎,图形渲染片元着色器接收上一阶段的数据,return片元渲染结果

3.如果不使用CBUFFER中声明,在Properties中声明属性之后,引入库

#include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"

这里会把属性的变量包装,但属性名字需要和类库中的一致,库中默认属性:

 com.unity.render-pipelines.universal,unity,游戏引擎,图形渲染

 此时就不需要自己在CBUFFER中声明属性了,对于Texture也不需要额外处理了,如:

com.unity.render-pipelines.universal,unity,游戏引擎,图形渲染

 4.添加一个Toggle判断

 注意Toggle(_AdditionalLights)里面的字段

com.unity.render-pipelines.universal,unity,游戏引擎,图形渲染

 声明shader_feature

 com.unity.render-pipelines.universal,unity,游戏引擎,图形渲染

 通过#if xxx  #endif判断

com.unity.render-pipelines.universal,unity,游戏引擎,图形渲染

5.Blinn-Phong光照模型

Shader "MyShader/BarkShader1"
{
   Properties
    {
      
        [MainColor] _BaseColor("Base Color", Color) = (1, 1, 1, 1)
        [MainTexture] _BaseMap("Base Map", 2D) = "white"{}
        _SpecColor("Specular", Color) = (1.0, 1.0, 1.0, 1.0)
        _Smoothness("Gloss", Range(8.0, 256)) = 20
    }

    SubShader
    {
        // URP的shader要在Tags中注明渲染管线是UniversalPipeline
      Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline" }


        Pass
        {
            // 声明Pass名称,方便调用与识别
            Name "ForwardBlinPhong"

            HLSLPROGRAM

            // 声明顶点/片段着色器对应的函数
            #pragma vertex vert
            #pragma fragment frag

            #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
            #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
            //引用后,自动SRP合批,且不需要再声明TEXTURE2D(_BaseMap); SAMPLER(sampler_BaseMap);及CBUFFER_START
            #include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
            struct Attributes
            {
                float4 positionOS : POSITION;
                float3 normalOS   : NORMAL;
                float2 uv         : TEXCOORD0;
            };

            struct Varyings
            {
                float4 positionCS : SV_POSITION;
                float3 positionWS : POSITION_WS;
                float2 uv         : TEXCOORD0;
                float3 normalWS    : NORMAL_WS;
            };
           
            // 顶点着色器
            Varyings vert(Attributes input)
            {
                // GetVertexPositionInputs方法根据使用情况自动生成各个坐标系下的定点信息
                const VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz);
                    
                Varyings output;
                output.uv = TRANSFORM_TEX(input.uv, _BaseMap);
                output.positionCS = vertexInput.positionCS;
                output.positionWS = vertexInput.positionWS;
                output.normalWS = TransformObjectToWorldNormal(input.normalOS);
                return output;
            }

            // 片段着色器
            half4 frag(Varyings input) : SV_Target
            {
                float4 output;  
                  
                real3 positionWS = input.positionWS;
               
                real3 normalWS = normalize(input.normalWS);
                Light mainLight = GetMainLight(); // 主光源
                real3 lightColor = mainLight.color; // 主光源颜色
                 
                real3 lightDir = normalize(mainLight.direction); // 主光源方向
                real3 albedo = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, input.uv) * _BaseColor;
                real3 viewDirectionWS = SafeNormalize(GetCameraPositionWS() - positionWS); // safe防止分母为0
                real3 h = SafeNormalize(viewDirectionWS + lightDir);
                real3 specular = pow(saturate(dot(h, input.normalWS)), _Smoothness) * lightColor * saturate(_SpecColor); // 高光
                real3 ambient = SampleSH(normalWS) * albedo; // 环境光
                   
                real3 diffuse = saturate(dot(lightDir,normalWS)) * lightColor * albedo; // 漫反射
                
                output = real4(ambient + diffuse + specular, 1.0);
                return output;
                }
            ENDHLSL
        }
       // 一般在Buit-In管线里,我们只需要最后FallBack返回到系统的Diffuse Shader,管线就会去里面找到他处理阴影的Pass。但是在URP中,一个Shader中的所有Pass需要有一致的CBuffer,否则便会打破SRP Batcher,影响效率。
       // 而系统默认SimpleLit的Shader中的CBuffer内容和我的写的并不一致,所以我们需要把它阴影处理的Pass复制一份,并且删掉其中引用的SimpleLitInput.hlsl(相关CBuffer的声明在这里面)
          Pass
        {
            Name "ShadowCaster"
            Tags{"LightMode" = "ShadowCaster"}

            ZWrite On
            ZTest LEqual
            ColorMask 0
            Cull[_Cull]

            HLSLPROGRAM
            #pragma exclude_renderers gles gles3 glcore
            #pragma target 4.5

            // -------------------------------------
            // Material Keywords
            #pragma shader_feature_local_fragment _ALPHATEST_ON
            #pragma shader_feature_local_fragment _GLOSSINESS_FROM_BASE_ALPHA

            //--------------------------------------
            // GPU Instancing
            #pragma multi_compile_instancing
            #pragma multi_compile _ DOTS_INSTANCING_ON

            #pragma vertex ShadowPassVertex
            #pragma fragment ShadowPassFragment

            #include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
            #include "Packages/com.unity.render-pipelines.universal/Shaders/ShadowCasterPass.hlsl"
            ENDHLSL
        }
    }
  
}

6.处理多光源

如果希望每个光源都能够进行逐像素的漫反射和高光反射计算,那么我们就需要在片元着色器中遍历每一个光源,并进行和上面一样的光照计算

GetAdditionalLightsCount()能够获取到影响这个片段的附加光源数量,但是如果数量超过了URP中设定的附加光照上限,就会返回附加光照上限的数量。

GetAdditionalLight(lightIndex, IN.positionWS);方法会按照index去找到对应的光源,并根据提供的片段世界坐标位置计算光照和阴影衰减,并存储在返回的Light结构体内。

int pixelLightCount = GetAdditionalLightsCount();
for (int lightIndex = 0; lightIndex < pixelLightCount; ++lightIndex)
{
    Light light = GetAdditionalLight(lightIndex, IN.positionWS);
    diffuse += LightingLambert(light.color, light.direction, IN.normalWS);
    specular += LightingSpecular(light.color, light.direction, normalize(IN.normalWS), normalize(IN.viewDirWS), _SpecularColor, _Smoothness);
}

7.带开关的多光源检测及高光

Shader "MyShader/BarkShader"
{
   Properties
    {
      
        [MainColor] _BaseColor("Base Color", Color) = (1, 1, 1, 1)
        [MainTexture] _BaseMap("Base Map", 2D) = "white"{}
        _BumpMap("Normal Map", 2D) = "bump"{}
        _BumpScale("NormalScale",Float) = 1.0
        _SpecColor("Specular", Color) = (1.0, 1.0, 1.0, 1.0)
        _Smoothness("Gloss", Range(8.0, 256)) = 20
        //添加一个Toggle判断
        [Toggle(_AdditionalLights)] _AddLights ("AddLights", Float) = 0
        [Toggle(_SpecColorToggle)] _SpecColorTog ("SpecColorToggle",Float) = 0
    }

    SubShader
    {
        // URP的shader要在Tags中注明渲染管线是UniversalPipeline
      Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline" }


        Pass
        {
            // 声明Pass名称,方便调用与识别
            Name "ForwardBlinPhong"

            HLSLPROGRAM

            // 声明顶点/片段着色器对应的函数
            #pragma vertex vert
            #pragma fragment frag
            #pragma shader_feature _AdditionalLights
            #pragma shader_feature _SpecColorToggle
            #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
            #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
            //引用后,自动SRP合批,且不需要再声明TEXTURE2D(_BaseMap); SAMPLER(sampler_BaseMap);及CBUFFER_START
            #include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
            //
            // TEXTURE2D(_BaseMap);
            // SAMPLER(sampler_BaseMap);
            // CBUFFER_START(UnityPerMaterial)
            // float4 _BaseColor;
            // float4 _BaseMap_ST;
            // real _Smoothness;
            // float4 _SpecColor;
            // CBUFFER_END
     
            struct Attributes
            {
                float4 positionOS : POSITION;
                float3 normalOS   : NORMAL;
                float4 tangentOS  : TANGENT;
                float2 uv         : TEXCOORD0;
            };

            struct Varyings
            {
                float4 positionCS : SV_POSITION;
                float3 positionWS : POSITION_WS;
                float2 uv         : TEXCOORD0;
                float3 normalWS    : NORMAL_WS;
                float4 tangentWS  : TANGENT_WS;
            };
           
            // 顶点着色器
            Varyings vert(Attributes input)
            {
                    // GetVertexPositionInputs方法根据使用情况自动生成各个坐标系下的定点信息
                const VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz);
                const VertexNormalInputs   vertexNormalInput = GetVertexNormalInputs(input.normalOS, input.tangentOS);
                    
                Varyings output;
                real sign = input.tangentOS.w * GetOddNegativeScale();
                output.uv = TRANSFORM_TEX(input.uv, _BaseMap);
                output.positionCS = vertexInput.positionCS;
                output.positionWS = vertexInput.positionWS;
                output.normalWS   = vertexNormalInput.normalWS;
                output.tangentWS = real4(vertexNormalInput.tangentWS, sign);
                return output;

                //方案2
                 // output.positionCS = TransformObjectToHClip(input.positionOS.xyz);
                 // output.normalWS = TransformObjectToWorldNormal(input.normalOS);
            }

            // 片段着色器
            half4 frag(Varyings input) : SV_Target
            {
                float4 output;  
                  
                real3 positionWS = input.positionWS;
                real sgn = input.tangentWS.w;      // should be either +1 or -1
                real3 bitangent = sgn * cross(input.normalWS.xyz, input.tangentWS.xyz);
                real3 normalTS=UnpackNormalScale(SAMPLE_TEXTURE2D(_BumpMap,sampler_BumpMap,input.uv),_BumpScale);
                real3 normalWS = mul(normalTS, real3x3(input.tangentWS.xyz, bitangent.xyz, input.normalWS.xyz)); 
                // real3 normalWS = normalize(input.normalWS);
                Light mainLight = GetMainLight(); // 主光源
                real3 lightColor = mainLight.color; // 主光源颜色
                 
                real3 lightDir = normalize(mainLight.direction); // 主光源方向
                real3 albedo = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, input.uv) * _BaseColor;
                   
                real3 ambient = SampleSH(normalWS) * albedo; // 环境光
                   
                real3 diffuse = saturate(dot(lightDir,normalWS)) * lightColor * albedo; // 漫反射

                output = real4(ambient+diffuse,1.0);
                
                #if _SpecColorToggle
                real3 viewDirectionWS = SafeNormalize(GetCameraPositionWS() - positionWS); // safe防止分母为0
                real3 h = SafeNormalize(viewDirectionWS + lightDir);
                real3 specular = pow(saturate(dot(h, input.normalWS)), _Smoothness) * lightColor * saturate(_SpecColor); // 高光
                output = real4(ambient + diffuse + specular, 1.0);
                #endif
               
                // // return real4(ambient + diffuse + specular, 1.0);
                # ifdef _AdditionalLights
                int lightCount = GetAdditionalLightsCount();
                for(int index = 0; index < lightCount; index++)
                {
                    Light light = GetAdditionalLight(index, positionWS);     
                    real3 lightColorx = light.color;
                    real3 lightDirx = normalize(light.direction);
                    albedo += SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, input.uv) * _BaseColor;
                    diffuse += saturate(dot(lightDirx,normalWS)) * lightColorx * albedo;
                  
                    #if _SpecColorToggle
                    real3 hx = SafeNormalize(viewDirectionWS + lightDirx);
                    specular += pow(saturate(dot(hx, input.normalWS)), _Smoothness) * lightColorx * saturate(_SpecColor);
                    #endif
                    
                }
                output = real4(ambient+diffuse,1.0);
                #if _SpecColorToggle
                output = real4(ambient + diffuse + specular, 1.0);
                #endif
               
                #endif
                return output;
                }
            ENDHLSL
        }
       // 一般在Buit-In管线里,我们只需要最后FallBack返回到系统的Diffuse Shader,管线就会去里面找到他处理阴影的Pass。但是在URP中,一个Shader中的所有Pass需要有一致的CBuffer,否则便会打破SRP Batcher,影响效率。
       // 而系统默认SimpleLit的Shader中的CBuffer内容和我的写的并不一致,所以我们需要把它阴影处理的Pass复制一份,并且删掉其中引用的SimpleLitInput.hlsl(相关CBuffer的声明在这里面)
          Pass
        {
            Name "ShadowCaster"
            Tags{"LightMode" = "ShadowCaster"}

            ZWrite On
            ZTest LEqual
            ColorMask 0
            Cull[_Cull]

            HLSLPROGRAM
            #pragma exclude_renderers gles gles3 glcore
            #pragma target 4.5

            // -------------------------------------
            // Material Keywords
            #pragma shader_feature_local_fragment _ALPHATEST_ON
            #pragma shader_feature_local_fragment _GLOSSINESS_FROM_BASE_ALPHA

            //--------------------------------------
            // GPU Instancing
            #pragma multi_compile_instancing
            #pragma multi_compile _ DOTS_INSTANCING_ON

            #pragma vertex ShadowPassVertex
            #pragma fragment ShadowPassFragment

            #include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
            #include "Packages/com.unity.render-pipelines.universal/Shaders/ShadowCasterPass.hlsl"
            ENDHLSL
        }
    }
  
}

8.透明度裁切Alpha Clipping

声明属性Properties

_Cutoff("Cutoff",float)=0.5

片元着色器中计算

half4 baseMap = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, input.uv);
clip(baseMap.a-_Cutoff);

注意baseMap的类型,需要是xxx4,才能有变量a

9.法线贴图

如果引用urp 的shader库,名字需要一致

com.unity.render-pipelines.universal,unity,游戏引擎,图形渲染

必要参数

com.unity.render-pipelines.universal,unity,游戏引擎,图形渲染

顶点着色器

com.unity.render-pipelines.universal,unity,游戏引擎,图形渲染

片元着色器

com.unity.render-pipelines.universal,unity,游戏引擎,图形渲染

 (不计算时法线贴图时,直接real3 normalWS = normalize(input.normalWS);文章来源地址https://www.toymoban.com/news/detail-795846.html

到了这里,关于Unity URP Shader(HLSL)踩坑日记(一)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • Unity Shader从内置渲染管线迁移到URP

    Unity 在URP中将shader更新为了HLSL语言,使用build-in shader 无法直接在URP中使用 这里讲一下关于shader的更新方法 参考 From Built-in to URP Tags 添加 \\\"RenderPipeline\\\" = \\\"UniversalPipeline\\\" CGPROGRAM ENDCG 改变为 HLSLPROGRAM ENDHLSL #include \\\"UnityCG.cginc\\\" 更改为 #include \\\"Packages/com.unity.render-pipelines.universal/Sh

    2024年02月05日
    浏览(29)
  • Unity URP Shader “Redefinition of _Time“ error

    强烈建议先尝试阅读本文之后自行解决:https://zhuanlan.zhihu.com/p/360566324 我这里记录一下我的思路: 首先检查URP升级是否正确,主要看Asset是否设置,ShaderGraph表现是否正常 尝试排除是否是未定义宏导致的问题,主要是对比ShaderGraph自动生成的代码 确认自己的代码是否使用了

    2024年02月15日
    浏览(26)
  • unity URP 利用particle system制作简单的shader交互

    首先这里制作了一个简单交互,使用shader grapgh,根据计算距离和变化数值的差实现交互后的扩散,同时计算消散遮罩让它逐渐谈去。 将他赋予材质物体,根据脚本传入位置和逐渐变化的大小后,呈现这样的效果。 但是,shader graph这样的工具,在做这种效果非常快的同时,也

    2024年02月07日
    浏览(26)
  • Unity Mac踩坑日记

    1、读取外部文件夹使用IO,读取StreamingAsset或者Unity定义文件夹或者服务器文件使用www或者UnityRequest 2、mac下使用www 需要添加前缀:\\\"file://\\\" 3、Mac下的Rider很好用,断点调试也很方便 4、改变文件编码格式,使用vscode通过编码保存可以保存为带BOM格式的UTF8文件在Mac上 5、Rider快捷

    2024年02月11日
    浏览(23)
  • unity build-in 渲染管线升级urp渲染 shader篇

            由于工作原因需要对项目进行升级,从build-in渲染管线升级到urp渲染管线,我自己对应的unity版本是2018.版本升级到2021.3.2版本,由于最近几年unity版本升级比较快,个体版本差异有所不同,如遇与版本不一致问题敬请谅解。以下是根据官网等系列网站整理的内容

    2023年04月16日
    浏览(39)
  • 《Unity的URP项目中使用自定义shader导致材质消失的解决办法》

            在Unity中使用URP时,会有需求使用自定义的一些shader来实现特殊效果,这时如果我们直接使用新建材质与无光照着色器(Unlit shader),可能会发生一个对于新手而言意料之外的问题—— 物体!消失了!         打开你正在使用的的 通用渲染器(Universal Rendere

    2024年02月06日
    浏览(41)
  • Unity Shader 学习笔记(4)URP渲染管线带阴影PBR-Shader模板 -- 新增可自定义阴影颜色

    材质面板截图 功能实现(URP渲染管线下): 1、进一步优化Shader结构和算法; 2、包含PBR材质; 3、投射和接收阴影,并升级 支持自定义阴影颜色 ; 4、支持点光源照射(但不支持点光源阴影)。 通用渲染截图 自定义阴影颜色截图 完整代码: 写在最后: 1、在我的上一篇文

    2024年02月12日
    浏览(27)
  • 【Unity Shader Graph URP渲染管线下的自定义半透明效果_半透明案例分享】

    URP的渲染管线下 在项目设置里找到“Graphic” 找到URP Asset文件 索引到Renderer List文件——“ForwardRenderer” 在这个“ForwardRenderer”文件里找到“Add Renderer Feature” 添加一个渲染对象,类似下图:Render Object (Experimental) 如图设置,将“Event”设置成 AfterRenderingSkybox ,然后“Layer M

    2024年02月09日
    浏览(44)
  • 【unity】URP的shader开发中支持多光源,_ADDITIONAL_LIGHTS_VERTEX 和 _ADDITIONAL_LIGHTS 区别

    项目里有一个其他同事实现的shader,美术那边希望能支持多个光源, 我一看代码里面, frag 函数里已经实现了   代码也加了:             #pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS 材质里加了这个keyword还是没起作用,   若宏控制注了有效。  一开始没搞明白

    2024年02月11日
    浏览(35)
  • 【Unity 踩坑系列】项目升级URP/HDRP渲染管线时如何解决材质丢失问题 (模型全部为粉红色)

    在我们创建项目时候如果我们一开始使用的是默认内置渲染管线,后期项目需要升级到URP或者HDRP渲染管线时有可能会出现预制体材质丢失的问题(原因是大部分资源的预制体在Unity官方推荐使用URP渲染管线之前,都只是使用默认内置管线的材质。所以并不适配现在的URP渲染管

    2024年02月16日
    浏览(38)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包