Mirror Texture Coordinates

Post your awesome Wire patches here, share tutorials
Post Reply
Online
cat
Hasn't felt like this about software in a long time
Posts: 131
Joined: Fri Oct 08, 2004 11:03

Mirror Texture Coordinates

Post by cat »

This is something that comes for free when you can define samplers, but it seems isf doesn't support it, so here is a shader that mirror repeats your coordinates, and allows you to offset your texture (and scales from the center not a corner) useful for many different shaders and effects


Code: Select all

/*{
    "CREDIT": "www.colour-burst.com",
    "DESCRIPTION": "",
    "CATEGORIES": [ "generator" ],
    "INPUTS": [
        {
            "TYPE": "image",
            "NAME": "image0"
        },
	 {
            "TYPE": "float",
            "NAME": "scaleX"
        },
	 {
            "TYPE": "float",
            "NAME": "scaleY"
        },
	 {
            "TYPE": "float",
            "NAME": "shiftX"
        },
	 {
            "TYPE": "float",
            "NAME": "shiftY"
        }
    ]
}*/

/*
ISF Reference
=========================

1) Valid inputs:
    - "event"
    - "bool"
    - "long"
    - "float"
    - "point2D"
    - "color"
    - "image"
    - "audio"
    - "audioFFT"

2) Functions:
    - IMG_NORM_PIXEL() -> get a pixel from input with normalized coordinates
    - IMG_PIXEL() -> get a pixel from input with screen space coordinates

3) Predefined variables:
    - RENDERSIZE (resolution of the shader)
    - TIME (run time)
    - gl_FragCoord.xy (screen space coordinates of current fragment)
    - isf_FragNormCoord.xy (normalized coordinates)

To learn more see:
https://github.com/mrRay/ISF_Spec/
*/
float mirror (float x){
	float peak = 1;
	x = mod(x,2);
	int en = int(x<peak);
	x = (x*en) +  ( (1-en)*( min(x,peak) + peak-x ) );
	return x;
}
vec2 mirror (vec2 cd){
	float peak = 1;
	cd = mod(cd,2);
	int enx = int(cd.x<peak);
	int eny = int(cd.y<peak);
	cd.x = (cd.x*enx) +  ( (1-enx)*( min(cd.x,peak) + peak-cd.x ) );
	cd.y = (cd.y*eny) +  ( (1-eny)*( min(cd.y,peak) + peak-cd.y ) );
	return cd;  
}

void main() {
	vec2 uv = ((isf_FragNormCoord.xy-.5)*vec2(scaleX,scaleY) )+0.5 +vec2(shiftX,shiftY); //scale from centre
	uv = mirror(uv); // mirror repeat coords vec2(shift,0)

	vec4 col = IMG_NORM_PIXEL(image0,uv);
    gl_FragColor = col;
}
Attachments
Cat_MirrorRepeat.wire
(11 KiB) Downloaded 52 times

Post Reply