Forums > Jitter

cf.edgedetect.jxs-help doesn't seem to be working?

January 19, 2010 | 7:51 am

No matter what I do, the cf.edgedetect.jxs-help patch in examples/jitter-examples/render/slap-helpers doesn’t seem to do anything: I just see a white output window, when I’m expecting to see something more like the output of jit.sobel.

Am I doing something wrong or is it broken?


January 19, 2010 | 5:27 pm

I looked in the javascript file and everything looks fine, but I too ran into complications. If you set the width, height and thresh to 1, 1, .25 you see some black artifacts appear, but no edge detection is happening. I’m guessing there’s a glitch somewhere in the javascript file that I can’t seem to find. Sorry!


January 19, 2010 | 8:27 pm

i was able to get an edge detection shader working based on the tutorial here:

http://www.ozone3d.net/tutorials/image_filtering.php

however, this requires you to use non-rectangular textures.
patch and shader below.

– Pasted Max Patch, click to expand. –

A 3×3 edge detection filter

#define KERNEL_SIZE 9

// Edge detection kernel (Laplacian filter).
// 0 1 0
// 1 -4 1
// 0 1 0
float kernel[KERNEL_SIZE];

varying vec2 texcoord0;

uniform sampler2D tex0;
uniform float width;
uniform float height;

float step_w = 1.0/width;
float step_h = 1.0/height;

vec2 offset[KERNEL_SIZE];

void main(void)
{
int i = 0;
vec4 sum = vec4(0.0);

offset[0] = vec2(-step_w, -step_h);
offset[1] = vec2(0.0, -step_h);
offset[2] = vec2(step_w, -step_h);

offset[3] = vec2(-step_w, 0.0);
offset[4] = vec2(0.0, 0.0);
offset[5] = vec2(step_w, 0.0);

offset[6] = vec2(-step_w, step_h);
offset[7] = vec2(0.0, step_h);
offset[8] = vec2(step_w, step_h);

kernel[0] = 0.0;
kernel[1] = 1.0;
kernel[2] = 0.0;
kernel[3] = 1.0;
kernel[4] = -4.0;
kernel[5] = 1.0;
kernel[6] = 0.0;
kernel[7] = 1.0;
kernel[8] = 0.0;

for(i=0; i


January 20, 2010 | 10:50 pm

Yeah, this is broken. A fix is in the next release. Here’s a modified shader for you. The issue was it was using device coordinates and not the texture coordinates, which the example had assumed to be the same thing.

FWIW, This is a greyscale based mask for edges. For jit.sobel style edge detection, please use cf.sobel.jxs.




A 3x3 edge detection filter




< ![CDATA[
varying vec2 texcoord0;

void main( void )
{
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
texcoord0 = vec2(gl_TextureMatrix[0] * gl_MultiTexCoord0);
}

]]>

< ![CDATA[
///////////////////////////////////////////////////////////////////////////////
//
// Copyright 2003, ATI Technologies, Inc., All rights reserved.
//
// Permission to use, copy, modify, and distribute this software and its
// documentation for any purpose and without fee is hereby granted,
// provided that the above copyright notice appear in all copies and derivative
// works and that both the copyright notice and this permission notice appear in
// support documentation, and that the name of ATI Technologies, Inc. not be used
// in advertising or publicity pertaining to distribution of the software without
// specific, written prior permission.
//
///////////////////////////////////////////////////////////////////////////////

// vertex to fragment shader io
varying vec2 texcoord0;

// globals
uniform float width;
uniform float height;
uniform float threshold;

// samplers
uniform sampler2DRect tex0;

// getGrey function
float
getGrey(vec4 c)
{
vec4 onethird;
vec4 cc;
float sum;
onethird = vec4 (0.333333,0.333333,0.333333,0);
cc = c;
sum = dot(onethird, cc);
return sum;
}

// entry point
void
main()
{
float K00 = -1.0;
float K01 = -2.0;
float K02 = -1.0;
float K10 = 0.0;
float K11 = 0.0;
float K12 = 0.0;
float K20 = 1.0;
float K21 = 2.0;
float K22 = 1.0;

vec2 ox = vec2 (0.0,0.0);
ox[0] = width;
vec2 oy = vec2 (0.0,0.0);
oy[1] = height;

float g00, g01, g02;
float g10, g11, g12;
float g20, g21, g22;
vec4 CC;

vec2 PP = texcoord0 - oy;
CC = texture2DRect(tex0, vec2(PP-ox));
g00 = getGrey(CC);
CC = texture2DRect(tex0, vec2(PP));
g01 = getGrey(CC);
CC = texture2DRect(tex0, vec2(PP+ox));
g02 = getGrey(CC);

PP = texcoord0;
CC = texture2DRect(tex0, vec2(PP-ox));
g10 = getGrey(CC);
CC = texture2DRect(tex0, vec2(PP));
g11 = getGrey(CC);
CC = texture2DRect(tex0, vec2(PP+ox));
g12 = getGrey(CC);

PP = texcoord0 + oy;
CC = texture2DRect(tex0, vec2(PP-ox));
g20 = getGrey(CC);
CC = texture2DRect(tex0, vec2(PP));
g21 = getGrey(CC);
CC = texture2DRect(tex0, vec2(PP+ox));
g22 = getGrey(CC);

float sx = 0.0, sy = 0.0;
sx = sx + g00 * K00;
sx = sx + g01 * K01;
sx = sx + g02 * K02;
sx = sx + g10 * K10;
sx = sx + g11 * K11;
sx = sx + g12 * K12;
sx = sx + g20 * K20;
sx = sx + g21 * K21;
sx = sx + g22 * K22;
sy = sy + g00 * K00;
sy = sy + g01 * K10;
sy = sy + g02 * K20;
sy = sy + g10 * K01;
sy = sy + g11 * K11;
sy = sy + g12 * K21;
sy = sy + g20 * K02;
sy = sy + g21 * K12;
sy = sy + g22 * K22;

float dist = sqrt(sx * sx + sy * sy);

gl_FragColor = dist > threshold ? vec4 (0,0,0,1) : vec4 (1,1,1,1);
}
]]>


Viewing 4 posts - 1 through 4 (of 4 total)