Unity 从BuildIn升级到URP以及常用的效果

一、CG->HLSL

CGPROGRAM->HLSLPROGRAM

ENDCG->ENDHLSL

CGINCLUDE->HLSLINCLUDE

二、灯光模式

"LightMode"="ForwardBase->UniversalForward"

删掉以下内容:

#define UNITY_PASS_FORWARDBASE
#pragma multi_compile_fwdbase

URP可以使用的灯光模式,有三种:

"UniversalForward"
"LightweightForward"
"SRPDefaultUnlit"

三、一些常用的方法(修改)

1、把#include "UnityCG.cginc"

改成

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

2、把#include "Lighting.cginc"

改成

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

3、o.pos = UnityObjectToClipPos( v.vertex );

改成

VertexPositionInputs vertexInput = GetVertexPositionInputs(v.vertex.xyz);

o.pos = vertexInput.positionCS;

或者

o.pos = TransformObjectToHClip(v.vertex.xyz);

4、o.normalDir = UnityObjectToWorldNormal(v.normal);

改成

VertexNormalInputs vertexNormalInput = GetVertexNormalInputs(v.normal);

o.normalDir = vertexNormalInput.normalWS;

或者

o.normalDir = TransformObjectToWorldNormal(v.normal);

5、灯光方向和灯光颜色

_WorldSpaceLightPos0.xyz改成

vert函数里:

o.shadowCoord = GetShadowCoord(vertexInput);

frag函数里:

Light mainLight = mainLight = GetMainLight(i.shadowCoord);

float3 lightDirection = mainLight.direction;

_LightColor0 改成 mainLight.color

6、把fixed 定义的变量都改成float或者half 的。

比如 fixed4 (finalColor,1)改成float4 (finalColor,1)

四、阴影

如何在unity的URP下实现阴影_unity urp阴影-CSDN博客

五、深度图

Unity URP 获取深度图_urp采样深度图-CSDN博客

六、多Pass

如何在Unity的URP下使用多pass(multi pass)_urp 多pass-CSDN博客

七、雾效

1、添加雾效变体

#pragma multi_compile_fog

2、在Varying结构体中添加雾效因子

float fogCoord : TEXCOORD2;

3、在顶点着色器中,我们使用内置函数得到雾效因子

o.fogCoord = ComputeFogFactor(o.vertexCS.z);

4、在片元着色器中,把输出颜色 和 雾效因子混合输出

col.rgb = MixFog(col,i.fogCoord);

八、环境光

BuildIn

fixed3 ambient = UNITY_LIGHTMODEL_AMBIENT.rgb

URP

half3 ambient = half3(unity_SHAr.w, unity_SHAg.w, unity_SHAb.w);

九、GPUInstancing

Unity URP 中 GPU Instancing的使用_urp gpuinstance-CSDN博客

相关推荐
摸鱼的春哥7 小时前
10年3次大失败,他从“罪人”输成了中年人的“白月光”
游戏
SmalBox9 小时前
【光照】Unity中的[经验模型]
unity·渲染
萘柰奈10 小时前
Unity学习----【进阶】TextMeshPro学习(三)--进阶知识点(TMP基础设置,材质球相关,两个辅助工具类)
学习·unity
Yasin Chen10 小时前
Unity UI坐标说明
ui·unity
gis分享者11 小时前
学习threejs,使用自定义GLSL 着色器,实现水面、粒子特效
threejs·着色器·glsl·粒子·shadermaterial·unrealbloompass·水面
应用市场11 小时前
无人机姿态控制系统详解与实现
游戏引擎·cocos2d
陈言必行16 小时前
Unity 性能优化 之 编辑器创建资源优化( 工作流 | 场景 | 预制体)
unity·编辑器·游戏引擎
1uther21 小时前
Unity核心概念⑨:Screen
开发语言·游戏·unity·c#·游戏引擎
2501_918126911 天前
用html5写一个flappybird游戏
css·游戏·html5
死也不注释1 天前
【Unity UGUI 交互组件——Slider(7)】
unity·游戏引擎·交互