浏览代码

Merged renderer features into one

/demo-work
André McGrail 5 年前
当前提交
48934340
共有 8 个文件被更改,包括 167 次插入203 次删除
  1. 25
      Assets/Data/UniversalRP/BoatDemoRenderer.asset
  2. 2
      Packages/com.verasl.water-system/Scripts/Rendering/WaterSystemFeature.cs.meta
  3. 14
      Packages/com.verasl.water-system/package.json
  4. 154
      Packages/com.verasl.water-system/Scripts/Rendering/WaterSystemFeature.cs
  5. 91
      Packages/com.verasl.water-system/Scripts/Rendering/WaterFXFeature.cs
  6. 11
      Packages/com.verasl.water-system/Scripts/Rendering/WaterFXFeature.cs.meta
  7. 73
      Packages/com.verasl.water-system/Scripts/Rendering/WaterCausticsFeature.cs
  8. 0
      /Packages/com.verasl.water-system/Scripts/Rendering/WaterSystemFeature.cs.meta

25
Assets/Data/UniversalRP/BoatDemoRenderer.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &-5007552800156170450
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: Water FX
m_EditorClassIdentifier:
settings:
debug: 0
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0

m_Name: BoatDemoRenderer
m_EditorClassIdentifier:
m_RendererFeatures:
- {fileID: 7749027049794126836}
- {fileID: -5007552800156170450}
- {fileID: 770174969183694509}
postProcessData: {fileID: 11400000, guid: 41439944d30ece34e96484bdb6645b55, type: 2}
shaders:
blitPS: {fileID: 4800000, guid: c17132b1f77d20942aa75f8429c0f8bc, type: 3}

passOperation: 2
failOperation: 0
zFailOperation: 0
--- !u!114 &7749027049794126836
--- !u!114 &770174969183694509
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}

m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 01c60659bc43f4603be9d5b8afb185fb, type: 3}
m_Name: Caustics
m_Script: {fileID: 11500000, guid: adbe377f4f72c497faee64bc3f0580b9, type: 3}
m_Name: WaterSystem
material: {fileID: 2100000, guid: 7e6ea000873112847bd146ddb78ac67d, type: 2}
causticMaterial: {fileID: 2100000, guid: 7e6ea000873112847bd146ddb78ac67d, type: 2}
mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0}
debug: 0

2
Packages/com.verasl.water-system/Scripts/Rendering/WaterSystemFeature.cs.meta


fileFormatVersion: 2
guid: 01c60659bc43f4603be9d5b8afb185fb
guid: adbe377f4f72c497faee64bc3f0580b9
MonoImporter:
externalObjects: {}
serializedVersion: 2

14
Packages/com.verasl.water-system/package.json


{
"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",
}
}

154
Packages/com.verasl.water-system/Scripts/Rendering/WaterSystemFeature.cs


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
}
}
}

91
Packages/com.verasl.water-system/Scripts/Rendering/WaterFXFeature.cs


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);
}
}
}

11
Packages/com.verasl.water-system/Scripts/Rendering/WaterFXFeature.cs.meta


fileFormatVersion: 2
guid: fc3f76324391a408d9c0770ca6fcb666
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

73
Packages/com.verasl.water-system/Scripts/Rendering/WaterCausticsFeature.cs


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);
}
}
}

/Packages/com.verasl.water-system/Scripts/Rendering/WaterCausticsFeature.cs.meta → /Packages/com.verasl.water-system/Scripts/Rendering/WaterSystemFeature.cs.meta

正在加载...
取消
保存