赞
踩
Unity引擎的渲染管线主要分为"渲染核心库"与"渲染策略"两个部分, “渲染核心库”是Unity把基于OpenGL/DirectX把渲染相关的接口函数封装成API,这部分Unity引擎写好后作为核心的API渲染库。”渲染策略”指的是Unity引擎绘制整个游戏场景的时候,如何处理多相机,多光源,阴影投射,物体绘制,雾,自发光等。这个就叫做渲染策略,渲染管线基于一种渲染策略,调用渲染核心库中的API,把整个游戏场景绘制出来。
渲染管线通过执行 剔除、渲染、后处理 来获取场景的内容,并将这些内容显示在屏幕上。不同的渲染管线具有不同的功能和性能特征,并且适用于不同的游戏、应用程序和平台。
URP相对内置管线的优点:
与默认管线功能对比见URP与内置渲染管线功能对照表
URP与unity版本对应:
Built-in | URP |
---|---|
CGPROGRAM、HLSLPROGRAM | HLSLPROGRAM |
ENDCG、ENDHLSL | ENDHLSL |
CGINCLUDE、HLSLINCLUDE | HLSLINCLUDE |
TEXTURE2D(_BaseMap);
SAMPLER(sampler_BaseMap);
CBUFFER_START(UnityPerMaterial)
half4 _BaseColor;
float4 _BaseMap_ST;
CBUFFER_END
\ | Built-in | URP |
---|---|---|
Core | Unity.cginc | Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl |
Light | AutoLight.cginc | Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl |
Shadows | AutoLight.cginc | Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl |
Surface shaders | Lighting.cginc | URP内没有,可以参考该github项目 |
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
Built-in | URP |
---|---|
ForwardBase | UniversalForward |
ForwardAdd | 移除,开启关键字_ADDITIONAL_LIGHTS解决 |
Deferred 以及相关 | URP12.0支持 |
Vertex and related | 移除 |
ShadowCaster | ShadowCaster |
MotionVectors | 暂不支持 |
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE
#pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS
#pragma multi_compile _ _ADDITIONAL_LIGHT_SHADOWS
#pragma multi_compile _ _SHADOWS_SOFT
#pragma multi_compile _ _MIXED_LIGHTING_SUBTRACTIVE
Built-in | URP |
---|---|
UNITY_PROJ_COORD(a) | 移除,改用 a.xy/a.w |
UNITY_INITIALIZE_OUTPUT(type, name) | ZERO_INITIALIZE(type, name) |
参考Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl
Built-in | URP |
---|---|
UNITY_DECLARE_SHADOWMAP(tex) | TEXTURE2D_SHADOW_PARAM(textureName, samplerName) |
UNITY_SAMPLE_SHADOW(tex, uv) | SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord3) |
UNITY_SAMPLE_SHADOW_PROJ(tex, uv) | SAMPLE_TEXTURE2D_SHADOW(textureName, samplerName, coord4.xyz/coord4.w) |
UNITY_SHADOW_COORDS(x) | float4 shadowCoord : TEXCOORD##x |
TRANSFER_SHADOW(a) | a.shadowCoord = TransformWorldToShadowCoord(worldSpacePosition) |
SHADOWS_SCREEN | 移除了 |
Built-in | URP |
---|---|
UNITY_DECLARE_TEX2D(name) | TEXTURE2D(textureName); SAMPLER(samplerName); |
UNITY_DECLARE_TEX2D_NOSAMPLER(name) | TEXTURE2D(textureName); |
UNITY_DECLARE_TEX2DARRAY(name) | TEXTURE2D_ARRAY(textureName); SAMPLER(samplerName); |
UNITY_SAMPLE_TEX2D(name, uv) | SAMPLE_TEXTURE2D(textureName, samplerName, coord2) |
UNITY_SAMPLE_TEX2D_SAMPLER(name, samplername, uv) | SAMPLE_TEXTURE2D(textureName, samplerName, coord2) |
UNITY_SAMPLE_TEX2DARRAY(name, uv) | SAMPLE_TEXTURE2D_ARRAY(textureName, samplerName, coord2, index) |
UNITY_SAMPLE_TEX2DARRAY_LOD(name, uv, lod) | SAMPLE_TEXTURE2D_ARRAY_LOD(textureName, samplerName, coord2, index, lod) |
UNITY_INITIALIZE_OUTPUT(name) | ZERO_INITIALIZE(name) |
Built-in | URP |
---|---|
UNITY_LIGHTMODEL_AMBIENT | half3(unity_SHAr.w,unity_SHAr.w,unity_SHAr.w); |
UNITY_FOG_COORDS(x) | 用float fogCoord : TEXCOORD##x; |
UNITY_TRANSFER_FOG(o, outpos) | o.fogCoord = ComputeFogFactor(clipSpacePosition.z); |
UNITY_APPLY_FOG(coord, col) | color = MixFog(color, i.fogCoord); |
Built-in | URP |
---|---|
float4 UnityObjectToClipPos(float3 pos) | float4 TransformObjectToHClip(float3 positionOS) |
float4 UnityWorldToClipPos(float3 pos) | float4 TransformWorldToHClip(float3 positionWS) |
float3 UnityObjectToViewPos(float3 pos) | TransformWorldToView(TransformObjectToWorld(positionOS)) |
float3 UnityObjectToWorldNormal(in float3 norm) | float3 TransformObjectToWorldNormal(float3 normalOS,bool doNormalize = true) |
float3 UnityWorldSpaceViewDir (float4 v) | _WorldSpaceCameraPos.xyz - positionWS |
float3 UnityObjectToWorldDir (float4 v) | float3 TransformObjectToWorldDir(real3 dirOS) |
Built-in | URP |
---|---|
float3 ObjSpaceViewDir (float4 v) | TransformWorldToObject(GetCameraPositionWS()) - objectSpacePosition; |
float2 ParallaxOffset (half h, half height, half3 viewDir) | 移除了。可以从UnityCG.cginc复制过来 |
fixed Luminance (fixed3 c) | real Luminance(real3 linearRgb) |
fixed3 DecodeLightmap (fixed4 color) | real3 DecodeLightmap(real4 encodedIlluminance, real4 decodeInstructions) |
float4 EncodeFloatRGBA (float v) | 移除了。可以从UnityCG.cginc复制过来 |
float DecodeFloatRGBA (float4 enc) | 移除了。可以从UnityCG.cginc复制过来 |
float2 EncodeFloatRG (float v) | 移除了。可以从UnityCG.cginc复制过来 |
float DecodeFloatRG (float2 enc) | 移除了。可以从UnityCG.cginc复制过来 |
float2 EncodeViewNormalStereo (float3 n) | 移除了。可以从UnityCG.cginc复制过来 |
float3 DecodeViewNormalStereo (float4 enc4) | 移除了。可以从UnityCG.cginc复制过来 |
Built-in | URP |
---|---|
float3 WorldSpaceLightDir(float4 v) | _MainLightPosition.xyz - TransformObjectToWorld(objectSpacePosition) |
float3 ObjSpaceLightDir (float4 v) | TransformWorldToObject(_MainLightPosition.xyz) - objectSpacePosition |
float3 Shade4PointLights (…) | 用half3 VertexLighting(float3 positionWS, half3 normalWS) |
Built-in | URP |
---|---|
float4 ComputeScreenPos (float4 clipPos) | float4 ComputeScreenPos(float4 positionCS) |
float4 ComputeGrabScreenPos (float4 clipPos) | 移除了 |
Built-in | URP |
---|---|
float3 ShadeVertexLights (float4 vertex, float3 normal) | 用half3(unity_SHAr.w, unity_SHAg.w, unity_SHAb.w) + VertexLighting(…) |
可直接使用 _CameraDepthTexture来采样深度纹理,也可使用SampleSceneDepth(…) 和 LoadSceneDepth(…)来采样。
Built-in | URP |
---|---|
LinearEyeDepth (sceneZ) | LinearEyeDepth(sceneZ, _ZBufferParams) |
Linear01Depth (sceneZ) | Linear01Depth(sceneZ, _ZBufferParams) |
Built-in | URP |
---|---|
shadeSH9 (float4 normal) | SampleSH(normal) |
unity_ColorSpaceLuminance | 用Luminance() |
Built-in | URP |
---|---|
_LightColor0 | _MainLightColor |
_WorldSpaceLightPos0 | _MainLightPosition |
_LightMatrix0 | 移除了。目前尚不支持 |
unity_4LightPosX0, unity_4LightPosY0, unity_4LightPosZ0 | 在URP中,其他光源存储在数组/缓冲区中(取决于平台)。使用Light GetAdditionalLight(uint i, float3 positionWS)获取光源信息 |
unity_4LightAtten0 | 同上 |
unity_LightColor | 同上) |
unity_WorldToShadow | float4x4 _MainLightWorldToShadow[MAX_SHADOW_CASCADES + 1] 或者_AdditionalLightsWorldToShadow[MAX_VISIBLE_LIGHTS] |
使用循环所有其他灯光–GetAdditionalLight(),查询其他灯光计数–GetAdditionalLightsCount()。
beginCameraRendering(ScriptableRenderContext context, Camera camera)
endCameraRendering(ScriptableRenderContext context, Camera camera)
beginFrameRendering(ScriptableRenderContext context,Camera[] cameras)
endFrameRendering(ScriptableRenderContext context,Camera[] cameras)
void OnEnable() { RenderPipelineManager.beginCameraRendering += MyCameraRendering; } void OnDisable() { RenderPipelineManager.beginCameraRendering -= MyCameraRendering; } void MyCameraRendering(ScriptableRenderContext context, Camera camera) { ... if(camera == myEffectCamera) { ... UniversalRenderPipeline.RenderSingleCamera(context, camera); } ... }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。