1
\$\begingroup\$

How can I make grab Shader similar to https://docs.unity3d.com/Manual/SL-GrabPass.html in GLSL.

The idea, is that you grab exact pixels from background (ex. from composited renderTarget) and put on rendered object. So it's like 100% transparency, because it always has the pixels right behind. Later if you disort the pixels, can give very cool effects like https://www.shadertoy.com/view/Mdc3Rl.

SO far I have texture of background (plane to renderTarget), and object cube right before it. My vertex shader for cube is gl_Position = WVP * spos; and I have no idea how do the frag shader to copy the pixels from background. Any help appreciated.

enter image description here

\$\endgroup\$
0
\$\begingroup\$

For my setup it was as easy as:

vec2 uv = gl_FragCoord.xy / screenSize;

fragColor.rgb = texture(background, uv.xy).rgb;
fragColor.a = 1.0;
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.