André McGrail
5 年前
当前提交
48934340
共有 8 个文件被更改,包括 167 次插入 和 203 次删除
-
25Assets/Data/UniversalRP/BoatDemoRenderer.asset
-
2Packages/com.verasl.water-system/Scripts/Rendering/WaterSystemFeature.cs.meta
-
14Packages/com.verasl.water-system/package.json
-
154Packages/com.verasl.water-system/Scripts/Rendering/WaterSystemFeature.cs
-
91Packages/com.verasl.water-system/Scripts/Rendering/WaterFXFeature.cs
-
11Packages/com.verasl.water-system/Scripts/Rendering/WaterFXFeature.cs.meta
-
73Packages/com.verasl.water-system/Scripts/Rendering/WaterCausticsFeature.cs
-
0/Packages/com.verasl.water-system/Scripts/Rendering/WaterSystemFeature.cs.meta
|
|||
{ |
|||
"name": "com.verasl.water-system", |
|||
"description": "A water system for LWRP.", |
|||
"version": "1.2.0-preview", |
|||
"unity": "2019.1", |
|||
"displayName": "LWRP Water System", |
|||
"description": "A water system for URP.", |
|||
"version": "1.3.0-preview", |
|||
"unity": "2019.3", |
|||
"displayName": "Boat Attack Water System", |
|||
"com.unity.mathematics": "0.0.12-preview.11", |
|||
"com.unity.burst": "0.2.4-preview.30", |
|||
"com.unity.mathematics": "1.0.0", |
|||
"com.unity.burst": "1.0.0", |
|||
} |
|||
} |
|
|||
using UnityEngine; |
|||
using UnityEngine.Rendering; |
|||
using UnityEngine.Rendering.Universal; |
|||
|
|||
public class WaterSystemFeature : ScriptableRendererFeature |
|||
{ |
|||
|
|||
#region Water Effects Pass
|
|||
|
|||
public class WaterFXPass : ScriptableRenderPass |
|||
{ |
|||
const string k_RenderWaterFXTag = "Render Water FX"; |
|||
public bool debug; |
|||
ShaderTagId m_WaterFXShaderTag = new ShaderTagId("WaterFX"); |
|||
Color m_ClearColor = new Color(0.0f, 0.5f, 0.5f, 0.5f); |
|||
RenderTargetHandle m_WaterFX = RenderTargetHandle.CameraTarget; |
|||
|
|||
private FilteringSettings transparentFilterSettings { get; set; } |
|||
|
|||
public WaterFXPass() |
|||
{ |
|||
m_WaterFX.Init("_WaterFXMap"); |
|||
transparentFilterSettings = new FilteringSettings(RenderQueueRange.transparent); |
|||
} |
|||
|
|||
public override void Configure(CommandBuffer cmd, RenderTextureDescriptor cameraTextureDescriptor) |
|||
{ |
|||
cameraTextureDescriptor.depthBufferBits = 0; |
|||
cameraTextureDescriptor.width = cameraTextureDescriptor.width / 2; |
|||
cameraTextureDescriptor.height = cameraTextureDescriptor.height / 2; |
|||
cameraTextureDescriptor.colorFormat = RenderTextureFormat.Default; |
|||
cmd.GetTemporaryRT(m_WaterFX.id, cameraTextureDescriptor, FilterMode.Bilinear); |
|||
ConfigureTarget(m_WaterFX.Identifier()); |
|||
ConfigureClear(ClearFlag.Color, m_ClearColor); |
|||
} |
|||
|
|||
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) |
|||
{ |
|||
CommandBuffer cmd = CommandBufferPool.Get(k_RenderWaterFXTag); |
|||
|
|||
using (new ProfilingSample(cmd, k_RenderWaterFXTag)) |
|||
{ |
|||
context.ExecuteCommandBuffer(cmd); |
|||
cmd.Clear(); |
|||
|
|||
var drawSettings = CreateDrawingSettings(m_WaterFXShaderTag, ref renderingData, SortingCriteria.CommonTransparent); |
|||
var filteringSettings = transparentFilterSettings; |
|||
|
|||
context.DrawRenderers(renderingData.cullResults, ref drawSettings, ref filteringSettings); |
|||
} |
|||
|
|||
context.ExecuteCommandBuffer(cmd); |
|||
CommandBufferPool.Release(cmd); |
|||
} |
|||
|
|||
public override void FrameCleanup(CommandBuffer cmd) |
|||
{ |
|||
if(!debug) |
|||
cmd.ReleaseTemporaryRT(m_WaterFX.id); |
|||
} |
|||
} |
|||
|
|||
#endregion
|
|||
|
|||
#region Caustics Pass
|
|||
|
|||
public class WaterCausticsPass : ScriptableRenderPass |
|||
{ |
|||
const string k_RenderWaterCausticsTag = "Render Water Caustics"; |
|||
public Material m_WaterCausticMaterial; |
|||
public Mesh m_mesh; |
|||
|
|||
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) |
|||
{ |
|||
if (m_WaterCausticMaterial == null || m_mesh == null) |
|||
{ |
|||
Debug.LogErrorFormat( |
|||
"Missing caustic material. {0} render pass will not execute. Check for missing reference in the renderer resources.", |
|||
GetType().Name); |
|||
return; |
|||
} |
|||
|
|||
Vector3 position = renderingData.cameraData.camera.transform.position; |
|||
position.y = 0; |
|||
Matrix4x4 matrix = Matrix4x4.TRS(position, Quaternion.identity, Vector3.one * 100f); |
|||
|
|||
CommandBuffer cmd = CommandBufferPool.Get(k_RenderWaterCausticsTag); |
|||
cmd.DrawMesh(m_mesh, matrix , m_WaterCausticMaterial, 0, 0); |
|||
context.ExecuteCommandBuffer(cmd); |
|||
CommandBufferPool.Release(cmd); |
|||
} |
|||
} |
|||
|
|||
#endregion
|
|||
|
|||
|
|||
WaterFXPass m_WaterFxPass; |
|||
WaterCausticsPass m_CausticsPass; |
|||
|
|||
public WaterSystemSettings settings = new WaterSystemSettings(); |
|||
|
|||
public override void Create() |
|||
{ |
|||
// WaterFX Pass
|
|||
m_WaterFxPass = new WaterFXPass(); |
|||
m_WaterFxPass.renderPassEvent = RenderPassEvent.BeforeRenderingOpaques; |
|||
|
|||
// Caustic Pass
|
|||
m_CausticsPass = new WaterCausticsPass(); |
|||
if (settings.debug == WaterSystemSettings.DebugMode.Caustics && settings.causticMaterial) |
|||
{ |
|||
settings.causticMaterial.SetFloat("_SrcBlend", 1f); |
|||
settings.causticMaterial.SetFloat("_DstBlend", 0f); |
|||
settings.causticMaterial.EnableKeyword("_DEBUG"); |
|||
m_CausticsPass.renderPassEvent = RenderPassEvent.AfterRenderingPostProcessing; |
|||
} |
|||
else |
|||
{ |
|||
settings.causticMaterial.SetFloat("_SrcBlend", 2f); |
|||
settings.causticMaterial.SetFloat("_DstBlend", 0f); |
|||
settings.causticMaterial.DisableKeyword("_DEBUG"); |
|||
m_CausticsPass.renderPassEvent = RenderPassEvent.AfterRenderingSkybox + 1; |
|||
} |
|||
m_CausticsPass.m_WaterCausticMaterial = settings.causticMaterial; |
|||
m_CausticsPass.m_mesh = settings.mesh; |
|||
} |
|||
|
|||
public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData) |
|||
{ |
|||
renderer.EnqueuePass(m_WaterFxPass); |
|||
renderer.EnqueuePass(m_CausticsPass); |
|||
} |
|||
|
|||
[System.Serializable] |
|||
public class WaterSystemSettings |
|||
{ |
|||
[Header("Water Effects Settings")] |
|||
|
|||
[Header("Caustics Settings")] |
|||
public Material causticMaterial; |
|||
public Mesh mesh; |
|||
[Header("Advanced Settings")] |
|||
public DebugMode debug = DebugMode.Disabled; |
|||
|
|||
public enum DebugMode |
|||
{ |
|||
Disabled, |
|||
WaterEffects, |
|||
Caustics |
|||
} |
|||
} |
|||
} |
|||
|
|||
|
|
|||
using UnityEngine; |
|||
using UnityEngine.Experimental.Rendering; |
|||
using UnityEngine.Rendering; |
|||
|
|||
|
|||
namespace WaterSystem |
|||
{ |
|||
public class WaterFXFeature : UnityEngine.Rendering.Universal.ScriptableRendererFeature |
|||
{ |
|||
WaterFXPass m_WaterFXPass; |
|||
public WaterFXSettings settings = new WaterFXSettings(); |
|||
|
|||
[System.Serializable] |
|||
public class WaterFXSettings |
|||
{ |
|||
public bool debug; |
|||
} |
|||
|
|||
public override void Create() |
|||
{ |
|||
m_WaterFXPass = new WaterFXPass(); |
|||
m_WaterFXPass.debug = settings.debug; |
|||
if (settings.debug) |
|||
{ |
|||
m_WaterFXPass.renderPassEvent = UnityEngine.Rendering.Universal.RenderPassEvent.AfterRendering; |
|||
} |
|||
else |
|||
{ |
|||
m_WaterFXPass.renderPassEvent = UnityEngine.Rendering.Universal.RenderPassEvent.BeforeRenderingOpaques; |
|||
} |
|||
} |
|||
|
|||
public override void AddRenderPasses(UnityEngine.Rendering.Universal.ScriptableRenderer renderer, ref UnityEngine.Rendering.Universal.RenderingData renderingData) |
|||
{ |
|||
renderer.EnqueuePass(m_WaterFXPass); |
|||
} |
|||
} |
|||
|
|||
public class WaterFXPass : UnityEngine.Rendering.Universal.ScriptableRenderPass |
|||
{ |
|||
const string k_RenderWaterFXTag = "Render Water FX"; |
|||
public bool debug; |
|||
ShaderTagId m_WaterFXShaderTag = new ShaderTagId("WaterFX"); |
|||
Color m_ClearColor = new Color(0.0f, 0.5f, 0.5f, 0.5f); |
|||
UnityEngine.Rendering.Universal.RenderTargetHandle m_WaterFX = UnityEngine.Rendering.Universal.RenderTargetHandle.CameraTarget; |
|||
|
|||
private FilteringSettings transparentFilterSettings { get; set; } |
|||
|
|||
public WaterFXPass() |
|||
{ |
|||
m_WaterFX.Init("_WaterFXMap"); |
|||
transparentFilterSettings = new FilteringSettings(RenderQueueRange.transparent); |
|||
} |
|||
|
|||
public override void Configure(CommandBuffer cmd, RenderTextureDescriptor cameraTextureDescriptor) |
|||
{ |
|||
cameraTextureDescriptor.depthBufferBits = 0; |
|||
cameraTextureDescriptor.width = cameraTextureDescriptor.width / 2; |
|||
cameraTextureDescriptor.height = cameraTextureDescriptor.height / 2; |
|||
cameraTextureDescriptor.colorFormat = RenderTextureFormat.Default; |
|||
cmd.GetTemporaryRT(m_WaterFX.id, cameraTextureDescriptor, FilterMode.Bilinear); |
|||
ConfigureTarget(m_WaterFX.Identifier()); |
|||
ConfigureClear(ClearFlag.Color, m_ClearColor); |
|||
} |
|||
|
|||
public override void Execute(ScriptableRenderContext context, ref UnityEngine.Rendering.Universal.RenderingData renderingData) |
|||
{ |
|||
CommandBuffer cmd = CommandBufferPool.Get(k_RenderWaterFXTag); |
|||
|
|||
using (new ProfilingSample(cmd, k_RenderWaterFXTag)) |
|||
{ |
|||
context.ExecuteCommandBuffer(cmd); |
|||
cmd.Clear(); |
|||
|
|||
var drawSettings = CreateDrawingSettings(m_WaterFXShaderTag, ref renderingData, SortingCriteria.CommonTransparent); |
|||
var filteringSettings = transparentFilterSettings; |
|||
|
|||
context.DrawRenderers(renderingData.cullResults, ref drawSettings, ref filteringSettings); |
|||
} |
|||
|
|||
context.ExecuteCommandBuffer(cmd); |
|||
CommandBufferPool.Release(cmd); |
|||
} |
|||
|
|||
public override void FrameCleanup(CommandBuffer cmd) |
|||
{ |
|||
if(!debug) |
|||
cmd.ReleaseTemporaryRT(m_WaterFX.id); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: fc3f76324391a408d9c0770ca6fcb666 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine; |
|||
using UnityEngine.Rendering; |
|||
using UnityEngine.Rendering.Universal; |
|||
|
|||
namespace WaterSystem |
|||
{ |
|||
public class WaterCausticsFeature : ScriptableRendererFeature |
|||
{ |
|||
private WaterCausticsPass m_WaterCausticsPass; |
|||
public WaterCausticSettings settings = new WaterCausticSettings(); |
|||
|
|||
[System.Serializable] |
|||
public class WaterCausticSettings |
|||
{ |
|||
public Material material; |
|||
public Mesh mesh; |
|||
public bool debug; |
|||
} |
|||
|
|||
public override void Create() |
|||
{ |
|||
m_WaterCausticsPass = new WaterCausticsPass(); |
|||
if (settings.debug) |
|||
{ |
|||
settings.material.SetFloat("_SrcBlend", 1f); |
|||
settings.material.SetFloat("_DstBlend", 0f); |
|||
settings.material.EnableKeyword("_DEBUG"); |
|||
m_WaterCausticsPass.renderPassEvent = RenderPassEvent.AfterRenderingPostProcessing; |
|||
} |
|||
else |
|||
{ |
|||
settings.material.SetFloat("_SrcBlend", 2f); |
|||
settings.material.SetFloat("_DstBlend", 0f); |
|||
settings.material.DisableKeyword("_DEBUG"); |
|||
m_WaterCausticsPass.renderPassEvent = RenderPassEvent.AfterRenderingSkybox + 1; |
|||
} |
|||
m_WaterCausticsPass.m_WaterCausticMaterial = settings.material; |
|||
m_WaterCausticsPass.m_mesh = settings.mesh; |
|||
} |
|||
|
|||
public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData) |
|||
{ |
|||
renderer.EnqueuePass(m_WaterCausticsPass); |
|||
} |
|||
} |
|||
|
|||
public class WaterCausticsPass : ScriptableRenderPass |
|||
{ |
|||
const string k_RenderWaterCausticsTag = "Render Water Caustics"; |
|||
public Material m_WaterCausticMaterial; |
|||
public Mesh m_mesh; |
|||
|
|||
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) |
|||
{ |
|||
if (m_WaterCausticMaterial == null || m_mesh == null) |
|||
{ |
|||
Debug.LogErrorFormat( |
|||
"Missing caustic material. {0} render pass will not execute. Check for missing reference in the renderer resources.", |
|||
GetType().Name); |
|||
return; |
|||
} |
|||
|
|||
Vector3 position = renderingData.cameraData.camera.transform.position; |
|||
position.y = 0; |
|||
Matrix4x4 matrix = Matrix4x4.TRS(position, Quaternion.identity, Vector3.one * 100f); |
|||
|
|||
CommandBuffer cmd = CommandBufferPool.Get(k_RenderWaterCausticsTag); |
|||
cmd.DrawMesh(m_mesh, matrix , m_WaterCausticMaterial, 0, 0); |
|||
context.ExecuteCommandBuffer(cmd); |
|||
CommandBufferPool.Release(cmd); |
|||
} |
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue