Unity SRP初识之URP

URP是Unity基于SRP提供的兼顾表现与性能的渲染管线。URP前身命名为LWRP(轻量级渲染管线),后更名为URP。

URP已包含在新建工程的工程模板中

  • URP使用简化的基于物理的照明和材质来实现高质量的快速渲染。
  • URP使用单遍正向渲染,以在多个平台上优化实时性能

官方配置说明文档:

https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@11.0/manual/universalrp-asset.html

BaseCamera与Overlay相机

  • URP支持两种RenderType不同的相机类型:Base与Overlay
  • Overlay相机渲染在Base相机在上,用于实现UI上的3D显示
  • Overlay相机必须加到BaseCamera上的Stack上,才能生效
  • Overlay相机不能应用post-processing

Post-processing

  • UPR实现了自己的后处理:Volume组件
  • 手机友好的后处理
    • Bloom (with High Quality Filtering disabled)
    • Chromatic Aberration 色差
    • Color Grading
    • Lens Distortion 镜头失真
    • Vignette 插图
  • 景深:
    • 在低端机上使用高斯景深( Gaussian Depth of Field)
    • 在桌面平台使用散景景深(Bokeh Depth of Field)
  • 抗锯齿:建议使用FXAA

Shader与材质球

官方文档

  • URP使用与内置渲染管线不一致的着色方法,因此内置光照与自定义光照着色器(Lit Shader)不能在URP中使用。URP有自己一套Lit Shader。
  • 内置管线的Unlit Shader(非光照Shader)仍然可以在URP中使用
  • 可以在所有平台使用URP的Lit Shader。Lit Shader基于PBR。在URP中,Standard Shader和Standard (Specular setup) Shaders 会被指向URP的Lit Shader
  • 非PBR可以使用Simple Lit shader,
  • 不需要实时光照,可以使用Baked Lit Shader

// This shader draws a texture on the mesh.

Shader "Example/URPUnlitShaderTexture"

{

    // The _BaseMap variable is visible in the Material's Inspector, as a field

    // called Base Map.

    Properties

    {

        _BaseMap("Base Map", 2D) = "white"

    }

    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;

                // The uv variable contains the UV coordinate on the texture for the

                // given vertex.

                float2 uv           : TEXCOORD0;

            };

            struct Varyings

            {

                float4 positionHCS  : SV_POSITION;

                // The uv variable contains the UV coordinate on the texture for the

                // given vertex.

                float2 uv           : TEXCOORD0;

            };

            // This macro declares _BaseMap as a Texture2D object.

            TEXTURE2D(_BaseMap);

            // This macro declares the sampler for the _BaseMap texture.

            SAMPLER(sampler_BaseMap);

            CBUFFER_START(UnityPerMaterial)

                // The following line declares the _BaseMap_ST variable, so that you

                // can use the _BaseMap variable in the fragment shader. The _ST

                // suffix is necessary for the tiling and offset function to work.

                float4 _BaseMap_ST;

            CBUFFER_END

            Varyings vert(Attributes IN)

            {

                Varyings OUT;

                OUT.positionHCS = TransformObjectToHClip(IN.positionOS.xyz);

                // The TRANSFORM_TEX macro performs the tiling and offset

                // transformation.

                OUT.uv = TRANSFORM_TEX(IN.uv, _BaseMap);

                return OUT;

            }

            half4 frag(Varyings IN) : SV_Target

            {

                // The SAMPLE_TEXTURE2D marco samples the texture with the given

                // sampler.

                half4 color = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, IN.uv);

                return color;

            }

            ENDHLSL

        }

    }

}

  • 需要额外声明TextureObj

TEXTURE2D(_BaseMap);

  • 贴图采样器的声明

SAMPLER(sampler_BaseMap);

  • CBUFFER

CBUFFER_START(UnityPerMaterial)

    // The following line declares the _BaseMap_ST variable, so that you

    // can use the _BaseMap variable in the fragment shader. The _ST

    // suffix is necessary for the tiling and offset function to work.

    float4 _BaseMap_ST;

CBUFFER_END

  • 顶点函数中物体空间到裁剪空间的转换

OUT.positionHCS = TransformObjectToHClip(IN.positionOS.xyz);

  • UV的计算

OUT.uv = TRANSFORM_TEX(IN.uv, _BaseMap);

  • 贴图采样

half4 color = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, IN.uv);

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值