Created
May 11, 2015 09:39
-
-
Save aras-p/ca86e6dddc46def4d1a8 to your computer and use it in GitHub Desktop.
Framebuffer fetch shader in Unity
This file contains 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
#include "UnityCG.cginc" | |
#pragma vertex vert | |
#pragma fragment frag | |
// in practice: only compile for gles2,gles3,metal | |
#pragma only_renderers framebufferfetch | |
struct appdata_t { | |
float4 vertex : POSITION; | |
float2 texcoord : TEXCOORD0; | |
}; | |
struct v2f { | |
float4 vertex : SV_POSITION; | |
fixed4 color : TEXCOORD0; | |
}; | |
v2f vert (appdata_t v) | |
{ | |
v2f o; | |
o.vertex = mul(UNITY_MATRIX_MVP, v.vertex); | |
o.color.rg = v.texcoord*4.0; | |
o.color.ba = 0; | |
return o; | |
} | |
void frag (v2f i, inout fixed4 ocol : SV_Target) | |
{ | |
i.color = frac(i.color); | |
ocol.rg = i.color.rg; | |
ocol.b *= 1.5; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think only Apple hardware supports it as-is (so basically "Metal only" these days). On Vulkan you'd want to use "sub-pass attachments" or some stuff like that to achieve something similar, but then I know almost nothing about Vulkan.