Skip to content

Commit

Permalink
Updated completed scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
phi-lira committed Aug 15, 2018
1 parent d4175cf commit 4b781bc
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 217 deletions.
3 changes: 2 additions & 1 deletion Assets/MyDeferredRenderer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using UnityEngine.Rendering;
using System.Collections.Generic;
using UnityEngine.Rendering;

namespace UnityEngine.Experimental.Rendering.LightweightPipeline
{
Expand Down
60 changes: 0 additions & 60 deletions Assets/_Completed/AddNyanCatAfterOpaque.cs

This file was deleted.

51 changes: 51 additions & 0 deletions Assets/_Completed/AddPassAfterOpaqueCompleted.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using UnityEngine.Rendering;

namespace UnityEngine.Experimental.Rendering.LightweightPipeline
{
[ExecuteInEditMode]
public class AddPassAfterOpaqueCompleted : MonoBehaviour, IAfterOpaquePass
{
const string k_CustomBlitShader = "Hidden/SIGGRAPH Studio/CustomBlit";

public Texture2D m_NyanCatTexture;
MyNyanCatPassCompleted m_NyanCat;

Material m_Material;

public void OnEnable()
{
m_NyanCat = new MyNyanCatPassCompleted();
m_Material = CoreUtils.CreateEngineMaterial(Shader.Find(k_CustomBlitShader));
}

public ScriptableRenderPass GetPassToEnqueue(RenderTextureDescriptor desc, RenderTargetHandle colorHandle, RenderTargetHandle depthHandle)
{
m_NyanCat.Setup(m_NyanCatTexture, colorHandle.Identifier(), m_Material);
return m_NyanCat;
}
}

public class MyNyanCatPassCompleted : ScriptableRenderPass
{
Texture2D m_NyanCatTexture;
RenderTargetIdentifier m_DestinationTarget;
Material m_Material;

public void Setup(Texture2D texture, RenderTargetIdentifier destination, Material material)
{
m_NyanCatTexture = texture;
m_DestinationTarget = destination;
m_Material = material;
}

public override void Execute(ScriptableRenderer renderer, ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData)
{
m_Material.SetTexture("_BlitTex", m_NyanCatTexture);

CommandBuffer cmd = CommandBufferPool.Get("Render Nyan Cat");
cmd.Blit(m_NyanCatTexture, m_DestinationTarget, m_Material);
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}
}
}
109 changes: 109 additions & 0 deletions Assets/_Completed/MyDeferredRendererCompleted.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
using System.Collections.Generic;
using UnityEngine.Rendering;

namespace UnityEngine.Experimental.Rendering.LightweightPipeline
{
[ExecuteInEditMode]
public class MyDeferredRendererCompleted : MonoBehaviour, IRendererSetup
{
MyGBufferAndLightingPass m_RenderPass;

public void OnEnable()
{
m_RenderPass = new MyGBufferAndLightingPass();
}

public void Setup(ScriptableRenderer renderer, ref ScriptableRenderContext context, ref CullResults cullResults, ref RenderingData renderingData)
{
renderer.Clear();
renderer.EnqueuePass(m_RenderPass);
}
}

public class MyGBufferAndLightingPassCompleted : ScriptableRenderPass
{
RenderPassAttachment m_GBufferDiffuse;
RenderPassAttachment m_GBufferSpecularAndRoughness;
RenderPassAttachment m_GBufferNormal;
RenderPassAttachment m_CameraTarget;
RenderPassAttachment m_Depth;

Material m_DeferredShadingMaterial;
MaterialPropertyBlock m_LightPropertiesBlock = new MaterialPropertyBlock();

public MyGBufferAndLightingPassCompleted()
{
m_GBufferDiffuse = new RenderPassAttachment(RenderTextureFormat.ARGB32);
m_GBufferSpecularAndRoughness = new RenderPassAttachment(RenderTextureFormat.ARGB32);
m_GBufferNormal = new RenderPassAttachment(RenderTextureFormat.ARGB2101010);
m_CameraTarget = new RenderPassAttachment(RenderTextureFormat.ARGBHalf);
m_Depth = new RenderPassAttachment(RenderTextureFormat.Depth);

m_DeferredShadingMaterial = CoreUtils.CreateEngineMaterial(Shader.Find("Hidden/SIGGRAPH Studio/DeferredLighting"));

m_CameraTarget.Clear(Color.black);
m_Depth.Clear(Color.black);
}

public override void Execute(ScriptableRenderer renderer, ref ScriptableRenderContext context,
ref CullResults cullResults, ref RenderingData renderingData)
{
Camera camera = renderingData.cameraData.camera;

m_CameraTarget.BindSurface(BuiltinRenderTextureType.CameraTarget, false, true);
context.SetupCameraProperties(camera, false);

using (RenderPass rp = new RenderPass(context, camera.pixelWidth, camera.pixelHeight, 1, new[] {m_GBufferDiffuse, m_GBufferSpecularAndRoughness, m_GBufferNormal, m_CameraTarget}, m_Depth))
{
using (new RenderPass.SubPass(rp, new[] {m_GBufferDiffuse, m_GBufferSpecularAndRoughness, m_GBufferNormal, m_CameraTarget}, null))
{
RenderGBuffer(context, cullResults, camera);
}

using (new RenderPass.SubPass(rp, new[] {m_CameraTarget}, new[] {m_GBufferDiffuse, m_GBufferSpecularAndRoughness, m_GBufferNormal, m_Depth}, true))
{
RenderLights(context, cullResults, renderingData.lightData);
}
}
}

public void RenderGBuffer(ScriptableRenderContext context, CullResults cullResults, Camera camera)
{
DrawRendererSettings drawSettings = new DrawRendererSettings(camera, new ShaderPassName("GBuffer Pass"))
{
sorting = { flags = SortFlags.CommonOpaque},
rendererConfiguration = RendererConfiguration.PerObjectLightmaps | RendererConfiguration.PerObjectLightProbe | RendererConfiguration.PerObjectReflectionProbes,
};

FilterRenderersSettings filterSettings = new FilterRenderersSettings(true)
{
renderQueueRange = RenderQueueRange.opaque,
};

context.DrawRenderers(cullResults.visibleRenderers, ref drawSettings, filterSettings);
}

public void RenderLights(ScriptableRenderContext context, CullResults cullResults, LightData lightData)
{
CommandBuffer cmd = CommandBufferPool.Get("Render Deferred Lights");
List<VisibleLight> visibleLights = lightData.visibleLights;

for (int i = 0 ; i < visibleLights.Count; ++i)
{
VisibleLight currLight = visibleLights[i];
if (currLight.lightType != LightType.Directional)
continue;

Vector4 lightDirection = -currLight.localToWorld.GetRow(2);
Vector4 lightColor = currLight.finalColor;
m_LightPropertiesBlock.Clear();
m_LightPropertiesBlock.SetVector("_MainLightPosition", lightDirection);
m_LightPropertiesBlock.SetVector("_MainLightColor", lightColor);
cmd.DrawMesh(LightweightPipeline.fullscreenMesh, Matrix4x4.identity, m_DeferredShadingMaterial, 0, 0, m_LightPropertiesBlock);
}

context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}
}
}
156 changes: 0 additions & 156 deletions Assets/_Completed/OnTileDeferredRenderer.cs

This file was deleted.

0 comments on commit 4b781bc

Please sign in to comment.