From 3aefb8319d810280a13337f66310aba29cece301 Mon Sep 17 00:00:00 2001 From: jgk Date: Sat, 13 Mar 2021 23:14:37 +0100 Subject: [PATCH] Continue changes to quadratic bezier rendering --- shader/bezierQuad.frag | 8 +++++++- shader/bezierQuad.geom | 26 ++++++++++++++++++++++++++ src/Dodge/Rendering.hs | 2 +- src/Picture.hs | 4 ++-- 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/shader/bezierQuad.frag b/shader/bezierQuad.frag index d2d2c3146..7743adead 100644 --- a/shader/bezierQuad.frag +++ b/shader/bezierQuad.frag @@ -1,8 +1,12 @@ #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) out vec4 fColor; @@ -19,8 +23,10 @@ void main() { //float d = x - y - 1 + 2* sqrt(y); float d = sqrt(x) + sqrt(y) - 1; - float e = sqrt(f(x,wStart)) + sqrt(f(y,wEnd)) - 1.0; +// float e = sqrt(f(x,wStart)) + sqrt(f(y,wEnd)) - 1.0; + float e = sqrt(box2.x) + sqrt(box2.y) - 1.0; // if ( d < 0 || e > 0) { discard; } fColor = gColor; +// if ( d < 0 || e > 0) { fColor = vec4(0,0,1,1); } if ( d < 0 || e > 0) { fColor = vec4(0,0,1,1); } } diff --git a/shader/bezierQuad.geom b/shader/bezierQuad.geom index 659ed7a5f..49b526cf3 100644 --- a/shader/bezierQuad.geom +++ b/shader/bezierQuad.geom @@ -9,6 +9,8 @@ out float wStart; out float wEnd; out vec3 gBoundingBox; +out vec2 box2 ; + vec2 normV2 (vec2 v) { return vec2(-v.y,v.x) ; } @@ -16,6 +18,19 @@ float lhs (vec2 da, vec2 db) { return sign(dot(da, normV2(db))) ; } +float extrapolate (vec2 inOne, vec2 inZeroA, vec2 inZeroB, vec2 xy) +{ + float det = inOne.x * (inZeroA.y - inZeroB.y) + + inZeroA.x * (inZeroB.y - inOne.y) + + inZeroB.x * (inOne.y - inZeroA.y) + ; + float r = (inZeroA.y - inZeroB.y) ; + float s = (inZeroB.x - inZeroA.x) ; + float t = (inZeroA.x * inZeroB.y - inZeroB.x * inZeroA.y) ; + return r * xy.x + s * xy.y + t + / det ; +} + void main() { vec3 pa = gl_in[0].gl_Position.xyz; @@ -25,22 +40,33 @@ void main() wStart = vRadMag [0]; wEnd = vRadMag [2]; + box2 = vec2 (1,0); gBoundingBox = vec3 (0.9,0.1,0); gColor = vColor[0]; gl_Position = vec4 (vPosOff[0] , pa.z , 1); EmitVertex(); + box2 = vec2 (0,1); gBoundingBox = vec3 (0.1,0.9,0); gColor = vColor[2]; gl_Position = vec4 (vPosOff[2] , pc.z , 1); EmitVertex(); + box2 = vec2( extrapolate(vPosOff[0],vPosOff[2],pb.xy,pa.xy) + , extrapolate(vPosOff[2],vPosOff[0],pb.xy,pa.xy) + ) ; + box2 = vec2(0.2,0); gBoundingBox = vec3 (1,0,1); gColor = vColor[0]; gl_Position = vec4 (pa, 1); EmitVertex(); + box2 = vec2( extrapolate(vPosOff[0],vPosOff[2],pb.xy,pc.xy) + , extrapolate(vPosOff[2],vPosOff[0],pb.xy,pc.xy) + ) ; + box2 = vec2(0,0.2); gBoundingBox = vec3 (0,1,1); gColor = vColor[2]; gl_Position = vec4 (pc, 1); EmitVertex(); + box2 = vec2( 0,0 ) ; gBoundingBox = vec3 (0,0,0); gColor = vColor[1]; gl_Position = vec4 (pb, 1); diff --git a/src/Dodge/Rendering.hs b/src/Dodge/Rendering.hs index eb94d2303..4c63e269e 100644 --- a/src/Dodge/Rendering.hs +++ b/src/Dodge/Rendering.hs @@ -122,7 +122,7 @@ worldPictures w testPic :: World -> [Picture] testPic w = --[blank] - [setLayer 1 $ onLayerL [99] $ bezierQuad white red 20 20 (00,00) (200,200) (200,000) ] + [setLayer 1 $ onLayerL [99] $ bezierQuad white red 20 20 (00,00) (150,90) (200,200) ] -- $ uncurry translate (mouseWorldPos w) diff --git a/src/Picture.hs b/src/Picture.hs index 985f685ec..fcd72cd9f 100644 --- a/src/Picture.hs +++ b/src/Picture.hs @@ -84,8 +84,8 @@ bezierQuad cola colc ra rc a b c = BezierQuad 0 [(aX, cola, aX +.+ aRadVec , fra | otherwise = c -.- b cRadVec = rc *.* (normalizeV $ vNormal b2c) cX = c -.- 0.5 *.* cRadVec - bX = (b -.- (0.5 * ra *.* aRadVec) ) - -.- (0.5 * rc *.* cRadVec) + bX = (b -.- (0.5 *.* aRadVec) ) + -.- (0.5 *.* cRadVec) fracRadA = ra / magV (aX -.- cX) fracRadC = rc / magV (aX -.- cX)