Archicad C++ API
About Archicad add-on development using the C++ API.

Texture as Mask

Anonymous
Not applicable
Not sure if this would be the correct placement of this thread, but seen the question asked before in here.

I am a designer of code128 barcode in vb.net.I have a texture intended as a mask. The texture type is GL_R32F (32 bit float) and the data inside is a signed distance field (= value of each texel is distance to nearest mask edge). For test purposes, the mask is just a circle part and is directly drawn in greyscale. The fragment shader handling this texture has following code:

void main() {
 float mask = texture( tex, fragTexCoord).r;
   vec4 res = vec4(1.0,1.0,1.0, 1.0);

   if(mask > 0.0) //test failed, outside of mask
      res = vec4(0.0,0.0,0.0, 0.0);
   //smoothing if there is an edge nearby 
   //0 or 1 otherwise
   res.w = smoothstep(0.0, 1.0, -1.0 * mask); 
   finalColor = res;
}
However if the mask is drawn too big, its edges appear blurry, because smoothstep afflicts too many fragments. This could be solved by multiplying the mask by some value, however it would stop smoothing if is the mask was drawn too small.

For illustration, on left is the mask(100px), in the middle is its zoomed edge and on right there is zoomed edge of mask if drawn big(600px). How to smooth the edge to appear correct regardless of the size? (=zoomed edges should always look the same, like the middle image)

1.png
2 REPLIES 2
David Maudlin
Rockstar
bobbell wrote:
Not sure if this would be the correct placement of this thread, but seen the question asked before in here.
I think this belongs in the Developer Forum.

David
David Maudlin / Architect
www.davidmaudlin.com
Digital Architecture
AC27 USA • iMac 27" 4.0GHz Quad-core i7 OSX11 | 24 gb ram • MacBook Pro M3 Pro | 36 gb ram OSX14
Laszlo Nagy
Community Admin
Community Admin
I have split this question from that other thread and moved it to the Developer Forum.
Loving Archicad since 1995 - Find Archicad Tips at x.com/laszlonagy
AMD Ryzen9 5900X CPU, 64 GB RAM 3600 MHz, Nvidia GTX 1060 6GB, 500 GB NVMe SSD
2x28" (2560x1440), Windows 10 PRO ENG, Ac20-Ac28