I’m trying to recreate GLSL code in TOPs.
// Uniforms
uniform vec2 iResolution; // Output resolution
// Sample the luminance-like value: length of RGB vector at a UV coordinate
float getLuminanceMagnitude(vec2 uv)
{
vec3 rgb = texture(sTD2DInputs[0], uv).rgb;
return length(rgb); // Gives a single scalar representing intensity
}
// Compute the gradient of luminance using central differences
vec2 computeLuminanceGradient(vec2 uv, float delta)
{
vec2 offset = vec2(delta, 0.0);
float dx = getLuminanceMagnitude(uv + offset.xy) - getLuminanceMagnitude(uv - offset.xy);
float dy = getLuminanceMagnitude(uv + offset.yx) - getLuminanceMagnitude(uv - offset.yx);
return vec2(dx, dy) / (delta*2.);
}
out vec4 fragColor;
void main()
{
vec2 uv = gl_FragCoord.xy / iResolution.xy;
// Compute luminance gradient
float pixel_delta = 1.0 / iResolution.y;
vec2 luminance_gradient = computeLuminanceGradient(uv, pixel_delta);
fragColor = vec4(luminance_gradient,1.,1.);
}
I created a TOPs network where I use transforms to offset the image in the x direction (1 and -1) and subtract them to create dx, and the same for dy. But the output is very different. The output of the GLSL code has more detail. How do I get the TOPs network to do something similar or closer to the GLSL code? Here is a toe with the TOPs network and the GLSL TOP.
normal_difference.5.toe (5.2 KB)