Previous topicNext topic

Fractal ISF Shader

Live performances or exported movies created with Magic.
Post Reply
SelfDrivingCarp
Posts: 20
Joined: Sat Jan 06, 2024 5:44 am

Fractal ISF Shader

Post by SelfDrivingCarp »

Put together a really simple ISF shader to do this fractal thing. The background of each frame is two rotated copies of the previous frame with the input image overlayed on top with basic alpha blending.

https://youtu.be/O5pmEglsJjU
Terry Payman
Posts: 807
Joined: Sun Sep 14, 2014 8:15 am
Location: UK
Contact:

Re: Fractal ISF Shader

Post by Terry Payman »

Really cool!
Are you willing to share your ISF?
SelfDrivingCarp
Posts: 20
Joined: Sat Jan 06, 2024 5:44 am

Re: Fractal ISF Shader

Post by SelfDrivingCarp »

Code: Select all

/*{
	"DESCRIPTION": "Fill the bockground with recursive copies of inputImage",
	"CREDIT": "@SelfDrivingCarp",
	"ISFVSN": "2",
	"CATEGORIES": [
		"Effect"
	],
	"INPUTS": [
		{
			"NAME": "inputImage",
			"TYPE": "image"
		}
	],
	"PASSES": [
		{
			"TARGET":"lastOutput",
            		"PERSISTENT": true
		},
		{
			"DESCRIPTION": "output"
		}
	]
	
}*/

vec4 baseImage(vec2 p) {
    // read this pixel from inputImage
    vec4 col = IMG_NORM_PIXEL(inputImage, p);
    
    // grab th color that would go under it. If it's on the left side, we'll
    // from lastOutput rotated and scaled one way, on the right, the other way
    vec2 underCoord;
    if (p.x < 0.5) {
        underCoord.x = p.y;
        underCoord.y = p.x*2.0;
    } else {
        underCoord.x = 1.0-p.y;
        underCoord.y = (1.0-p.x)*2.0;
    }
    
    // grab the underneath pixel from lastOutput. Add some transparency
    vec4 under = IMG_NORM_PIXEL(lastOutput, underCoord);
    under.a *= 0.9;
    
    // combine the input color with the under color according to the alpha
    // channel of the input color. For the resulting alpha channel, use the
    // higher alpha value of input and under color
    col.rgb = (col.rgb * col.a) + (under.rgb * (1.0-col.a));
    col.a = max(col.a,under.a);
    return col;
}


void main()	{
	vec4		inputPixelColor;
	
	if (PASSINDEX == 0) {
            // Our first pass composites the new input with the previous frame,
            // writing the output to the persistent lastOutput buffer
	    inputPixelColor = baseImage(isf_FragNormCoord.xy);
	} else {
            // Our second pass copies from the persistent buffer to our output
	    inputPixelColor = IMG_NORM_PIXEL(lastOutput, isf_FragNormCoord.xy);
	}
	
	gl_FragColor = inputPixelColor;
}
There's really not much to it. There's probably more efficient ways to do this and I'd like to add in a delay effect to the frames but that will be for another time.

This won't do anything interesting without alpha transparency in the input.
Sadler
Posts: 1348
Joined: Sat Aug 02, 2014 7:10 pm
Location: London, UK

Re: Fractal ISF Shader

Post by Sadler »

Lots of fun with different content - thank you for sharing!
Screenshot 2025-05-09 181316.jpg
Screenshot 2025-05-09 181316.jpg (203.7 KiB) Viewed 10563 times
Post Reply