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

相关推荐
xiezhr43 分钟前
米哈游36岁程序员被曝复工当晚猝死出租屋内
游戏·程序员·游戏开发
爱搞虚幻的阿恺4 天前
Niagara粒子系统-超炫酷的闪电特效(加餐 纸牌螺旋上升效果)
游戏·游戏引擎
_Li.4 天前
Simulink - 6DOF (Euler Angles)
人工智能·算法·机器学习·游戏引擎·cocos2d
智算菩萨4 天前
儿童游乐空间的双维建构:室内淘气堡与室外亲子乐园的发展学理、功能分野与协同育人机制研究
游戏·游戏策划
weixin_424294674 天前
Unity 调用Steamworks API 的 SteamUserStats.RequestCurrentStats()报错
unity·游戏引擎·steamwork
HoFunGames4 天前
Unity小地图,Easy Minimap System MT-GPS插件
unity·游戏引擎
marteker4 天前
房地产市场平台Zillow与《魔兽世界》合作展示游戏内房屋
游戏
wy3258643644 天前
Unity 新输入系统InputSystem(基本操作)
unity·c#·游戏引擎
WarPigs4 天前
着色器multi_compile笔记
unity·着色器
wanhengidc4 天前
云手机 打造云端算力
运维·服务器·网络·游戏·智能手机