Skip to content

Commit

Permalink
Added transparency to custom pass.
Browse files Browse the repository at this point in the history
  • Loading branch information
phi-lira committed Aug 10, 2018
1 parent 85028a4 commit d918685
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
8 changes: 5 additions & 3 deletions Assets/Shaders/CustomBlit.shader
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Properties
{
_BlitTex("BlitTexture", 2D) = "white" {}
_Alpha("Alpha", Float) = 0.5
}
SubShader
{
Expand All @@ -19,14 +20,15 @@

TEXTURE2D(_BlitTex);
SAMPLER(sampler_BlitTex);
half _Alpha;

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

VertexOutput vert (float4 positionOS : POSITION, float uv0 : TEXCOORD0)
VertexOutput vert (float4 positionOS : POSITION, float2 uv0 : TEXCOORD0)
{
VertexOutput OUT;
OUT.positionCS = TransformObjectToHClip(positionOS.xyz);
Expand All @@ -37,7 +39,7 @@
half4 frag (VertexOutput IN) : SV_Target
{
half3 color = SAMPLE_TEXTURE2D(_BlitTex, sampler_BlitTex, IN.uv0).rgb;
return half4(color, 0.5);
return half4(color, _Alpha);
}
ENDHLSL
}
Expand Down
35 changes: 21 additions & 14 deletions Assets/_Completed/CustomPassGetter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,59 @@

namespace UnityEngine.Experimental.Rendering.LightweightPipeline
{
[ExecuteInEditMode]
public class CustomPassGetter : MonoBehaviour, IAfterOpaquePass
{
public Texture2D m_OverlayTexture;
private CustomPass pass = new CustomPass();
public float m_Alpha = 0.5f;
private CustomPass m_Pass;

public void OnEnable()
{
Material material = CoreUtils.CreateEngineMaterial(Shader.Find("Hidden/SIGGRAPH Studio/CustomBlit"));
m_Pass = new CustomPass(material);
}

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


public class CustomPass : ScriptableRenderPass
{
public CustomPass(Material material)
{
m_Material = material;
}

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);
m_Material.SetFloat("_Alpha", m_Alpha);

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

public void Setup(RenderTargetHandle colorAttachmentHandle, Texture2D overlayTexture)
public void Setup(RenderTargetHandle colorAttachmentHandle, Texture2D overlayTexture, float alpha)
{
colorAttachment = colorAttachmentHandle;
m_OverlayTexture = overlayTexture;
m_Alpha = alpha;
}

private Material m_Material = null;
private Material m_Material = null;
private RenderTargetHandle colorAttachment;
private Texture2D m_OverlayTexture;

private float m_Alpha;
}
}

0 comments on commit d918685

Please sign in to comment.