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博客

相关推荐
aaaffaewrerewrwer12 小时前
一个真正可玩、可分享、可自定义的在线单词搜索游戏网站(Word Search Puzzles)
游戏·word
tealcwu16 小时前
【Unity实战】Unity IAP 4.x 在 Windows Store (UWP) 平台上的实现指南
windows·unity·游戏引擎
玉夏16 小时前
【Shader基础】CG/HLSL 基础语法
unity·shader
LongJ_Sir16 小时前
Cesium-鼠标传入着色器中并进行交互
javascript·着色器
wjql217 小时前
少女前线蓝蝶契约体力恢复时间 少女前线蓝蝶契约体力怎么恢复
游戏
wjql219 小时前
高能探宝团零氪阵容推荐 高能探宝团零氪阵容怎么搭配
游戏
垂葛酒肝汤19 小时前
Unity的UGUI的坐标
unity
寰宇的行者19 小时前
我用Hermes Agent一个月:自动写文章、管股票、看游戏截图,成本账一次算清
游戏
sensen_kiss19 小时前
CPT306 Principles of Computer Games Design 电脑游戏设计原理 Pt.8 Game AI(游戏里的“人工智能系统”)
人工智能·游戏
winlife_19 小时前
让 AI 写敌人状态机,并用脚本化场景验证状态转换正确:funplay-unity-mcp 实战
人工智能·unity·游戏引擎·ai编程·状态机·mcp