浏览代码
Merge remote-tracking branch 'origin/demo-work-customrenderer' into merge-branch
/demo-work-customrenderer
Merge remote-tracking branch 'origin/demo-work-customrenderer' into merge-branch
/demo-work-customrenderer
Mike Geig
5 年前
当前提交
95da86b0
共有 20 个文件被更改,包括 638 次插入 和 17 次删除
-
2Assets/Data/UniversalRP/PipelineAsset.asset
-
31Assets/Data/UniversalRP/CustomBoatDemoRenderer.asset
-
8Assets/Data/UniversalRP/CustomBoatDemoRenderer.asset.meta
-
8Assets/Rendering.meta
-
113Packages/com.verasl.water-system/CausticsModified.mat
-
8Packages/com.verasl.water-system/CausticsModified.mat.meta
-
95Packages/com.verasl.water-system/Shaders/CausticsModified.shader
-
9Packages/com.verasl.water-system/Shaders/CausticsModified.shader.meta
-
11Assets/Rendering/BoatRenderer.cs.meta
-
41Assets/Rendering/BoatRendererData.cs
-
11Assets/Rendering/BoatRendererData.cs.meta
-
11Assets/Rendering/MainRenderPass.cs.meta
-
227Assets/Rendering/BoatRenderer.cs
-
64Assets/Rendering/MainRenderPass.cs
-
8Assets/Shaders/PackedPBR.meta
-
8Assets/EntityCache.meta
|
|||
%YAML 1.1 |
|||
%TAG !u! tag:unity3d.com,2011: |
|||
--- !u!114 &11400000 |
|||
MonoBehaviour: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInstance: {fileID: 0} |
|||
m_PrefabAsset: {fileID: 0} |
|||
m_GameObject: {fileID: 0} |
|||
m_Enabled: 1 |
|||
m_EditorHideFlags: 0 |
|||
m_Script: {fileID: 11500000, guid: 580815c7b01f60e429065cd2e33f7e1d, type: 3} |
|||
m_Name: CustomBoatDemoRenderer |
|||
m_EditorClassIdentifier: |
|||
m_RendererFeatures: |
|||
- {fileID: 6778594283966551180} |
|||
- {fileID: 0} |
|||
postProcessData: {fileID: 11400000, guid: 41439944d30ece34e96484bdb6645b55, type: 2} |
|||
caustics: {fileID: 2100000, guid: f09f40ad472134250a9e0ad60dd212f0, type: 2} |
|||
--- !u!114 &6778594283966551180 |
|||
MonoBehaviour: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInstance: {fileID: 0} |
|||
m_PrefabAsset: {fileID: 0} |
|||
m_GameObject: {fileID: 0} |
|||
m_Enabled: 1 |
|||
m_EditorHideFlags: 0 |
|||
m_Script: {fileID: 11500000, guid: fc3f76324391a408d9c0770ca6fcb666, type: 3} |
|||
m_Name: WaterFX |
|||
m_EditorClassIdentifier: |
|
|||
fileFormatVersion: 2 |
|||
guid: 9bab193ea15b8314184732322e8c9073 |
|||
NativeFormatImporter: |
|||
externalObjects: {} |
|||
mainObjectFileID: 0 |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: cf5d23597296ed547841632296585938 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
%YAML 1.1 |
|||
%TAG !u! tag:unity3d.com,2011: |
|||
--- !u!114 &-3341692864896818629 |
|||
MonoBehaviour: |
|||
m_ObjectHideFlags: 11 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInstance: {fileID: 0} |
|||
m_PrefabAsset: {fileID: 0} |
|||
m_GameObject: {fileID: 0} |
|||
m_Enabled: 1 |
|||
m_EditorHideFlags: 0 |
|||
m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3} |
|||
m_Name: |
|||
m_EditorClassIdentifier: |
|||
version: 1 |
|||
--- !u!21 &2100000 |
|||
Material: |
|||
serializedVersion: 6 |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInstance: {fileID: 0} |
|||
m_PrefabAsset: {fileID: 0} |
|||
m_Name: CausticsModified |
|||
m_Shader: {fileID: 4800000, guid: a7e6cd2d14dfc49d188a4707edf9a870, type: 3} |
|||
m_ShaderKeywords: |
|||
m_LightmapFlags: 4 |
|||
m_EnableInstancingVariants: 0 |
|||
m_DoubleSidedGI: 0 |
|||
m_CustomRenderQueue: -1 |
|||
stringTagMap: {} |
|||
disabledShaderPasses: [] |
|||
m_SavedProperties: |
|||
serializedVersion: 3 |
|||
m_TexEnvs: |
|||
- Texture2DArray_29EA5301: |
|||
m_Texture: {fileID: 18700000, guid: 2bf4e75081aab4b5f88bfb7069f598ac, type: 2} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- Texture2D_A294F6AA: |
|||
m_Texture: {fileID: 2800000, guid: f395b7d64f44848c6a3cba1f1173fe90, type: 3} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _BaseMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _BumpMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _CameraDepthTexture: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _CausticMap: |
|||
m_Texture: {fileID: 2800000, guid: f395b7d64f44848c6a3cba1f1173fe90, type: 3} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _EmissionMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _MainTex: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _MetallicGlossMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _OcclusionMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _SpecGlossMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
m_Floats: |
|||
- Vector1_CD857B77: 0.47 |
|||
- Vector1_DC11883E: 0.5 |
|||
- Vector1_E85F4D08: -0.15 |
|||
- Vector1_EA2AE021: 0.4 |
|||
- Vector1_F3303B3C: 0.5 |
|||
- _AlphaClip: 0 |
|||
- _Blend: 0 |
|||
- _BlendDistance: 2 |
|||
- _BumpScale: 1 |
|||
- _Cull: 2 |
|||
- _Cutoff: 0.5 |
|||
- _DstBlend: 0 |
|||
- _EnvironmentReflections: 1 |
|||
- _GlossMapScale: 0 |
|||
- _Glossiness: 0 |
|||
- _GlossyReflections: 0 |
|||
- _Metallic: 0 |
|||
- _OcclusionStrength: 1 |
|||
- _QueueOffset: 0 |
|||
- _ReceiveShadows: 1 |
|||
- _Size: 0.25 |
|||
- _Smoothness: 0.5 |
|||
- _SmoothnessTextureChannel: 0 |
|||
- _SpecularHighlights: 1 |
|||
- _SrcBlend: 1 |
|||
- _Surface: 0 |
|||
- _WaterLevel: -0.625 |
|||
- _WorkflowMode: 1 |
|||
- _ZWrite: 1 |
|||
m_Colors: |
|||
- _BaseColor: {r: 0.5, g: 0.5, b: 0.5, a: 1} |
|||
- _Color: {r: 0.5, g: 0.5, b: 0.5, a: 1} |
|||
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1} |
|||
- _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1} |
|
|||
fileFormatVersion: 2 |
|||
guid: f09f40ad472134250a9e0ad60dd212f0 |
|||
NativeFormatImporter: |
|||
externalObjects: {} |
|||
mainObjectFileID: 2100000 |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
Shader "Hidden/BoatAttack/CausticsModified" |
|||
{ |
|||
Properties |
|||
{ |
|||
//Vector1_F3303B3C("Speed", Float) = 0.5 |
|||
_Size("Size", Float) = 0.5 |
|||
[NoScaleOffset]_CausticMap("Caustics", 2D) = "white" {} |
|||
_WaterLevel("WaterLevel", Float) = -0.25 |
|||
_BlendDistance("BlendDistance", Float) = 0.1 |
|||
//Vector1_CD857B77("CausticsRGB Split", Float) = 2 |
|||
} |
|||
SubShader |
|||
{ |
|||
// No culling or depth |
|||
Cull Off |
|||
ZWrite Off |
|||
ZTest Always |
|||
|
|||
Pass |
|||
{ |
|||
Blend DstColor Zero, One Zero |
|||
HLSLPROGRAM |
|||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" |
|||
|
|||
#pragma vertex vert |
|||
#pragma fragment frag |
|||
|
|||
struct Attributes |
|||
{ |
|||
float4 positionOS : POSITION; |
|||
float2 uv : TEXCOORD0; |
|||
}; |
|||
|
|||
struct Varyings |
|||
{ |
|||
float2 uv : TEXCOORD0; |
|||
float4 positionOS : SV_POSITION; |
|||
}; |
|||
|
|||
TEXTURE2D(_CameraDepthTexture); SAMPLER(sampler_CameraDepthTexture); |
|||
TEXTURE2D(_CausticMap); SAMPLER(sampler_CausticMap); |
|||
|
|||
half _Size; |
|||
half _WaterLevel; |
|||
half _BlendDistance; |
|||
|
|||
float3 ReconstructWorldPos(half2 screenPos, float depth) |
|||
{ |
|||
// World Pos reconstriction |
|||
float4 raw = mul(UNITY_MATRIX_I_VP, float4(screenPos * 2 - 1, depth, 1)); |
|||
float3 worldPos = raw.rgb / raw.a; |
|||
return worldPos; |
|||
} |
|||
|
|||
// Can be done per-vertex |
|||
float2 CausticUVs(float2 rawUV, float2 offset) |
|||
{ |
|||
//anim |
|||
float2 uv = rawUV * _Size + float2(_Time.y, _Time.x) * 0.1; |
|||
return uv + offset * 0.25; |
|||
} |
|||
|
|||
Varyings vert (Attributes input) |
|||
{ |
|||
Varyings output; |
|||
output.positionOS = float4(input.positionOS.xyz, 1.0); |
|||
output.uv = float2(input.uv.x, 1.0 - input.uv.y); |
|||
return output; |
|||
} |
|||
|
|||
sampler2D _MainTex; |
|||
|
|||
real4 frag (Varyings input) : SV_Target |
|||
{ |
|||
real depth = SAMPLE_DEPTH_TEXTURE( _CameraDepthTexture, sampler_CameraDepthTexture, input.uv); |
|||
|
|||
float3 worldPos = ReconstructWorldPos(input.uv, depth); |
|||
float waveOffset = SAMPLE_TEXTURE2D(_CausticMap, sampler_CausticMap, worldPos.xz * 0.025 + _Time.x * 0.25).w - 0.5; |
|||
|
|||
float2 causticUV = CausticUVs(worldPos.xz, waveOffset); |
|||
|
|||
float3 caustics = SAMPLE_TEXTURE2D(_CausticMap, sampler_CausticMap, causticUV).bbb; |
|||
|
|||
half upperMask = saturate(-worldPos.y + _WaterLevel); |
|||
half lowerMask = saturate((worldPos.y - _WaterLevel) / _BlendDistance + _BlendDistance); |
|||
|
|||
caustics *= min(upperMask, lowerMask) * 1.5; |
|||
|
|||
//return half4(waveOffset.xx, 0, 1); |
|||
return half4(caustics + 1, 1); |
|||
} |
|||
ENDHLSL |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: a7e6cd2d14dfc49d188a4707edf9a870 |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 45e2f51a3917e6941a41ceb69f5b1a58 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine; |
|||
using UnityEngine.Rendering; |
|||
using UnityEngine.Rendering.Universal; |
|||
|
|||
[CreateAssetMenu] |
|||
public class BoatRendererData : ScriptableRendererData |
|||
{ |
|||
[ReloadGroup] |
|||
public sealed class ShaderResources |
|||
{ |
|||
[Reload("Shaders/Utils/Blit.shader")] |
|||
public Shader blitPS; |
|||
|
|||
[Reload("Shaders/Utils/CopyDepth.shader")] |
|||
public Shader copyDepthPS; |
|||
|
|||
[Reload("Shaders/Utils/ScreenSpaceShadows.shader")] |
|||
public Shader screenSpaceShadowPS; |
|||
|
|||
[Reload("Shaders/Utils/Sampling.shader")] |
|||
public Shader samplingPS; |
|||
} |
|||
|
|||
[Reload("Runtime/Data/PostProcessData.asset")] |
|||
public PostProcessData postProcessData = null; |
|||
public ShaderResources shaders = null; |
|||
public Material caustics = null; |
|||
|
|||
protected override ScriptableRenderer Create() |
|||
{ |
|||
#if UNITY_EDITOR
|
|||
if (!Application.isPlaying) |
|||
{ |
|||
ResourceReloader.ReloadAllNullIn(this, UniversalRenderPipelineAsset.packagePath); |
|||
ResourceReloader.ReloadAllNullIn(postProcessData, UniversalRenderPipelineAsset.packagePath); |
|||
} |
|||
#endif
|
|||
|
|||
return new BoatRenderer(this); |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 580815c7b01f60e429065cd2e33f7e1d |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: ab0cf89a3f1c6f041a012ad1d75a117f |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine; |
|||
using UnityEngine.Rendering; |
|||
using UnityEngine.Rendering.Universal; |
|||
|
|||
public class BoatRenderer : ScriptableRenderer |
|||
{ |
|||
const int k_DepthStencilBufferBits = 32; |
|||
const string k_CreateCameraTextures = "Create Camera Texture"; |
|||
|
|||
ColorGradingLutPass m_ColorGradingLutPass; |
|||
MainLightShadowCasterPass m_MainLightShadowCasterPass; |
|||
PostProcessPass m_PostProcessPass; |
|||
PostProcessPass m_FinalPostProcessPass; |
|||
MainRenderPass m_MainRenderPass; |
|||
FinalBlitPass m_FinalBlitPass; |
|||
CopyDepthPass m_CopyDepthPass; |
|||
|
|||
#if UNITY_EDITOR
|
|||
SceneViewDepthCopyPass m_SceneViewDepthCopyPass; |
|||
#endif
|
|||
|
|||
RenderTargetHandle m_ActiveCameraColorAttachment; |
|||
RenderTargetHandle m_ActiveCameraDepthAttachment; |
|||
public RenderTargetHandle m_CameraColorAttachment; |
|||
public RenderTargetHandle m_CameraDepthAttachment; |
|||
RenderTargetHandle m_AfterPostProcessColor; |
|||
RenderTargetHandle m_ColorGradingLut; |
|||
|
|||
RenderTargetHandle m_DepthTexture; |
|||
|
|||
ForwardLights m_ForwardLights; |
|||
|
|||
public BoatRenderer(BoatRendererData data) : base(data) |
|||
{ |
|||
Material blitMaterial = CoreUtils.CreateEngineMaterial(data.shaders.blitPS); |
|||
Material copyDepthMaterial = CoreUtils.CreateEngineMaterial(data.shaders.copyDepthPS); |
|||
|
|||
m_MainLightShadowCasterPass = new MainLightShadowCasterPass(RenderPassEvent.BeforeRenderingShadows); |
|||
m_ColorGradingLutPass = new ColorGradingLutPass(RenderPassEvent.BeforeRenderingOpaques, data.postProcessData); |
|||
m_PostProcessPass = new PostProcessPass(RenderPassEvent.BeforeRenderingPostProcessing, data.postProcessData); |
|||
m_FinalPostProcessPass = new PostProcessPass(RenderPassEvent.AfterRenderingPostProcessing, data.postProcessData); |
|||
m_MainRenderPass = new MainRenderPass(RenderPassEvent.BeforeRenderingOpaques, data.caustics); |
|||
m_FinalBlitPass = new FinalBlitPass(RenderPassEvent.AfterRendering, blitMaterial); |
|||
m_CopyDepthPass = new CopyDepthPass(RenderPassEvent.BeforeRenderingOpaques, copyDepthMaterial); |
|||
|
|||
#if UNITY_EDITOR
|
|||
m_SceneViewDepthCopyPass = new SceneViewDepthCopyPass(RenderPassEvent.AfterRendering + 9, copyDepthMaterial); |
|||
#endif
|
|||
|
|||
// RenderTexture format depends on camera and pipeline (HDR, non HDR, etc)
|
|||
// Samples (MSAA) depend on camera and pipeline
|
|||
m_CameraColorAttachment.Init("_CameraColorTexture"); |
|||
m_CameraDepthAttachment.Init("_CameraDepthAttachment"); |
|||
m_AfterPostProcessColor.Init("_AfterPostProcessTexture"); |
|||
m_ColorGradingLut.Init("_InternalGradingLut"); |
|||
m_DepthTexture.Init("_CameraDepthTexture"); |
|||
m_ForwardLights = new ForwardLights(); |
|||
} |
|||
|
|||
public override void Setup(ScriptableRenderContext context, ref RenderingData renderingData) |
|||
{ |
|||
ref CameraData cameraData = ref renderingData.cameraData; |
|||
var cameraTargetDescriptor = cameraData.cameraTargetDescriptor; |
|||
bool mainLightShadows = m_MainLightShadowCasterPass.Setup(ref renderingData); |
|||
bool resolveShadowsInScreenSpace = mainLightShadows && renderingData.shadowData.requiresScreenSpaceShadowResolve; |
|||
|
|||
// Depth prepass is generated in the following cases:
|
|||
// - We resolve shadows in screen space
|
|||
// - Scene view camera always requires a depth texture. We do a depth pre-pass to simplify it and it shouldn't matter much for editor.
|
|||
// - If game or offscreen camera requires it we check if we can copy the depth from the rendering opaques pass and use that instead.
|
|||
bool requiresDepthPrepass = renderingData.cameraData.isSceneViewCamera || |
|||
(cameraData.requiresDepthTexture && (!CanCopyDepth(ref renderingData.cameraData))); |
|||
requiresDepthPrepass |= resolveShadowsInScreenSpace; |
|||
|
|||
bool createColorTexture = RequiresIntermediateColorTexture(ref renderingData, cameraTargetDescriptor) |
|||
|| rendererFeatures.Count != 0; |
|||
|
|||
// If camera requires depth and there's no depth pre-pass we create a depth texture that can be read
|
|||
// later by effect requiring it.
|
|||
bool createDepthTexture = cameraData.requiresDepthTexture && !requiresDepthPrepass; |
|||
bool postProcessEnabled = cameraData.postProcessEnabled; |
|||
|
|||
bool requiresFinalPostProcessPass = postProcessEnabled && |
|||
renderingData.cameraData.antialiasing == AntialiasingMode.FastApproximateAntialiasing; |
|||
|
|||
m_ActiveCameraColorAttachment = (createColorTexture) ? m_CameraColorAttachment : RenderTargetHandle.CameraTarget; |
|||
m_ActiveCameraDepthAttachment = (createDepthTexture) ? m_CameraDepthAttachment : RenderTargetHandle.CameraTarget; |
|||
bool intermediateRenderTexture = createColorTexture || createDepthTexture; |
|||
|
|||
if (intermediateRenderTexture) |
|||
CreateCameraRenderTarget(context, ref cameraData); |
|||
|
|||
ConfigureCameraTarget(m_ActiveCameraColorAttachment.Identifier(), m_ActiveCameraDepthAttachment.Identifier()); |
|||
|
|||
for (int i = 0; i < rendererFeatures.Count; ++i) |
|||
{ |
|||
rendererFeatures[i].AddRenderPasses(this, ref renderingData); |
|||
} |
|||
|
|||
int count = activeRenderPassQueue.Count; |
|||
for (int i = count - 1; i >= 0; i--) |
|||
{ |
|||
if (activeRenderPassQueue[i] == null) |
|||
activeRenderPassQueue.RemoveAt(i); |
|||
} |
|||
|
|||
if (mainLightShadows) |
|||
EnqueuePass(m_MainLightShadowCasterPass); |
|||
|
|||
if (postProcessEnabled) |
|||
{ |
|||
m_ColorGradingLutPass.Setup(m_ColorGradingLut); |
|||
EnqueuePass(m_ColorGradingLutPass); |
|||
} |
|||
|
|||
m_MainRenderPass.renderer = this; |
|||
EnqueuePass(m_MainRenderPass); |
|||
|
|||
// If a depth texture was created we necessarily need to copy it, otherwise we could have render it to a renderbuffer
|
|||
if (createDepthTexture) |
|||
{ |
|||
m_CopyDepthPass.Setup(m_ActiveCameraDepthAttachment, m_DepthTexture); |
|||
EnqueuePass(m_CopyDepthPass); |
|||
} |
|||
|
|||
if (postProcessEnabled) |
|||
{ |
|||
if (requiresFinalPostProcessPass) |
|||
{ |
|||
m_PostProcessPass.Setup(cameraTargetDescriptor, m_ActiveCameraColorAttachment, m_AfterPostProcessColor, m_ActiveCameraDepthAttachment, m_ColorGradingLut); |
|||
EnqueuePass(m_PostProcessPass); |
|||
m_FinalPostProcessPass.SetupFinalPass(m_AfterPostProcessColor); |
|||
EnqueuePass(m_FinalPostProcessPass); |
|||
} |
|||
else |
|||
{ |
|||
m_PostProcessPass.Setup(cameraTargetDescriptor, m_ActiveCameraColorAttachment, RenderTargetHandle.CameraTarget, m_ActiveCameraDepthAttachment, m_ColorGradingLut); |
|||
EnqueuePass(m_PostProcessPass); |
|||
} |
|||
} |
|||
else if (m_ActiveCameraColorAttachment != RenderTargetHandle.CameraTarget) |
|||
{ |
|||
m_FinalBlitPass.Setup(cameraTargetDescriptor, m_ActiveCameraColorAttachment); |
|||
EnqueuePass(m_FinalBlitPass); |
|||
} |
|||
} |
|||
|
|||
public override void SetupLights(ScriptableRenderContext context, ref RenderingData renderingData) |
|||
{ |
|||
m_ForwardLights.Setup(context, ref renderingData); |
|||
} |
|||
|
|||
public override void SetupCullingParameters(ref ScriptableCullingParameters cullingParameters, |
|||
ref CameraData cameraData) |
|||
{ |
|||
Camera camera = cameraData.camera; |
|||
cullingParameters.shadowDistance = Mathf.Min(cameraData.maxShadowDistance, camera.farClipPlane); |
|||
} |
|||
|
|||
public override void FinishRendering(CommandBuffer cmd) |
|||
{ |
|||
if (m_ActiveCameraColorAttachment != RenderTargetHandle.CameraTarget) |
|||
cmd.ReleaseTemporaryRT(m_ActiveCameraColorAttachment.id); |
|||
|
|||
if (m_ActiveCameraDepthAttachment != RenderTargetHandle.CameraTarget) |
|||
cmd.ReleaseTemporaryRT(m_ActiveCameraDepthAttachment.id); |
|||
} |
|||
|
|||
void CreateCameraRenderTarget(ScriptableRenderContext context, ref CameraData cameraData) |
|||
{ |
|||
CommandBuffer cmd = CommandBufferPool.Get(k_CreateCameraTextures); |
|||
var descriptor = cameraData.cameraTargetDescriptor; |
|||
int msaaSamples = descriptor.msaaSamples; |
|||
if (m_ActiveCameraColorAttachment != RenderTargetHandle.CameraTarget) |
|||
{ |
|||
bool useDepthRenderBuffer = m_ActiveCameraDepthAttachment == RenderTargetHandle.CameraTarget; |
|||
var colorDescriptor = descriptor; |
|||
colorDescriptor.depthBufferBits = (useDepthRenderBuffer) ? k_DepthStencilBufferBits : 0; |
|||
cmd.GetTemporaryRT(m_ActiveCameraColorAttachment.id, colorDescriptor, FilterMode.Bilinear); |
|||
} |
|||
|
|||
if (m_ActiveCameraDepthAttachment != RenderTargetHandle.CameraTarget) |
|||
{ |
|||
var depthDescriptor = descriptor; |
|||
depthDescriptor.colorFormat = RenderTextureFormat.Depth; |
|||
depthDescriptor.depthBufferBits = k_DepthStencilBufferBits; |
|||
depthDescriptor.bindMS = msaaSamples > 1 && !SystemInfo.supportsMultisampleAutoResolve && (SystemInfo.supportsMultisampledTextures != 0); |
|||
cmd.GetTemporaryRT(m_ActiveCameraDepthAttachment.id, depthDescriptor, FilterMode.Point); |
|||
} |
|||
|
|||
context.ExecuteCommandBuffer(cmd); |
|||
CommandBufferPool.Release(cmd); |
|||
} |
|||
|
|||
bool RequiresIntermediateColorTexture(ref RenderingData renderingData, RenderTextureDescriptor baseDescriptor) |
|||
{ |
|||
ref CameraData cameraData = ref renderingData.cameraData; |
|||
int msaaSamples = cameraData.cameraTargetDescriptor.msaaSamples; |
|||
bool isStereoEnabled = renderingData.cameraData.isStereoEnabled; |
|||
bool isScaledRender = !Mathf.Approximately(cameraData.renderScale, 1.0f); |
|||
bool isCompatibleBackbufferTextureDimension = baseDescriptor.dimension == TextureDimension.Tex2D; |
|||
bool requiresExplicitMsaaResolve = msaaSamples > 1 && !SystemInfo.supportsMultisampleAutoResolve; |
|||
bool isOffscreenRender = cameraData.camera.targetTexture != null && !cameraData.isSceneViewCamera; |
|||
bool isCapturing = cameraData.captureActions != null; |
|||
|
|||
bool requiresBlitForOffscreenCamera = cameraData.postProcessEnabled || cameraData.requiresOpaqueTexture || requiresExplicitMsaaResolve; |
|||
if (isOffscreenRender) |
|||
return requiresBlitForOffscreenCamera; |
|||
|
|||
return requiresBlitForOffscreenCamera || cameraData.isSceneViewCamera || isScaledRender || cameraData.isHdrEnabled || |
|||
!isCompatibleBackbufferTextureDimension || !cameraData.isDefaultViewport || isCapturing || Display.main.requiresBlitToBackbuffer |
|||
|| (renderingData.killAlphaInFinalBlit && !isStereoEnabled); |
|||
} |
|||
bool CanCopyDepth(ref CameraData cameraData) |
|||
{ |
|||
bool msaaEnabledForCamera = cameraData.cameraTargetDescriptor.msaaSamples > 1; |
|||
bool supportsTextureCopy = SystemInfo.copyTextureSupport != CopyTextureSupport.None; |
|||
bool supportsDepthTarget = RenderingUtils.SupportsRenderTextureFormat(RenderTextureFormat.Depth); |
|||
bool supportsDepthCopy = !msaaEnabledForCamera && (supportsDepthTarget || supportsTextureCopy); |
|||
|
|||
// TODO: We don't have support to highp Texture2DMS currently and this breaks depth precision.
|
|||
// currently disabling it until shader changes kick in.
|
|||
//bool msaaDepthResolve = msaaEnabledForCamera && SystemInfo.supportsMultisampledTextures != 0;
|
|||
bool msaaDepthResolve = false; |
|||
return supportsDepthCopy || msaaDepthResolve; |
|||
} |
|||
} |
|
|||
using UnityEngine; |
|||
using UnityEngine.Rendering; |
|||
using UnityEngine.Rendering.Universal; |
|||
using Unity.Collections; |
|||
|
|||
public class MainRenderPass : ScriptableRenderPass |
|||
{ |
|||
FilteringSettings m_OpaqueFilteringSettings; |
|||
FilteringSettings m_TransparentFilteringSettings; |
|||
ShaderTagId m_UniversalForwardPass = new ShaderTagId("UniversalForward"); |
|||
|
|||
AttachmentDescriptor colorAttachmentDescriptor; |
|||
AttachmentDescriptor depthAttachmentDescriptor; |
|||
|
|||
Material m_CausticsMaterial; |
|||
public BoatRenderer renderer; |
|||
|
|||
public MainRenderPass(RenderPassEvent renderPassEvent, Material causticsMaterial) |
|||
{ |
|||
this.renderPassEvent = renderPassEvent; |
|||
m_OpaqueFilteringSettings = new FilteringSettings(RenderQueueRange.opaque); |
|||
m_TransparentFilteringSettings = new FilteringSettings(RenderQueueRange.transparent); |
|||
colorAttachmentDescriptor = new AttachmentDescriptor(RenderTextureFormat.RGB111110Float); |
|||
depthAttachmentDescriptor = new AttachmentDescriptor(RenderTextureFormat.Depth); |
|||
m_CausticsMaterial = causticsMaterial; |
|||
} |
|||
|
|||
//public override void Configure(CommandBuffer cmd, RenderTextureDescriptor cameraTextureDescriptor)
|
|||
//{
|
|||
// ConfigureTarget(BuiltinRenderTextureType.CurrentActive, BuiltinRenderTextureType.CurrentActive);
|
|||
//}
|
|||
|
|||
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) |
|||
{ |
|||
var opaqueDrawingSettings = CreateDrawingSettings(m_UniversalForwardPass, ref renderingData, SortingCriteria.CommonOpaque); |
|||
var transparentDrawingSettings = CreateDrawingSettings(m_UniversalForwardPass, ref renderingData, SortingCriteria.CommonTransparent); |
|||
|
|||
var cameraTargetDescriptor = renderingData.cameraData.cameraTargetDescriptor; |
|||
int width = cameraTargetDescriptor.width; |
|||
int height = cameraTargetDescriptor.height; |
|||
colorAttachmentDescriptor.ConfigureTarget(renderer.m_CameraColorAttachment.Identifier(), false, true); |
|||
depthAttachmentDescriptor.ConfigureTarget(renderer.m_CameraDepthAttachment.Identifier(), false, true); |
|||
var descriptors = new NativeArray<AttachmentDescriptor>( |
|||
new[] { colorAttachmentDescriptor, depthAttachmentDescriptor }, |
|||
Allocator.Temp); |
|||
|
|||
using (context.BeginScopedRenderPass(width, height, 1, descriptors, 1)) |
|||
{ |
|||
descriptors.Dispose(); |
|||
NativeArray<int> attachmentIndices = new NativeArray<int>(new[] { 0 }, Allocator.Temp); |
|||
using (context.BeginScopedSubPass(attachmentIndices)) |
|||
{ |
|||
attachmentIndices.Dispose(); |
|||
context.DrawRenderers(renderingData.cullResults, ref opaqueDrawingSettings, ref m_OpaqueFilteringSettings); |
|||
context.DrawSkybox(renderingData.cameraData.camera); |
|||
var cmd = CommandBufferPool.Get("DrawCaustics"); |
|||
cmd.DrawMesh(RenderingUtils.fullscreenMesh, Matrix4x4.identity, m_CausticsMaterial); |
|||
context.ExecuteCommandBuffer(cmd); |
|||
CommandBufferPool.Release(cmd); |
|||
//context.DrawRenderers(renderingData.cullResults, ref transparentDrawingSettings, ref m_TransparentFilteringSettings);
|
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 82a703e8c80f14c02afba8369541363e |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: e50cf0f4dde230944a81a4bb1a939a90 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue