Skip to content

Instantly share code, notes, and snippets.

@smokelore
Created February 14, 2017 20:43
Show Gist options
  • Select an option

  • Save smokelore/d9c46388221d779c86bc63d27efae6e2 to your computer and use it in GitHub Desktop.

Select an option

Save smokelore/d9c46388221d779c86bc63d27efae6e2 to your computer and use it in GitHub Desktop.
Shader "CookbookShaders/GrabPass"
{
SubShader
{
Tags
{
"Queue" = "Transparent"
"IgnoreProjector" = "True"
"RenderType" = "Opaque"
}
ZWrite On Lighting Off Cull Off Fog{ Mode Off } Blend One Zero
GrabPass {} // first pass is a grab pass
Pass // rest of the code is in the second pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _GrabTexture; // automatically generated by the GrabPass
struct vertInput
{
float4 vertex : POSITION;
};
struct vertOutput
{
float4 vertex : POSITION;
float4 uvgrab : TEXCOORD1;
};
vertOutput vert(vertInput v)
{
vertOutput o;
o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
o.uvgrab = ComputeGrabScreenPos(o.vertex); // grab screen texture
return o;
}
half4 frag(vertOutput i) : COLOR
{
fixed4 col = tex2Dproj(_GrabTexture, UNITY_PROJ_COORD(i.uvgrab)); // apply the screen texture in the correct position
col += half4(0.5, 0, 0, 0); // add a little red tint just so we can see it
return col;
}
ENDCG
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment