Created
February 14, 2017 20:43
-
-
Save smokelore/d9c46388221d779c86bc63d27efae6e2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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