浏览代码

Added caustics

/demo-work-customrenderer
Felipe Lira 5 年前
当前提交
d47cf909
共有 8 个文件被更改,包括 252 次插入5 次删除
  1. 2
      Assets/Data/UniversalRP/CustomBoatDemoRenderer.asset
  2. 18
      Assets/Rendering/BoatRenderer.cs
  3. 1
      Assets/Rendering/BoatRendererData.cs
  4. 11
      Assets/Rendering/MainRenderPass.cs
  5. 113
      Packages/com.verasl.water-system/CausticsModified.mat
  6. 8
      Packages/com.verasl.water-system/CausticsModified.mat.meta
  7. 95
      Packages/com.verasl.water-system/Shaders/CausticsModified.shader
  8. 9
      Packages/com.verasl.water-system/Shaders/CausticsModified.shader.meta

2
Assets/Data/UniversalRP/CustomBoatDemoRenderer.asset


m_EditorClassIdentifier:
m_RendererFeatures:
- {fileID: 6778594283966551180}
- {fileID: 0}
caustics: {fileID: 2100000, guid: f09f40ad472134250a9e0ad60dd212f0, type: 2}
--- !u!114 &6778594283966551180
MonoBehaviour:
m_ObjectHideFlags: 0

18
Assets/Rendering/BoatRenderer.cs


PostProcessPass m_FinalPostProcessPass;
MainRenderPass m_MainRenderPass;
FinalBlitPass m_FinalBlitPass;
CopyDepthPass m_CopyDepthPass;
#if UNITY_EDITOR
SceneViewDepthCopyPass m_SceneViewDepthCopyPass;

RenderTargetHandle m_CameraDepthAttachment;
RenderTargetHandle m_AfterPostProcessColor;
RenderTargetHandle m_ColorGradingLut;
RenderTargetHandle m_DepthTexture;
ForwardLights m_ForwardLights;

Material copyDepthMaterial = CoreUtils.CreateEngineMaterial(data.shaders.copyDepthPS);
m_MainRenderPass = new MainRenderPass(RenderPassEvent.BeforeRenderingOpaques);
m_MainRenderPass = new MainRenderPass(RenderPassEvent.BeforeRenderingOpaques, data.caustics);
m_CopyDepthPass = new CopyDepthPass(RenderPassEvent.BeforeRenderingOpaques, copyDepthMaterial);
#if UNITY_EDITOR
m_SceneViewDepthCopyPass = new SceneViewDepthCopyPass(RenderPassEvent.AfterRendering + 9, copyDepthMaterial);
#endif

m_CameraDepthAttachment.Init("_CameraDepthAttachment");
m_AfterPostProcessColor.Init("_AfterPostProcessTexture");
m_ColorGradingLut.Init("_InternalGradingLut");
m_DepthTexture.Init("_CameraDepthTexture");
m_ForwardLights = new ForwardLights();
}

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

1
Assets/Rendering/BoatRendererData.cs


[Reload("Runtime/Data/PostProcessData.asset")]
public PostProcessData postProcessData = null;
public ShaderResources shaders = null;
public Material caustics = null;
protected override ScriptableRenderer Create()
{

11
Assets/Rendering/MainRenderPass.cs


AttachmentDescriptor colorAttachmentDescriptor;
AttachmentDescriptor depthAttachmentDescriptor;
public MainRenderPass(RenderPassEvent renderPassEvent)
Material m_CausticsMaterial;
public MainRenderPass(RenderPassEvent renderPassEvent, Material causticsMaterial)
{
this.renderPassEvent = renderPassEvent;
m_OpaqueFilteringSettings = new FilteringSettings(RenderQueueRange.opaque);

m_CausticsMaterial = causticsMaterial;
}
//public override void Configure(CommandBuffer cmd, RenderTextureDescriptor cameraTextureDescriptor)

context.DrawRenderers(renderingData.cullResults, ref opaqueDrawingSettings, ref m_OpaqueFilteringSettings);
context.DrawSkybox(renderingData.cameraData.camera);
context.DrawRenderers(renderingData.cullResults, ref transparentDrawingSettings, ref m_TransparentFilteringSettings);
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);
}
}

113
Packages/com.verasl.water-system/CausticsModified.mat


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

8
Packages/com.verasl.water-system/CausticsModified.mat.meta


fileFormatVersion: 2
guid: f09f40ad472134250a9e0ad60dd212f0
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:

95
Packages/com.verasl.water-system/Shaders/CausticsModified.shader


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

9
Packages/com.verasl.water-system/Shaders/CausticsModified.shader.meta


fileFormatVersion: 2
guid: a7e6cd2d14dfc49d188a4707edf9a870
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存