Render bezier curves using distance fields

This commit is contained in:
jgk
2021-03-14 00:13:29 +01:00
parent 3aefb8319d
commit b0c8c10658
6 changed files with 51 additions and 37 deletions
+6 -20
View File
@@ -1,32 +1,18 @@
#version 430 core
in vec4 gColor;
in vec3 gBoundingBox;
in vec2 box2;
in float wStart;
in float wEnd;
// the width is calculated along the line a-c
// this should instead be along the lines a-b (for start width)
// and b-c (for end width)
in vec4 vColor;
in vec2 boxOut;
in vec2 boxIn;
out vec4 fColor;
float x = gBoundingBox.x;
float y = gBoundingBox.y;
float z = gBoundingBox.z;
float f (float a, float b)
{
float c = 1 / (1 - 2*b) ;
return c * (a - 0.5) + 0.5 ;
}
void main()
{
//float d = x - y - 1 + 2* sqrt(y);
float d = sqrt(x) + sqrt(y) - 1;
float d = sqrt(boxOut.x) + sqrt(boxOut.y) - 1;
// float e = sqrt(f(x,wStart)) + sqrt(f(y,wEnd)) - 1.0;
float e = sqrt(box2.x) + sqrt(box2.y) - 1.0;
float e = sqrt(boxIn.x) + sqrt(boxIn.y) - 1.0;
// if ( d < 0 || e > 0) { discard; }
fColor = gColor;
fColor = vColor;
// if ( d < 0 || e > 0) { fColor = vec4(0,0,1,1); }
if ( d < 0 || e > 0) { fColor = vec4(0,0,1,1); }
}
+5 -5
View File
@@ -1,10 +1,10 @@
#version 430 core
layout (location = 0) in vec3 position;
layout (location = 1) in vec4 color;
layout (location = 2) in vec3 radVec;
layout (location = 2) in vec4 boxes;
out vec4 vColor;
out vec2 vPosOff;
out float vRadMag;
out vec2 boxOut;
out vec2 boxIn;
uniform vec2 winSize;
uniform float zoom;
@@ -16,6 +16,6 @@ void main()
{
gl_Position = worldMat * vec4(position.xyz,1);
vColor = color;
vPosOff = ( worldMat * vec4(radVec.xy,0,1) ).xy ;
vRadMag = radVec.z ;
boxOut = boxes.xy ;
boxIn = boxes.zw ;
}