|
Texture Mapping & Edge Detection
Image with Edge Detection and Aliased (Zoom)
The popping is very noticeable here, especially in the finer details
of the image.
Code
/* simple shader for use in finding the edge for a texture map */
surface
edge_mapper( float Kd = 1,
s_offset = .005,
t_offset = .005,
sensitivity = .1,
blur =.02,
mixValue = .3,
mixValue2 = .3,
sampleRate = 1,
lightness = 1;
string texname = "") /*texture to apply to object*/
{
color edgeDetect = color(1, 1, 1);
color surfcolor = color(1, 1, 1);
float total = 0;
float c1, c2, i, j, diff;
/* Use the texture function if user specifies a texture file*/
if(texname != "") {
color textureMap = texture(texname,s,t) * lightness;
c1 = float texture(texname, s, t);
/* Grab a surrounding sampling of pixels */
for(i = -sampleRate; i <= sampleRate; i = i + 1)
{
for(j = -sampleRate; j <= sampleRate; j = j + 1)
{
c2 = float texture(texname, s + (i*s_offset), t + (j*t_offset));
diff = abs(c1-c2);
total += diff;
}
}
/*surfcolor = smoothstep(-blur, blur, 1 - sqrt(total) - sensitivity);*/
edgeDetect = 1 - smoothstep(-blur, blur, 1 - sqrt(total) - sensitivity);
/* Mix the edge with the original image*/
surfcolor = mix(edgeDetect,textureMap,mixValue);
}
normal n = normalize(N);
normal nf = faceforward(n, I);
/* */
Oi = Os;
color diffusecolor = Kd * diffuse(nf);
Ci = Oi * Cs * surfcolor * diffusecolor;
}
|