Translate shader from ISF to GLSL...
-
Hi, I am trying to convert ISF shaders into GLSL shaders, so that I can use them in Isadora.
I got inspired by DusX and Marks recommendation of the ISF Editor (https://www.interactiveshaderf...), which offers shaders in GLSL code with an Json header.To use them in Isadora the Json header needs to be translated back into GLSL-language.
ISF allowes these types of valuables:
The GLSL syntax for FLOAT is something like:
// ISADORA_FLOAT_PARAM(gridSize, grid, 1.0, 256.0, 30.0, "Help text");
which defines the parameter to Isadora and
uniform float gridSize;
which defines the variable in GLSL. I found the explanation in the GLSL tutorial from Mark (https://support.troikatronix.c...)
Can anybody with more programming experience than me help me figuring out the syntax for the other ones?
Especially point2D and image (which I figured out, but can not really explain it...)
Best regards, Tom
-
point2D is basically just a point on an 2D matrix, you can't create this type of input in Isadora natively, what we can do is 2 floats called x and y that combined make a point on an 2D matrix.
// ISADORA_FLOAT_PARAM(x, xpoint, 0.0, 100.0, 100.0, "The x coordinate of our point"); // ISADORA_FLOAT_PARAM(y, ypoint, 0.0, 100.0, 100.0, "The y coordinate of our point"); // We need two containers for our float values before we are allowed to parse them to our vec2 function. uniform float x; uniform float y; // Create a new point2D based on our Isadora parameters. vec2 point = vec2(x, y);
Image is just the below :
uniform sampler2D tex0
-
Dear All,
This morning, because of this thread and another thread that was branching to this topic, I started writing a command line utility to see if I could convert a ISF file to an Isadora GLSL file. Looks promising, but I'm not giving a timeline on this because there are other tasks at the forefront. That said, if I can get it done if a few more hours of work I'll post it here for people to try.
Best Wishes,
Mark -
Dear All,
So I've made progress on the ISF converter this morning. Here's are my first two successes: an ISF plugin called "Bad TV" and one called "Bounce", both converted to the Isadora GLSL format.
Enjoy,
Mark---------- BAD TV GLSL CODE STARTS HERE----------
// ISADORA_FLOAT_PARAM(noiseLevel, PIXD, 0, 1, 0.5, "No help available.") // ISADORA_FLOAT_PARAM(distortion1, OLTS, 0, 5, 1, "No help available.") // ISADORA_FLOAT_PARAM(distortion2, *wl3, 0, 5, 5, "No help available.") // ISADORA_FLOAT_PARAM(speed, rth=, 0, 1, 0.3, "No help available.") // ISADORA_FLOAT_PARAM(scroll, 2*^j, 0, 1, 0, "No help available.") // ISADORA_FLOAT_PARAM(scanLineThickness, fhue, 1, 50, 25, "No help available.") // ISADORA_FLOAT_PARAM(scanLineIntensity, bj%N, 0, 1, 0.5, "No help available.") // ISADORA_FLOAT_PARAM(scanLineOffset, f*P3, 0, 1, 0, "No help available.") uniform sampler2D tex0; uniform float noiseLevel; uniform float distortion1; uniform float distortion2; uniform float speed; uniform float scroll; uniform float scanLineThickness; uniform float scanLineIntensity; uniform float scanLineOffset; uniform vec2 resolution; uniform float time; // Adapted from http://www.airtightinteractive... // Also uses adopted Ashima WebGl Noise: https://github.com/ashima/webg... /* * The MIT License * * Copyright (c) 2014 Felix Turner * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * */ // Start Ashima 2D Simplex Noise const vec4 C = vec4(0.211324865405187,0.366025403784439,-0.577350269189626,0.024390243902439); vec3 mod289(vec3 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; } vec2 mod289(vec2 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; } vec3 permute(vec3 x) { return mod289(((x*34.0)+1.0)*x); } float snoise(vec2 v) { vec2 i = floor(v + dot(v, C.yy) ); vec2 x0 = v - i + dot(i, C.xx); vec2 i1; i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0); vec4 x12 = x0.xyxy + C.xxzz; x12.xy -= i1; i = mod289(i); // Avoid truncation effects in permutation vec3 p = permute( permute( i.y + vec3(0.0, i1.y, 1.0 ))+ i.x + vec3(0.0, i1.x, 1.0 )); vec3 m = max(0.5 - vec3(dot(x0,x0), dot(x12.xy,x12.xy), dot(x12.zw,x12.zw)), 0.0); m = m*m ; m = m*m ; vec3 x = 2.0 * fract(p * C.www) - 1.0; vec3 h = abs(x) - 0.5; vec3 ox = floor(x + 0.5); vec3 a0 = x - ox; m *= 1.79284291400159 - 0.85373472095314 * ( a0*a0 + h*h ); vec3 g; g.x = a0.x * x0.x + h.x * x0.y; g.yz = a0.yz * x12.xz + h.yz * x12.yw; return 130.0 * dot(m, g); } // End Ashima 2D Simplex Noise const float tau = 6.28318530718; // use this pattern for scan lines vec2 pattern(vec2 pt) { float s = 0.0; float c = 1.0; vec2 tex = pt * resolution; vec2 point = vec2( c * tex.x - s * tex.y, s * tex.x + c * tex.y ) * (1.0/scanLineThickness); float d = point.y; return vec2(sin(d + scanLineOffset * tau + cos(pt.x * tau)), cos(d + scanLineOffset * tau + sin(pt.y * tau))); } float rand(vec2 co){ return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453); } void main() { vec2 p = gl_TexCoord[0].xy; float ty = time*speed; float yt = p.y - ty; //smooth distortion float offset = snoise(vec2(yt*3.0,0.0))*0.2; // boost distortion offset = pow( offset*distortion1,3.0)/max(distortion1,0.001); //add fine grain distortion offset += snoise(vec2(yt*50.0,0.0))*distortion2*0.001; //combine distortion on X with roll on Y vec2 adjusted = vec2(fract(p.x + offset),fract(p.y-scroll) ); vec4 result = texture2D(tex0, adjusted); vec2 pat = pattern(adjusted); vec3 shift = scanLineIntensity * vec3(0.3 * pat.x, 0.59 * pat.y, 0.11) / 2.0; result.rgb = (1.0 + scanLineIntensity / 2.0) * result.rgb + shift + (rand(adjusted * time) - 0.5) * noiseLevel; gl_FragColor = result; }
---------- BAD TV GLSL CODE ENDS HERE----------
---------- BOUNCE GLSL CODE STARTS HERE----------
// ISADORA_FLOAT_PARAM(progress, EzYH, 0, 1, 0, "No help available.")
// ISADORA_FLOAT_PARAM(bounces, hUY<, 0, 10, 2, "No help available.")
// ISADORA_FLOAT_PARAM(shadow_height, tBF6, 0, 1, 0.1, "No help available.")
// ISADORA_VEC4_COLOR_PARAM(shadow_colour, 3n%2, 0xFF000000, "No help available.") uniform sampler2D tex0;
uniform sampler2D tex1;
uniform float progress;
uniform float bounces;
uniform float shadow_height;
uniform vec4 shadow_colour; vec4 getFromColor(vec2 inUV) {
return texture2D(tex0, inUV);
}
vec4 getToColor(vec2 inUV) {
return texture2D(tex1, inUV);
} // Author: Adrian Purser
// License: MIT const float PI = 3.14159265358; vec4 transition (vec2 uv) {
float time = progress;
float stime = sin(time * PI / 2.);
float phase = time * PI * bounces;
float y = (abs(cos(phase))) * (1.0 - stime);
float d = uv.y - y;
return mix(
mix(
getToColor(uv),
shadow_colour,
step(d, shadow_height) * (1. - mix(
((d / shadow_height) * shadow_colour.a) + (1.0 - shadow_colour.a),
1.0,
smoothstep(0.95, 1., progress) // fade-out the shadow at the end
))
),
getFromColor(vec2(uv.x, uv.y + (1.0 - y))),
step(d, 0.0)
);
} void main() {
gl_FragColor = transition(gl_TexCoord[0].xy.xy);
}---------- BOUNCE GLSL CODE ENDS HERE----------
-
Wow, thanks a lot, you all! I am going to look at the code as soon as I get time....