Carna  Version 3.3.2
mr-edgedetect.frag
1 #version 330
2 
3 /*
4  * Copyright (C) 2021 Leonid Kostrykin
5  *
6  */
7 
8 uniform sampler2D labelMap;
9 uniform vec4 color;
10 uniform vec2 steps;
11 
12 in vec2 textureCoordinates;
13 
14 out vec4 gl_FragColor;
15 
16 
17 // ----------------------------------------------------------------------------------
18 // Fragment Procedure
19 // ----------------------------------------------------------------------------------
20 
21 void main()
22 {
23  vec2 tc = textureCoordinates;
24 
25  float edgeScore
26  = abs( texture( labelMap, vec2( tc.x - steps.x, tc.y ) ).r - texture( labelMap, vec2( tc.x + steps.x, tc.y ) ).r )
27  + abs( texture( labelMap, vec2( tc.x, tc.y - steps.y ) ).r - texture( labelMap, vec2( tc.x, tc.y + steps.y ) ).r );
28 
29  if( edgeScore > 0 )
30  {
31  gl_FragColor = color;
32  }
33  else
34  {
35  discard;
36  }
37 }