浏览代码

More work to the renderer

/demo-work-customrenderer
Felipe Lira 5 年前
当前提交
f5e6d084
共有 4 个文件被更改,包括 37 次插入15 次删除
  1. 1
      Assets/Data/UniversalRP/CustomBoatDemoRenderer.asset
  2. 31
      Assets/Rendering/BoatRenderer.cs
  3. 15
      Assets/Rendering/MainRenderPass.cs
  4. 5
      Packages/com.verasl.water-system/Shaders/CausticsModified.shader

1
Assets/Data/UniversalRP/CustomBoatDemoRenderer.asset


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

31
Assets/Rendering/BoatRenderer.cs


const string k_CreateCameraTextures = "Create Camera Texture";
ColorGradingLutPass m_ColorGradingLutPass;
DepthOnlyPass m_DepthPrepass;
CopyDepthPass m_CopyDepthPass;
CopyColorPass m_CopyColorPass;
DrawObjectsPass m_RenderTransparentForwardPass;
#if UNITY_EDITOR
SceneViewDepthCopyPass m_SceneViewDepthCopyPass;
#endif

public RenderTargetHandle m_CameraDepthAttachment;
RenderTargetHandle m_AfterPostProcessColor;
RenderTargetHandle m_ColorGradingLut;
RenderTargetHandle m_OpaqueColor;
RenderTargetHandle m_DepthTexture;

{
Material blitMaterial = CoreUtils.CreateEngineMaterial(data.shaders.blitPS);
Material copyDepthMaterial = CoreUtils.CreateEngineMaterial(data.shaders.copyDepthPS);
Material samplingMaterial = CoreUtils.CreateEngineMaterial(data.shaders.samplingPS);
m_DepthPrepass = new DepthOnlyPass(RenderPassEvent.BeforeRenderingPrepasses, RenderQueueRange.opaque, -1);
m_FinalBlitPass = new FinalBlitPass(RenderPassEvent.AfterRendering, blitMaterial);
m_CopyDepthPass = new CopyDepthPass(RenderPassEvent.BeforeRenderingOpaques, copyDepthMaterial);
m_FinalBlitPass = new FinalBlitPass(RenderPassEvent.AfterRendering, blitMaterial);
m_CopyColorPass = new CopyColorPass(RenderPassEvent.BeforeRenderingTransparents, samplingMaterial);
m_RenderTransparentForwardPass = new DrawObjectsPass("Render Transparents", false, RenderPassEvent.BeforeRenderingTransparents, RenderQueueRange.transparent, -1, StencilState.defaultValue, 0);
#if UNITY_EDITOR
m_SceneViewDepthCopyPass = new SceneViewDepthCopyPass(RenderPassEvent.AfterRendering + 9, copyDepthMaterial);
#endif

m_CameraColorAttachment.Init("_CameraColorTexture");
m_CameraDepthAttachment.Init("_CameraDepthAttachment");
m_AfterPostProcessColor.Init("_AfterPostProcessTexture");
m_OpaqueColor.Init("_CameraOpaqueTexture");
m_ColorGradingLut.Init("_InternalGradingLut");
m_DepthTexture.Init("_CameraDepthTexture");
m_ForwardLights = new ForwardLights();

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)
if (renderingData.cameraData.requiresOpaqueTexture)
m_CopyDepthPass.Setup(m_ActiveCameraDepthAttachment, m_DepthTexture);
EnqueuePass(m_CopyDepthPass);
// TODO: Downsampling method should be store in the renderer isntead of in the asset.
// We need to migrate this data to renderer. For now, we query the method in the active asset.
Downsampling downsamplingMethod = UniversalRenderPipeline.asset.opaqueDownsampling;
m_CopyColorPass.Setup(m_ActiveCameraColorAttachment.Identifier(), m_OpaqueColor, downsamplingMethod);
EnqueuePass(m_CopyColorPass);
EnqueuePass(m_RenderTransparentForwardPass);
if (postProcessEnabled)
{
if (requiresFinalPostProcessPass)

15
Assets/Rendering/MainRenderPass.cs


int width = cameraTargetDescriptor.width;
int height = cameraTargetDescriptor.height;
colorAttachmentDescriptor.ConfigureTarget(renderer.m_CameraColorAttachment.Identifier(), false, true);
depthAttachmentDescriptor.ConfigureTarget(renderer.m_CameraDepthAttachment.Identifier(), false, true);
colorAttachmentDescriptor.ConfigureClear(renderingData.cameraData.camera.backgroundColor);
var descriptors = new NativeArray<AttachmentDescriptor>(
new[] { colorAttachmentDescriptor, depthAttachmentDescriptor },
Allocator.Temp);

descriptors.Dispose();
NativeArray<int> attachmentIndices = new NativeArray<int>(new[] { 0 }, Allocator.Temp);
// Opaques + Skybox Subpass
}
// Caustics Subpass
attachmentIndices = new NativeArray<int>(new[]{0}, Allocator.Temp);
var inputIndices = new NativeArray<int>(new[]{1}, Allocator.Temp);
using (context.BeginScopedSubPass(attachmentIndices, inputIndices, false))
{
attachmentIndices.Dispose();
inputIndices.Dispose();
//context.DrawRenderers(renderingData.cullResults, ref transparentDrawingSettings, ref m_TransparentFilteringSettings);
}
}
}

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


float4 positionOS : SV_POSITION;
};
TEXTURE2D(_CameraDepthTexture); SAMPLER(sampler_CameraDepthTexture);
UNITY_DECLARE_FRAMEBUFFER_INPUT_FLOAT(Depth);
TEXTURE2D(_CausticMap); SAMPLER(sampler_CausticMap);
half _Size;

real4 frag (Varyings input) : SV_Target
{
real depth = SAMPLE_DEPTH_TEXTURE( _CameraDepthTexture, sampler_CameraDepthTexture, input.uv);
float depth = UNITY_READ_FRAMEBUFFER_INPUT(Depth, input.uv);
//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;

正在加载...
取消
保存