stencil.vert raw

   1  #version 310 es
   2  
   3  // SPDX-License-Identifier: Unlicense OR MIT
   4  
   5  precision highp float;
   6  
   7  layout(binding = 0) uniform Block {
   8  	vec4 transform;
   9  	vec2 pathOffset;
  10  } _block;
  11  
  12  layout(location=0) in float corner;
  13  layout(location=1) in float maxy;
  14  layout(location=2) in vec2 from;
  15  layout(location=3) in vec2 ctrl;
  16  layout(location=4) in vec2 to;
  17  
  18  layout(location=0) out vec2 vFrom;
  19  layout(location=1) out vec2 vCtrl;
  20  layout(location=2) out vec2 vTo;
  21  
  22  void main() {
  23  	// Add a one pixel overlap so curve quads cover their
  24  	// entire curves. Could use conservative rasterization
  25  	// if available.
  26  	vec2 from = from + _block.pathOffset;
  27  	vec2 ctrl = ctrl + _block.pathOffset;
  28  	vec2 to = to + _block.pathOffset;
  29  	float maxy = maxy + _block.pathOffset.y;
  30  	vec2 pos;
  31  	float c = corner;
  32  	if (c >= 0.375) {
  33  		// North.
  34  		c -= 0.5;
  35  		pos.y = maxy + 1.0;
  36  	} else {
  37  		// South.
  38  		pos.y = min(min(from.y, ctrl.y), to.y) - 1.0;
  39  	}
  40  	if (c >= 0.125) {
  41  		// East.
  42  		pos.x = max(max(from.x, ctrl.x), to.x)+1.0;
  43  	} else {
  44  		// West.
  45  		pos.x = min(min(from.x, ctrl.x), to.x)-1.0;
  46  	}
  47  	vFrom = from-pos;
  48  	vCtrl = ctrl-pos;
  49  	vTo = to-pos;
  50  	pos = pos*_block.transform.xy + _block.transform.zw;
  51  	gl_Position = vec4(pos, 1, 1);
  52  }
  53  
  54