Taken iq’s background transparent code and Dr. Neyret’s advice: This shader can be used for rendering pop-up images in a 3D environment.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
// Image Fade-In Effect, CC0 // Forked from iq's invisible shader with transparent background: [url]https://www.shadertoy.com/view/XljSRK[/url] float backgroundPattern( in vec2 p ) { vec2 uv = p + 0.1*texture2D( iChannel2, 0.05*p ).xy; return texture2D( iChannel1, 16.0*uv ).x; } vec3 getBackground(in vec2 coord) { float fa = backgroundPattern( (coord + 0.0) / iChannelResolution[0].xy ); float fb = backgroundPattern( (coord - 0.5) / iChannelResolution[0].xy ); return vec3( 0.822 + 0.4*(fa-fb) ); } float getFadeInWeight(vec2 uv) { float edge = 0.3 * abs(sin(0.5)); // taken FabriceNeyret2's advice vec4 v = smoothstep(0., edge, vec4(uv, 1. - uv) ); return v.x * v.y * v.z * v.w; } void mainImage( out vec4 fragColor, in vec2 fragCoord ) { vec2 uv = fragCoord.xy / iResolution.xy; vec3 bg = getBackground(fragCoord); vec3 col = texture2D(iChannel0, uv).rgb; float alpha = getFadeInWeight(uv); fragColor = vec4(mix(bg, col, alpha), 1.0); } |