Skip to content

Commit

Permalink
Changed CustomPass to render a nyan cat overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
phi-lira committed Aug 10, 2018
1 parent 04225c9 commit 85028a4
Show file tree
Hide file tree
Showing 11 changed files with 185 additions and 140 deletions.
45 changes: 45 additions & 0 deletions Assets/Shaders/CustomBlit.shader
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
Shader "Hidden/SIGGRAPH Studio/CustomBlit"
{
Properties
{
_BlitTex("BlitTexture", 2D) = "white" {}
}
SubShader
{
Tags { "RenderPipeline" = "LightweightPipeline" }

Pass
{
Blend SrcAlpha OneMinusSrcAlpha
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag

#include "LWRP/ShaderLibrary/Core.hlsl"

TEXTURE2D(_BlitTex);
SAMPLER(sampler_BlitTex);

struct VertexOutput
{
float4 positionCS : SV_POSITION;
float3 uv0 : TEXCOORD0;
};

VertexOutput vert (float4 positionOS : POSITION, float uv0 : TEXCOORD0)
{
VertexOutput OUT;
OUT.positionCS = TransformObjectToHClip(positionOS.xyz);
OUT.uv0 = uv0;
return OUT;
}

half4 frag (VertexOutput IN) : SV_Target
{
half3 color = SAMPLE_TEXTURE2D(_BlitTex, sampler_BlitTex, IN.uv0).rgb;
return half4(color, 0.5);
}
ENDHLSL
}
}
}
9 changes: 9 additions & 0 deletions Assets/Shaders/CustomBlit.shader.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added Assets/Textures/nyan_cat.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
88 changes: 88 additions & 0 deletions Assets/Textures/nyan_cat.jpg.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 43 additions & 32 deletions Assets/_Completed/CustomPassGetter.cs
Original file line number Diff line number Diff line change
@@ -1,42 +1,53 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Experimental.Rendering.LightweightPipeline;
using UnityEngine.Rendering;

public class CustomPassGetter : MonoBehaviour, IAfterOpaquePass
using UnityEngine.Rendering;

namespace UnityEngine.Experimental.Rendering.LightweightPipeline
{
private CustomPass pass = new CustomPass();

public ScriptableRenderPass GetPassToEnqueue(RenderTextureDescriptor baseDescriptor, RenderTargetHandle colorAttachmentHandle,
RenderTargetHandle depthAttachmentHandle)
public class CustomPassGetter : MonoBehaviour, IAfterOpaquePass
{
pass.Setup(colorAttachmentHandle, depthAttachmentHandle);
return pass;
public Texture2D m_OverlayTexture;
private CustomPass pass = new CustomPass();

public ScriptableRenderPass GetPassToEnqueue(RenderTextureDescriptor baseDescriptor,
RenderTargetHandle colorAttachmentHandle,
RenderTargetHandle depthAttachmentHandle)
{
pass.Setup(colorAttachmentHandle, m_OverlayTexture);
return pass;
}
}
}


public class CustomPass : ScriptableRenderPass
{
public override void Execute(ScriptableRenderer renderer, ref ScriptableRenderContext context, ref CullResults cullResults,
ref RenderingData renderingData)
public class CustomPass : ScriptableRenderPass
{
CommandBuffer cmd = CommandBufferPool.Get("Render");
cmd.SetRenderTarget(colorhandle.Identifier(), depthHandle.Identifier());
cmd.ClearRenderTarget(true, true, Color.blue);
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}
public override void Execute(ScriptableRenderer renderer, ref ScriptableRenderContext context,
ref CullResults cullResults,
ref RenderingData renderingData)
{
if (m_Material == null)
m_Material = CoreUtils.CreateEngineMaterial(Shader.Find("Hidden/SIGGRAPH Studio/CustomBlit"));
m_Material.SetTexture("_BlitTex", m_OverlayTexture);

public void Setup(RenderTargetHandle colorAttachmentHandle, RenderTargetHandle depthAttachmentHandle)
{
this.colorhandle = colorAttachmentHandle;
this.depthHandle = depthAttachmentHandle;
}
if (m_OverlayTexture != null)
{
MaterialPropertyBlock props = new MaterialPropertyBlock();
props.SetTexture("_BlitTex", m_OverlayTexture);
}

CommandBuffer cmd = CommandBufferPool.Get("Render Overlay");
cmd.Blit(m_OverlayTexture, colorAttachment.Identifier(), m_Material);
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}

RenderTargetHandle colorhandle { get; set; }
public void Setup(RenderTargetHandle colorAttachmentHandle, Texture2D overlayTexture)
{
colorAttachment = colorAttachmentHandle;
m_OverlayTexture = overlayTexture;
}

RenderTargetHandle depthHandle { get; set; }
private Material m_Material = null;
private RenderTargetHandle colorAttachment;
private Texture2D m_OverlayTexture;

}
}
File renamed without changes.
8 changes: 0 additions & 8 deletions Assets/_Completed/Scripts.meta

This file was deleted.

8 changes: 0 additions & 8 deletions Assets/_Completed/TraditionalDeferredRenderer.meta

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 85028a4

Please sign in to comment.