Back to shaders
Shader test bench
Chroma Zoom.fs
runnable fragment
Complete GLSL fragment shader. Stronghold runs it directly when the browser can compile it.
Code
uniform sampler2D inputImage;
uniform float master_zoom;
uniform float red_zoom;
uniform float green_zoom;
uniform float blue_zoom;
uniform vec2 center;
precision mediump float;
/*
{
"CATEGORIES" : [
"Color Effect",
"Stylize"
],
"ISFVSN" : "2",
"INPUTS" : [
{
"NAME" : "inputImage",
"TYPE" : "image"
},
{
"NAME" : "master_zoom",
"TYPE" : "float",
"MAX" : 2,
"DEFAULT" : 1,
"MIN" : 0.1
},
{
"NAME" : "red_zoom",
"TYPE" : "float",
"MAX" : 1.5,
"DEFAULT" : 1,
"MIN" : 1
},
{
"NAME" : "green_zoom",
"TYPE" : "float",
"MAX" : 1.5,
"DEFAULT" : 1,
"MIN" : 1
},
{
"NAME" : "blue_zoom",
"TYPE" : "float",
"MAX" : 1.5,
"DEFAULT" : 1,
"MIN" : 1
},
{
"NAME" : "center",
"TYPE" : "point2D",
"MAX" : [
1,
1
],
"DEFAULT" : [
0.5,
0.5
],
"MIN" : [
0,
0
]
}
],
"CREDIT" : "by toneburst"
}
*/
void main() {
vec2 loc;
vec2 modifiedCenter;
loc = (gl_FragCoord.xy / u_resolution.xy);
modifiedCenter = center;
vec2 locR = (loc - modifiedCenter)*(1.0/(red_zoom*master_zoom)) + modifiedCenter;
vec2 locG = (loc - modifiedCenter)*(1.0/(green_zoom*master_zoom)) + modifiedCenter;
vec2 locB = (loc - modifiedCenter)*(1.0/(blue_zoom*master_zoom)) + modifiedCenter;
vec4 outPix;
outPix.r = texture2D(inputImage, locR).r;
outPix.g = texture2D(inputImage, locG).g;
outPix.b = texture2D(inputImage, locB).b;
loc.x = (loc.x - modifiedCenter.x)*(1.0/master_zoom) + modifiedCenter.x;
loc.y = (loc.y - modifiedCenter.y)*(1.0/master_zoom) + modifiedCenter.y;
outPix.a = texture2D(inputImage, loc).a;
gl_FragColor = outPix;
}