Improve ellipses

This commit is contained in:
jgk
2021-03-10 03:59:38 +01:00
parent cddf7d1f8f
commit cc86a701db
7 changed files with 39 additions and 60 deletions
+2 -14
View File
@@ -1,25 +1,13 @@
#version 430 core
in vec4 gColor;
in vec2 gFocusA;
in vec2 gFocusB;
in float gRad;
in vec2 gBoundingBox;
out vec4 fColor;
//out float gl_FragDepth;
void main()
{
vec2 pos = gl_FragCoord.xy;
// fColor = vec4( gColor.xyz , 0 );
// fColor = vec4( gColor.xyz , 1 - step(distance(pos,cenPos.xy),gRad) );
// fColor = vec4( gColor.xyz , distance(pos,cenPos.xy)/gRad );
// fColor = vec4( gColor.rgb, gColor.a * (1-step(gRad/2,distance(pos,cenPosT))) );
gl_FragDepth = max( gl_FragCoord.z
, step(gRad/2
, distance(pos,gFocusA) + distance(gFocusA,gFocusB)
//+ distance(pos,gFocusB)
)
);
if ( dot(gBoundingBox,gBoundingBox) > 1) { discard; }
fColor = gColor;
// fColor = vec4 (1,1,1,1);
}
+15 -26
View File
@@ -1,44 +1,33 @@
#version 430 core
layout (lines) in;
layout (triangles) in;
layout (triangle_strip, max_vertices = 4) out;
in vec4 vCol[];
in float vRad[];
out vec4 gColor;
out float gRad;
out vec2 gFocusA;
out vec2 gFocusB;
out vec2 gBoundingBox;
uniform vec2 winSize;
uniform float zoom;
void main()
{
vec3 focusA = gl_in[0].gl_Position.xyz;
vec3 focusB = gl_in[1].gl_Position.xyz;
vec3 pa = gl_in[0].gl_Position.xyz;
vec3 pb = gl_in[1].gl_Position.xyz;
vec3 pc = gl_in[2].gl_Position.xyz;
gColor = vCol[0];
gRad = vRad[0] * zoom * 2 ;
gFocusA = vec2 ( (focusA.x + 1) * 0.5 * winSize.x , (focusA.y + 1) * 0.5 * winSize.y);
// focusA = vec3 ( 0 , 0, focusA.z);
gFocusB = vec2 ( (focusB.x + 1) * 0.5 * winSize.x , (focusB.y + 1) * 0.5 * winSize.y);
float am = 0.5;
gl_Position = vec4 (focusA.x + gRad/winSize.x, focusA.y + gRad/winSize.y, focusA.z , 1);
// gl_Position = vec4 (focusA.x + am, focusA.y + am, -1 , 1);
// gl_Position = vec4 (focusA , 1);
gBoundingBox = vec2 (-1,1);
gl_Position = vec4 (pb, 1);
//gl_Position = vec4 (0.5,0,0, 1);
EmitVertex();
gl_Position = vec4 (focusA.x - gRad/winSize.x, focusA.y + gRad/winSize.y, focusA.z , 1);
// gl_Position = vec4 (focusA.x - am, focusA.y + am, -1 , 1);
// gl_Position = vec4 (0 ,0.5 ,-1 , 1);
// gl_Position = vec4 (0 + gRad ,0 ,-1 , 1);
gBoundingBox = vec2 (1,1);
gl_Position = vec4 (pa, 1);
EmitVertex();
gl_Position = vec4 (focusA.x + gRad/winSize.x, focusA.y - gRad/winSize.y, focusA.z , 1);
// gl_Position = vec4 (focusA.x + am, focusA.y - am, -1 , 1);
// gl_Position = vec4 (0.5 ,0.5 ,-1 , 1);
gBoundingBox = vec2 (-1,-1);
gl_Position = vec4 (pc, 1);
// gl_Position = vec4 (0.5,0.5,0, 1);
EmitVertex();
gl_Position = vec4 (focusA.x - gRad/winSize.x, focusA.y - gRad/winSize.y, focusA.z , 1);
// gl_Position = vec4 (focusA.x - am, focusA.y - am, -1 , 1);
// gl_Position = vec4 (0.5 ,0 ,-1 , 1);
gBoundingBox = vec2 (1,-1);
gl_Position = vec4 (pa + pc - pb, 1);
EmitVertex();
EndPrimitive();
-3
View File
@@ -1,9 +1,7 @@
#version 430 core
layout (location = 0) in vec3 position;
layout (location = 1) in vec4 col;
layout (location = 2) in float rad;
out vec4 vCol;
out float vRad;
uniform vec2 winSize;
uniform float zoom;
@@ -14,6 +12,5 @@ uniform mat4 worldMat;
void main()
{
gl_Position = worldMat * vec4(position,1);
vRad = rad;
vCol = col;
}
+1 -1
View File
@@ -1035,7 +1035,7 @@ moveFlame rotd w pt =
-- $ circleSolid 5
-- $ pictures $ reverse [color white $ circleSolid 4
$ pictures $ reverse
[color red $ ellipseSolid (0,-2) (0,2) 6
[color red $ ellipseSolid (-2,0) (2,0) 6
--,color white $ ellipseSolid (2,0) (-2,0) 6
--,color white $ ellipseSolid (2,0) (-2,0) 6
,color (withAlpha 0.5 white) $ circleSolid 5
+1 -1
View File
@@ -61,7 +61,7 @@ data RenderType
| RenderCirc (Point3,Point4,Float)
| RenderArc (Point3,Point4,Point4)
| RenderLine [(Point3,Point4)]
| RenderEllipse [(Point3,Point4,Float)]
| RenderEllipse [(Point3,Point4)]
data Picture
= Blank
+1 -1
View File
@@ -152,7 +152,7 @@ preloadRender = do
linevao <- setupVAO [(0,3),(1,4)]
textvao <- setupVAO [(0,3),(1,4),(2,3)]
circvao <- setupVAO [(0,3),(1,4),(2,1)]
ellipsevao <- setupVAO [(0,3),(1,4),(2,1)]
ellipsevao <- setupVAO [(0,3),(1,4)]
arcvao <- setupVAO [(0,3),(1,4),(2,4)]
backgroundvao <- setupVAO [(0,4),(1,2)]
wallvao <- setupVAO [(0,4),(1,4)]
+19 -14
View File
@@ -63,7 +63,7 @@ overPos :: (Point3 -> Point3) -> RenderType -> RenderType
overPos f (RenderPoly vs) = RenderPoly $ 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 (RenderEllipse vs) = RenderEllipse $ map (\(a,b,c) -> (f a,b,c)) vs
overPos f (RenderEllipse vs) = RenderEllipse $ map (first f) vs
overPos f (RenderCirc (a,b,c)) = RenderCirc (f a,b,c)
overPos f (RenderArc (a,b,c)) = RenderArc (f a,b,c)
@@ -76,8 +76,8 @@ overCol :: (Point4 -> Point4) -> RenderType -> RenderType
{-# INLINE overCol #-}
overCol f (RenderPoly vs) = RenderPoly $ map (second $ f) vs
overCol f (RenderLine vs) = RenderLine $ 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 (RenderEllipse vs) = RenderEllipse $ map (\(a,b,c) -> (a,f b,c)) vs
overCol f (RenderCirc (a,b,c)) = RenderCirc (a,f b,c)
overCol f (RenderArc (a,b,c)) = RenderArc (a,f b,c)
@@ -131,8 +131,11 @@ picToAlt x (PolygonCol i vs)
picToAlt x (Circle i r)
| i == x = Ap.pure $ RenderCirc $ ((0,0,0),black,r)
| otherwise = Ap.empty
picToAlt x (Ellipse i pa pb r)
| i == x = Ap.pure $ RenderEllipse [(zeroZ pa,black,r),(zeroZ pb,black,r)]
picToAlt x (Ellipse i (ax,ay) (bx,by) r)
| i == x = Ap.pure $ RenderEllipse [((ax,ay+r,0),black)
,((ax,ay-r,0),black)
,((bx,by-r,0),black)
]
| otherwise = Ap.empty
picToAlt x (ThickArc i startA endA rad wdth)
| i == x = Ap.pure $ RenderArc $ ((0,0,0),black,(startA,endA,rad,wdth))
@@ -165,8 +168,11 @@ picToLTree mx (PolygonCol i vs)
picToLTree mx (Circle i r)
| Just i == mx || Nothing == mx = LLeaf $ RenderCirc $ ((0,0,0),black,r)
| otherwise = LBranches []
picToLTree mx (Ellipse i pa pb r)
| Just i == mx || Nothing == mx = LLeaf $ RenderEllipse [(zeroZ pa,black,r),(zeroZ pb,black,r)]
picToLTree mx (Ellipse i (ax,ay) (bx,by) r)
| Just i == mx || Nothing == mx = LLeaf $ RenderEllipse [((ax,ay+r,0),black)
,((ax,ay-r,0),black)
,((bx,by-r,0),black)
]
| otherwise = LBranches []
picToLTree mx (ThickArc i startA endA rad wdth)
| Just i == mx || Nothing == mx = LLeaf $ RenderArc $ ((0,0,0),black,(startA,endA,rad,wdth))
@@ -202,7 +208,7 @@ theFold :: TwoPtrs
-> ThreePtrs
-> TwoPtrs
-> ThreePtrs
-> ThreePtrs
-> TwoPtrs
-> F.FoldM IO RenderType (Int,Int,Int,Int,Int,Int)
theFold pas pbs pcs pds pes pfs
= (,,,,,) <$> pokeTwoPtrsWith pokePoly pas
@@ -210,7 +216,7 @@ theFold pas pbs pcs pds pes pfs
<*> pokeThreePtrsWith pokeCirc pcs
<*> pokeTwoPtrsWith pokeLine pds
<*> pokeThreePtrsWith pokeArc pes
<*> pokeThreePtrsWith pokeEllipse pfs
<*> pokeTwoPtrsWith pokeEllipse pfs
type ThreePtrs = (Ptr Float,Ptr Float,Ptr Float)
type TwoPtrs = (Ptr Float,Ptr Float)
@@ -235,19 +241,18 @@ pokeArc (pa,pb,pc) n (RenderArc (p,c,s))
return $ n + 1
pokeArc _ n _ = return n
pokeEllipse:: ThreePtrs -> Int -> RenderType -> IO Int
pokeEllipse:: TwoPtrs -> Int -> RenderType -> IO Int
{-# INLINE pokeEllipse #-}
pokeEllipse ptrs n (RenderEllipse vs) = foldM (pokeEllipseVert ptrs) n vs
pokeEllipse _ n _ = return n
pokeEllipseVert :: ThreePtrs -> Int -> (Point3,Point4,Float) -> IO Int
pokeEllipseVert :: TwoPtrs -> Int -> (Point3,Point4) -> IO Int
{-# INLINE pokeEllipseVert #-}
pokeEllipseVert (pa,pb,pc) n (p,c,s)
pokeEllipseVert (pa,pb) n (p,c)
| n > 20000 * 2 = return n
| otherwise = do
pokeThreeOff pa n p
pokeFourOff pb n c
pokeElemOff pc n s
return $ n + 1
pokeTwoOff :: Ptr Float -> Int -> (Float,Float) -> IO ()
@@ -498,7 +503,7 @@ renderTree pdata rot zoom (tranx,trany) (winx,winy) tree = do
(threePtrsVAO $ _circVAO pdata)
(twoPtrsVAO $ _lineVAO pdata)
(threePtrsVAO $ _arcVAO pdata)
(threePtrsVAO $ _ellipseVAO pdata)
(twoPtrsVAO $ _ellipseVAO pdata)
) $ tree
pokeEndTicks <-SDL.ticks
@@ -538,7 +543,7 @@ renderTree pdata rot zoom (tranx,trany) (winx,winy) tree = do
-- draw ellipses
currentProgram $= Just (fst $ _ellipseShader pdata)
bindVertexArrayObject $= Just (_vao $ _ellipseVAO pdata)
drawArrays Lines 0 (fromIntegral $ nEllVs)
drawArrays Triangles 0 (fromIntegral $ nEllVs)
-- draw arcs
currentProgram $= Just (fst $ _arcShader pdata)
bindVertexArrayObject $= Just (_vao $ _arcVAO pdata)