Got a minute? We appreciate your feedback:

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

Texture as Mask

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 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)

David Maudlin
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 Maudlin / Architect
Digital Architecture
AC27 USA • iMac 27" 4.0GHz Quad-core i7 | 24 gb ram • MacBook Pro 2.8GHz | 16 gb ram • OSX11.7.10

Laszlo Nagy
Community Admin
Community Admin
I have split this question from that other thread and moved it to the Developer Forum.
Get Archicad Tips at
AMD Ryzen 1700X CPU, 48 GB RAM, Nvidia GTX 1060 6GB, 500 GB NVMe SSD
2x28" (2560x1440), WIN10 PRO ENG, AC20-AC26
Loving Archicad since 1995

Didn't find the answer?

Check other topics in this Forum

Back to Forum

Read the latest accepted solutions!

Accepted Solutions

Start a new conversation!