Implement color for quadratic bezier curves
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
#version 430 core
|
#version 430 core
|
||||||
in vec4 gColor;
|
in vec4 gColor;
|
||||||
in vec3 gBoundingBox;
|
in vec3 gBoundingBox;
|
||||||
|
in float gRadStart;
|
||||||
|
in float gRadEnd;
|
||||||
|
|
||||||
out vec4 fColor;
|
out vec4 fColor;
|
||||||
|
|
||||||
@@ -8,7 +10,8 @@ float x = gBoundingBox.x;
|
|||||||
float y = gBoundingBox.y;
|
float y = gBoundingBox.y;
|
||||||
float z = gBoundingBox.z;
|
float z = gBoundingBox.z;
|
||||||
|
|
||||||
float w = 0.1;
|
float w = gRadEnd;
|
||||||
|
float w2 = gRadStart;
|
||||||
|
|
||||||
float f (float a, float b)
|
float f (float a, float b)
|
||||||
{
|
{
|
||||||
@@ -17,10 +20,9 @@ float f (float a, float b)
|
|||||||
}
|
}
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
|
|
||||||
//float d = x - y - 1 + 2* sqrt(y);
|
//float d = x - y - 1 + 2* sqrt(y);
|
||||||
float d = sqrt(x) + sqrt(y) - 1;
|
float d = sqrt(x) + sqrt(y) - 1;
|
||||||
float e = sqrt(f(x,w)) + sqrt(f(y,w)) - 1;
|
float e = sqrt(f(x,w)) + sqrt(f(y,w2)) - 1.0;
|
||||||
if ( d < 0 || e > 0) { discard; }
|
if ( d < 0 || e > 0) { discard; }
|
||||||
fColor = gColor;
|
fColor = gColor;
|
||||||
// if ( d < 0) { fColor = vec4 (0,1,0,1); }
|
// if ( d < 0) { fColor = vec4 (0,1,0,1); }
|
||||||
|
|||||||
@@ -2,7 +2,10 @@
|
|||||||
layout (triangles) in;
|
layout (triangles) in;
|
||||||
layout (triangle_strip, max_vertices = 3) out;
|
layout (triangle_strip, max_vertices = 3) out;
|
||||||
in vec4 vColor[];
|
in vec4 vColor[];
|
||||||
|
in float vRad[];
|
||||||
out vec4 gColor;
|
out vec4 gColor;
|
||||||
|
out float gRadStart;
|
||||||
|
out float gRadEnd;
|
||||||
out vec3 gBoundingBox;
|
out vec3 gBoundingBox;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
@@ -11,6 +14,8 @@ void main()
|
|||||||
vec3 pb = gl_in[1].gl_Position.xyz;
|
vec3 pb = gl_in[1].gl_Position.xyz;
|
||||||
vec3 pc = gl_in[2].gl_Position.xyz;
|
vec3 pc = gl_in[2].gl_Position.xyz;
|
||||||
|
|
||||||
|
gRadStart = vRad[0];
|
||||||
|
gRadEnd = vRad[2];
|
||||||
// vec3 pa = vec3(paa.xy + 0.1 * (paa.xy - pca.xy), paa.z);
|
// vec3 pa = vec3(paa.xy + 0.1 * (paa.xy - pca.xy), paa.z);
|
||||||
// vec3 pc = vec3(pca.xy + 0.1 * (pca.xy - paa.xy), pca.z);
|
// vec3 pc = vec3(pca.xy + 0.1 * (pca.xy - paa.xy), pca.z);
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
#version 430 core
|
#version 430 core
|
||||||
layout (location = 0) in vec3 position;
|
layout (location = 0) in vec3 position;
|
||||||
layout (location = 1) in vec4 color;
|
layout (location = 1) in vec4 color;
|
||||||
|
layout (location = 2) in float rad;
|
||||||
out vec4 vColor;
|
out vec4 vColor;
|
||||||
|
out float vRad;
|
||||||
|
|
||||||
uniform vec2 winSize;
|
uniform vec2 winSize;
|
||||||
uniform float zoom;
|
uniform float zoom;
|
||||||
@@ -13,4 +15,5 @@ void main()
|
|||||||
{
|
{
|
||||||
gl_Position = worldMat * vec4(position.xyz,1);
|
gl_Position = worldMat * vec4(position.xyz,1);
|
||||||
vColor = color;
|
vColor = color;
|
||||||
|
vRad = rad;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ worldPictures w
|
|||||||
where tst x y sc t = translate x y $ scale sc sc $ color white $ text t
|
where tst x y sc t = translate x y $ scale sc sc $ color white $ text t
|
||||||
|
|
||||||
testPic :: World -> [Picture]
|
testPic :: World -> [Picture]
|
||||||
testPic w = [setLayer 1 $ onLayerL [99] $ color red $ bezierQuad (-200,200) (-200,-200) (200,200) ]
|
testPic w = [setLayer 1 $ onLayerL [99] $ bezierQuad white red 5 50 (-200,200) (-200,-200) (00,00) ]
|
||||||
-- $ uncurry translate (mouseWorldPos w)
|
-- $ uncurry translate (mouseWorldPos w)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+14
-2
@@ -69,8 +69,20 @@ polygonCol :: [(Point2,RGBA)] -> Picture
|
|||||||
{-# INLINE polygonCol #-}
|
{-# INLINE polygonCol #-}
|
||||||
polygonCol = PolygonCol 0
|
polygonCol = PolygonCol 0
|
||||||
|
|
||||||
bezierQuad :: Point2 -> Point2 -> Point2 -> Picture
|
-- note that much of work computing the width of the bezier curve is done here
|
||||||
bezierQuad a b c = BezierQuad 0 [a,b,c]
|
-- not sure that moving the control point does much...
|
||||||
|
bezierQuad :: Color -> Color -> Float -> Float -> Point2 -> Point2 -> Point2 -> Picture
|
||||||
|
bezierQuad cola colc ra rc a b c = BezierQuad 0 [(aX,cola ,raX)
|
||||||
|
,(bx,mixColors 0.5 0.5 cola colc,1)
|
||||||
|
,(cX,colc ,rcX)]
|
||||||
|
where v = a -.- c
|
||||||
|
nv = normalizeV v
|
||||||
|
aX = a +.+ ra * 0.5 *.* nv
|
||||||
|
cX = c -.- rc * 0.5 *.* nv
|
||||||
|
raX = ra / magV (aX -.- cX)
|
||||||
|
rcX = rc / magV (aX -.- cX)
|
||||||
|
bx = b +.+ (0.5 * ra *.* normalizeV (b -.- a))
|
||||||
|
+.+ (0.5 * rc *.* normalizeV (b -.- c))
|
||||||
|
|
||||||
color :: RGBA -> Picture -> Picture
|
color :: RGBA -> Picture -> Picture
|
||||||
{-# INLINE color #-}
|
{-# INLINE color #-}
|
||||||
|
|||||||
+2
-2
@@ -22,7 +22,7 @@ import Data.Traversable
|
|||||||
|
|
||||||
data RenderType
|
data RenderType
|
||||||
= RenderPoly [(Point3,Point4)]
|
= RenderPoly [(Point3,Point4)]
|
||||||
| RenderBezQ [(Point3,Point4)]
|
| RenderBezQ [(Point3,Point4,Float)]
|
||||||
| RenderText [(Point3,Point4,Point3)]
|
| RenderText [(Point3,Point4,Point3)]
|
||||||
| RenderArc (Point3,Point4,Point4)
|
| RenderArc (Point3,Point4,Point4)
|
||||||
| RenderLine [(Point3,Point4)]
|
| RenderLine [(Point3,Point4)]
|
||||||
@@ -75,7 +75,7 @@ data Picture
|
|||||||
= Blank
|
= Blank
|
||||||
| Text Int String
|
| Text Int String
|
||||||
| Polygon Int [Point2]
|
| Polygon Int [Point2]
|
||||||
| BezierQuad Int [Point2]
|
| BezierQuad Int [(Point2,RGBA,Float)]
|
||||||
| PolygonCol Int [(Point2,RGBA)]
|
| PolygonCol Int [(Point2,RGBA)]
|
||||||
| Circle Int RGBA RGBA Float
|
| Circle Int RGBA RGBA Float
|
||||||
| ThickArc Int Float Float Float Float
|
| ThickArc Int Float Float Float Float
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ preloadRender = do
|
|||||||
"data/texture/charMap.png"
|
"data/texture/charMap.png"
|
||||||
|
|
||||||
bezierQuadShader
|
bezierQuadShader
|
||||||
<- makeShader "bezierQuad" [vert,geom,frag] [(0,3),(1,4)] Triangles pokeBezQStrat
|
<- makeShader "bezierQuad" [vert,geom,frag] [(0,3),(1,4),(2,1)] Triangles pokeBezQStrat
|
||||||
|
|
||||||
--the following vbo is set up to contain one fixed vertex
|
--the following vbo is set up to contain one fixed vertex
|
||||||
dummyvbo <- genObjectName
|
dummyvbo <- genObjectName
|
||||||
@@ -84,7 +84,7 @@ cleanUpRenderPreload pd = do
|
|||||||
|
|
||||||
{-# INLINE pokeBezQStrat #-}
|
{-# INLINE pokeBezQStrat #-}
|
||||||
pokeBezQStrat :: RenderType -> [[[Float]]]
|
pokeBezQStrat :: RenderType -> [[[Float]]]
|
||||||
pokeBezQStrat (RenderBezQ vs) = fmap (\((x,y,z),(r,g,b,a)) -> [[x,y,z],[r,g,b,a]]) vs
|
pokeBezQStrat (RenderBezQ vs) = fmap (\((x,y,z),(r,g,b,a),s) -> [[x,y,z],[r,g,b,a],[s]]) vs
|
||||||
pokeBezQStrat _ = []
|
pokeBezQStrat _ = []
|
||||||
|
|
||||||
{-# INLINE pokeTriStrat #-}
|
{-# INLINE pokeTriStrat #-}
|
||||||
|
|||||||
+6
-4
@@ -17,8 +17,10 @@ picToLTree mx (Polygon i ps)
|
|||||||
picToLTree mx (PolygonCol i vs)
|
picToLTree mx (PolygonCol i vs)
|
||||||
= filtB mx i $ LLeaf $ RenderPoly $ zip (map zeroZ $ polyToTris ps) $ polyToTris cs
|
= filtB mx i $ LLeaf $ RenderPoly $ zip (map zeroZ $ polyToTris ps) $ polyToTris cs
|
||||||
where (ps,cs) = unzip vs
|
where (ps,cs) = unzip vs
|
||||||
picToLTree mx (BezierQuad i ps)
|
picToLTree mx (BezierQuad i vs)
|
||||||
= filtB mx i $ LLeaf $ RenderBezQ $ zip (map zeroZ $ ps) $ repeat black
|
= filtB mx i $ LLeaf $ RenderBezQ $ zip3 (map zeroZ ps) cols rs
|
||||||
|
where (ps,cols,rs) = unzip3 vs
|
||||||
|
|
||||||
picToLTree mx (Circle i colC colE r)
|
picToLTree mx (Circle i colC colE r)
|
||||||
= filtB mx i $ LLeaf $ RenderEllipse [( (-r, r,0), colC)
|
= filtB mx i $ LLeaf $ RenderEllipse [( (-r, r,0), colC)
|
||||||
,( (-r,-r,0), colE)
|
,( (-r,-r,0), colE)
|
||||||
@@ -68,9 +70,9 @@ scaleT (x,y) (a,b,(o,s,t)) = (a,b,(o,s*x,t*y))
|
|||||||
overPos :: (Point3 -> Point3) -> RenderType -> RenderType
|
overPos :: (Point3 -> Point3) -> RenderType -> RenderType
|
||||||
{-# INLINE overPos #-}
|
{-# INLINE overPos #-}
|
||||||
overPos f (RenderPoly vs) = RenderPoly $ map (first $ f) vs
|
overPos f (RenderPoly vs) = RenderPoly $ map (first $ f) vs
|
||||||
overPos f (RenderBezQ vs) = RenderBezQ $ map (first $ f) vs
|
|
||||||
overPos f (RenderLine vs) = RenderLine $ map (first $ f) vs
|
overPos f (RenderLine vs) = RenderLine $ map (first $ f) vs
|
||||||
overPos f (RenderText vs) = RenderText $ map (\(a,b,c) -> (f a,b,c)) vs
|
overPos f (RenderText vs) = RenderText $ map (\(a,b,c) -> (f a,b,c)) vs
|
||||||
|
overPos f (RenderBezQ vs) = RenderBezQ $ map (\(a,b,c) -> (f a,b,c)) vs
|
||||||
overPos f (RenderEllipse vs) = RenderEllipse $ map (first f) vs
|
overPos f (RenderEllipse vs) = RenderEllipse $ map (first f) vs
|
||||||
overPos f (RenderArc (a,b,c)) = RenderArc (f a,b,c)
|
overPos f (RenderArc (a,b,c)) = RenderArc (f a,b,c)
|
||||||
|
|
||||||
@@ -82,10 +84,10 @@ overRot _ ren = ren
|
|||||||
overCol :: (Point4 -> Point4) -> RenderType -> RenderType
|
overCol :: (Point4 -> Point4) -> RenderType -> RenderType
|
||||||
{-# INLINE overCol #-}
|
{-# INLINE overCol #-}
|
||||||
overCol f (RenderPoly vs) = RenderPoly $ map (second $ f) vs
|
overCol f (RenderPoly vs) = RenderPoly $ map (second $ f) vs
|
||||||
overCol f (RenderBezQ vs) = RenderBezQ $ map (second $ f) vs
|
|
||||||
overCol f (RenderLine vs) = RenderLine $ map (second $ f) vs
|
overCol f (RenderLine vs) = RenderLine $ map (second $ f) vs
|
||||||
overCol f (RenderEllipse vs) = RenderEllipse $ map (second $ f) vs
|
overCol f (RenderEllipse vs) = RenderEllipse $ map (second $ f) vs
|
||||||
overCol f (RenderText vs) = RenderText $ map (\(a,b,c) -> (a,f b,c)) vs
|
overCol f (RenderText vs) = RenderText $ map (\(a,b,c) -> (a,f b,c)) vs
|
||||||
|
overCol f (RenderBezQ vs) = RenderBezQ $ map (\(a,b,c) -> (a,f b,c)) vs
|
||||||
overCol f (RenderArc (a,b,c)) = RenderArc (a,f b,c)
|
overCol f (RenderArc (a,b,c)) = RenderArc (a,f b,c)
|
||||||
|
|
||||||
overSca :: (Point2 -> Point2) -> RenderType -> RenderType
|
overSca :: (Point2 -> Point2) -> RenderType -> RenderType
|
||||||
|
|||||||
Reference in New Issue
Block a user