@woland said:
/* a Displace Shader Actor proposed by Jacques Hoepffner after isadora Werkstatt 2017 updated by Mark Coniglio to move the pixels based on a displace amount and an angle instead of separate x/y inputs this version also calculates the actual greyscale brightness of the pixel using standard a conversion algorithm Note that this code will not produce the same results as the built-in Isadora Displace actor. */ // greyscale weights for RGB to gray conversion const vec3 sGrayScaleWeights = vec3(0.3086, 0.6094, 0.0820); // used to convert from degrees to radians const float sDegreesToRadians = 0.01745329252; // 2 texture inputs uniform sampler2D tex0; uniform sampler2D tex1; // ISADORA_FLOAT_PARAM(amount, amtt, 0.0, 100.0, 50.0, "Displace amount."); uniform float amount; // ISADORA_FLOAT_PARAM(angle, angl, 0.0, 360.0, 0.0, "Displace angle"); uniform float angle; void main(void) { // Convert angle to radians float radians = angle * sDegreesToRadians; // Calculate offset direction based on angle vec2 offset_direction = vec2(sin(radians), cos(radians)); // Sample the brightness from tex1 vec4 c1 = texture2D(tex1, gl_TexCoord[0].st); // Convert the sampled color to luminance float luminance = dot(c1.rgb, sGrayScaleWeights); // Calculate the displacement offset vec2 displacement = offset_direction * (luminance - 0.5) * (amount / 100.0); // Calculate the source coordinates in tex0 vec2 src_coord = gl_TexCoord[0].st + displacement; // Sample the color from tex0 at the displaced coordinates vec4 color = texture2D(tex0, src_coord); // Output the final color gl_FragColor = color; }
Thanks for the code Impro