discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

polyhedron rendering

J
jay
Thu, Dec 22, 2022 1:57 PM

I build everething with a tolerance of 0.01 where i add or subtract the tolarance accordingly when drawing diferances, but i never found a solution to the close to view problem.Its usfull to no it only does it in perspective view though, i never noticed that before.Sent via the Samsung Galaxy S7, an AT&T 4G LTE smartphone
-------- Original message --------From: Rogier Wolff R.E.Wolff@BitWizard.nl Date: 12/22/22  1:22 PM  (GMT+00:00) To: OpenSCAD general discussion Mailing-list discuss@lists.openscad.org Subject: [OpenSCAD] Re: preview difference() glitch On Tue, Dec 20, 2022 at 04:42:26PM +0000, nop head wrote:> Yes, OpenCSG is used to draw the preview without calculating any of the> geometry. It just draws all the primitive objects with different graphics> modes.What it boils down to is that most people don't understand how say "acube" ends up on the screen. A quick computer graphics lesson:Let us work towards the situation where we put: difference () {cube (10);translate ([5,5,5]) cube (10);} on the screen. But first lets do the first cube only. In practice, these things often only work on triangles, Not sure ifnowadays that's still true, but for now lets pretend we can work withsquares too.The cube has 6 faces. For each face, we first compare the normal tothe viewing vector. If it is facing away from the camera(i.e. anglebetween them is less than 90 degrees), we can ignore it.This leaves us with just three faces we need to draw. We transform thecube's coorinates to screen coordinates and simply draw the pixelsinside the quadrilaterals with the proper color depending on the anglebetween the normal, viewing angle and the light source.Now if we want to draw a second cube (not a difference, like above,but a union), things get a bit fishy: Depending on the drawing orderyou get to see faces that should be obscured by the othercube. So... for each pixel, we calculate the distance from the viewingplane and store that together with the color of the pixel.Now while drawing a pixel instead of just drawing it, we compare thedepth value. If the current depth value is further away than what'salready drawn, we ignore this pixel of this face, otherwise we draw asnormal and update the depth value.Now you can pretty quickly get a reasonable preview for multipleobjects combined.But how to draw the difference?  For the "negative" cube in my examplecase we need to turn things around: We ignore faces pointing towardsus, and draw faces pointing away from us. Also the depth rule turnsaround: We only draw pixels that are DEEPER than the pixel alreadydrawn.Now this is going to be "messy" to implement. Corner cases everywhereand things like that, but this is the principle. All in all, this isthe X billion pixels per second that graphics cards claim to be ableto handle. So this also includes all the pixels that do NOT end up onyour screen.It also explains the Z-fighting that you sometimes see: Two planesin theory at precisely the same depth so it depends on floating pointrounding errors if one is in front of the other or not. Roger. -- ** R.E.Wolff@BitWizard.nl ** https://www.BitWizard.nl/ ** +31-15-2049110 ****    Delftechpark 11 2628 XJ  Delft, The Netherlands.  KVK: 27239233    **f equals m times a. When your f is steady, and your m is going downyour a is going up.  -- Chris Hadfield about flying up the space shuttle._______________________________________________OpenSCAD mailing listTo unsubscribe send an email to discuss-leave@lists.openscad.org

I build everething with a tolerance of 0.01 where i add or subtract the tolarance accordingly when drawing diferances, but i never found a solution to the close to view problem.Its usfull to no it only does it in perspective view though, i never noticed that before.Sent via the Samsung Galaxy S7, an AT&T 4G LTE smartphone -------- Original message --------From: Rogier Wolff <R.E.Wolff@BitWizard.nl> Date: 12/22/22 1:22 PM (GMT+00:00) To: OpenSCAD general discussion Mailing-list <discuss@lists.openscad.org> Subject: [OpenSCAD] Re: preview difference() glitch On Tue, Dec 20, 2022 at 04:42:26PM +0000, nop head wrote:> Yes, OpenCSG is used to draw the preview without calculating any of the> geometry. It just draws all the primitive objects with different graphics> modes.What it boils down to is that most people don't understand how say "acube" ends up on the screen. A quick computer graphics lesson:Let us work towards the situation where we put: difference () {cube (10);translate ([5,5,5]) cube (10);} on the screen. But first lets do the first cube only. In practice, these things often only work on triangles, Not sure ifnowadays that's still true, but for now lets pretend we can work withsquares too.The cube has 6 faces. For each face, we first compare the normal tothe viewing vector. If it is facing away from the camera(i.e. anglebetween them is less than 90 degrees), we can ignore it.This leaves us with just three faces we need to draw. We transform thecube's coorinates to screen coordinates and simply draw the pixelsinside the quadrilaterals with the proper color depending on the anglebetween the normal, viewing angle and the light source.Now if we want to draw a second cube (not a difference, like above,but a union), things get a bit fishy: Depending on the drawing orderyou get to see faces that should be obscured by the othercube. So... for each pixel, we calculate the distance from the viewingplane and store that together with the color of the pixel.Now while drawing a pixel instead of just drawing it, we compare thedepth value. If the current depth value is further away than what'salready drawn, we ignore this pixel of this face, otherwise we draw asnormal and update the depth value.Now you can pretty quickly get a reasonable preview for multipleobjects combined.But how to draw the difference?  For the "negative" cube in my examplecase we need to turn things around: We ignore faces pointing towardsus, and draw faces pointing away from us. Also the depth rule turnsaround: We only draw pixels that are DEEPER than the pixel alreadydrawn.Now this is going to be "messy" to implement. Corner cases everywhereand things like that, but this is the principle. All in all, this isthe X billion pixels per second that graphics cards claim to be ableto handle. So this also includes all the pixels that do NOT end up onyour screen.It also explains the Z-fighting that you sometimes see: Two planesin theory at precisely the same depth so it depends on floating pointrounding errors if one is in front of the other or not. Roger. -- ** R.E.Wolff@BitWizard.nl ** https://www.BitWizard.nl/ ** +31-15-2049110 ****    Delftechpark 11 2628 XJ  Delft, The Netherlands.  KVK: 27239233    **f equals m times a. When your f is steady, and your m is going downyour a is going up.  -- Chris Hadfield about flying up the space shuttle._______________________________________________OpenSCAD mailing listTo unsubscribe send an email to discuss-leave@lists.openscad.org
J
jay
Thu, Dec 22, 2022 2:01 PM

Would i be correct in saying that the Preview is rendered by the underlying graphics library on the GPU and the Render is renderd by openscad on the GPU?Sent via the Samsung Galaxy S7, an AT&T 4G LTE smartphone
-------- Original message --------From: Rogier Wolff R.E.Wolff@BitWizard.nl Date: 12/22/22  1:22 PM  (GMT+00:00) To: OpenSCAD general discussion Mailing-list discuss@lists.openscad.org Subject: [OpenSCAD] Re: preview difference() glitch On Tue, Dec 20, 2022 at 04:42:26PM +0000, nop head wrote:> Yes, OpenCSG is used to draw the preview without calculating any of the> geometry. It just draws all the primitive objects with different graphics> modes.What it boils down to is that most people don't understand how say "acube" ends up on the screen. A quick computer graphics lesson:Let us work towards the situation where we put: difference () {cube (10);translate ([5,5,5]) cube (10);} on the screen. But first lets do the first cube only. In practice, these things often only work on triangles, Not sure ifnowadays that's still true, but for now lets pretend we can work withsquares too.The cube has 6 faces. For each face, we first compare the normal tothe viewing vector. If it is facing away from the camera(i.e. anglebetween them is less than 90 degrees), we can ignore it.This leaves us with just three faces we need to draw. We transform thecube's coorinates to screen coordinates and simply draw the pixelsinside the quadrilaterals with the proper color depending on the anglebetween the normal, viewing angle and the light source.Now if we want to draw a second cube (not a difference, like above,but a union), things get a bit fishy: Depending on the drawing orderyou get to see faces that should be obscured by the othercube. So... for each pixel, we calculate the distance from the viewingplane and store that together with the color of the pixel.Now while drawing a pixel instead of just drawing it, we compare thedepth value. If the current depth value is further away than what'salready drawn, we ignore this pixel of this face, otherwise we draw asnormal and update the depth value.Now you can pretty quickly get a reasonable preview for multipleobjects combined.But how to draw the difference?  For the "negative" cube in my examplecase we need to turn things around: We ignore faces pointing towardsus, and draw faces pointing away from us. Also the depth rule turnsaround: We only draw pixels that are DEEPER than the pixel alreadydrawn.Now this is going to be "messy" to implement. Corner cases everywhereand things like that, but this is the principle. All in all, this isthe X billion pixels per second that graphics cards claim to be ableto handle. So this also includes all the pixels that do NOT end up onyour screen.It also explains the Z-fighting that you sometimes see: Two planesin theory at precisely the same depth so it depends on floating pointrounding errors if one is in front of the other or not. Roger. -- ** R.E.Wolff@BitWizard.nl ** https://www.BitWizard.nl/ ** +31-15-2049110 ****    Delftechpark 11 2628 XJ  Delft, The Netherlands.  KVK: 27239233    **f equals m times a. When your f is steady, and your m is going downyour a is going up.  -- Chris Hadfield about flying up the space shuttle._______________________________________________OpenSCAD mailing listTo unsubscribe send an email to discuss-leave@lists.openscad.org

Would i be correct in saying that the Preview is rendered by the underlying graphics library on the GPU and the Render is renderd by openscad on the GPU?Sent via the Samsung Galaxy S7, an AT&T 4G LTE smartphone -------- Original message --------From: Rogier Wolff <R.E.Wolff@BitWizard.nl> Date: 12/22/22 1:22 PM (GMT+00:00) To: OpenSCAD general discussion Mailing-list <discuss@lists.openscad.org> Subject: [OpenSCAD] Re: preview difference() glitch On Tue, Dec 20, 2022 at 04:42:26PM +0000, nop head wrote:> Yes, OpenCSG is used to draw the preview without calculating any of the> geometry. It just draws all the primitive objects with different graphics> modes.What it boils down to is that most people don't understand how say "acube" ends up on the screen. A quick computer graphics lesson:Let us work towards the situation where we put: difference () {cube (10);translate ([5,5,5]) cube (10);} on the screen. But first lets do the first cube only. In practice, these things often only work on triangles, Not sure ifnowadays that's still true, but for now lets pretend we can work withsquares too.The cube has 6 faces. For each face, we first compare the normal tothe viewing vector. If it is facing away from the camera(i.e. anglebetween them is less than 90 degrees), we can ignore it.This leaves us with just three faces we need to draw. We transform thecube's coorinates to screen coordinates and simply draw the pixelsinside the quadrilaterals with the proper color depending on the anglebetween the normal, viewing angle and the light source.Now if we want to draw a second cube (not a difference, like above,but a union), things get a bit fishy: Depending on the drawing orderyou get to see faces that should be obscured by the othercube. So... for each pixel, we calculate the distance from the viewingplane and store that together with the color of the pixel.Now while drawing a pixel instead of just drawing it, we compare thedepth value. If the current depth value is further away than what'salready drawn, we ignore this pixel of this face, otherwise we draw asnormal and update the depth value.Now you can pretty quickly get a reasonable preview for multipleobjects combined.But how to draw the difference?  For the "negative" cube in my examplecase we need to turn things around: We ignore faces pointing towardsus, and draw faces pointing away from us. Also the depth rule turnsaround: We only draw pixels that are DEEPER than the pixel alreadydrawn.Now this is going to be "messy" to implement. Corner cases everywhereand things like that, but this is the principle. All in all, this isthe X billion pixels per second that graphics cards claim to be ableto handle. So this also includes all the pixels that do NOT end up onyour screen.It also explains the Z-fighting that you sometimes see: Two planesin theory at precisely the same depth so it depends on floating pointrounding errors if one is in front of the other or not. Roger. -- ** R.E.Wolff@BitWizard.nl ** https://www.BitWizard.nl/ ** +31-15-2049110 ****    Delftechpark 11 2628 XJ  Delft, The Netherlands.  KVK: 27239233    **f equals m times a. When your f is steady, and your m is going downyour a is going up.  -- Chris Hadfield about flying up the space shuttle._______________________________________________OpenSCAD mailing listTo unsubscribe send an email to discuss-leave@lists.openscad.org
J
jay
Thu, Dec 22, 2022 2:02 PM

Typo sorry. Try that againWould i be correct in saying that the Preview is rendered by the underlying graphics library on the GPU and the Render is renderd by openscad on the CPU?Sent via the Samsung Galaxy S7, an AT&T 4G LTE smartphone
-------- Original message --------From: Rogier Wolff R.E.Wolff@BitWizard.nl Date: 12/22/22  1:22 PM  (GMT+00:00) To: OpenSCAD general discussion Mailing-list discuss@lists.openscad.org Subject: [OpenSCAD] Re: preview difference() glitch On Tue, Dec 20, 2022 at 04:42:26PM +0000, nop head wrote:> Yes, OpenCSG is used to draw the preview without calculating any of the> geometry. It just draws all the primitive objects with different graphics> modes.What it boils down to is that most people don't understand how say "acube" ends up on the screen. A quick computer graphics lesson:Let us work towards the situation where we put: difference () {cube (10);translate ([5,5,5]) cube (10);} on the screen. But first lets do the first cube only. In practice, these things often only work on triangles, Not sure ifnowadays that's still true, but for now lets pretend we can work withsquares too.The cube has 6 faces. For each face, we first compare the normal tothe viewing vector. If it is facing away from the camera(i.e. anglebetween them is less than 90 degrees), we can ignore it.This leaves us with just three faces we need to draw. We transform thecube's coorinates to screen coordinates and simply draw the pixelsinside the quadrilaterals with the proper color depending on the anglebetween the normal, viewing angle and the light source.Now if we want to draw a second cube (not a difference, like above,but a union), things get a bit fishy: Depending on the drawing orderyou get to see faces that should be obscured by the othercube. So... for each pixel, we calculate the distance from the viewingplane and store that together with the color of the pixel.Now while drawing a pixel instead of just drawing it, we compare thedepth value. If the current depth value is further away than what'salready drawn, we ignore this pixel of this face, otherwise we draw asnormal and update the depth value.Now you can pretty quickly get a reasonable preview for multipleobjects combined.But how to draw the difference?  For the "negative" cube in my examplecase we need to turn things around: We ignore faces pointing towardsus, and draw faces pointing away from us. Also the depth rule turnsaround: We only draw pixels that are DEEPER than the pixel alreadydrawn.Now this is going to be "messy" to implement. Corner cases everywhereand things like that, but this is the principle. All in all, this isthe X billion pixels per second that graphics cards claim to be ableto handle. So this also includes all the pixels that do NOT end up onyour screen.It also explains the Z-fighting that you sometimes see: Two planesin theory at precisely the same depth so it depends on floating pointrounding errors if one is in front of the other or not. Roger. -- ** R.E.Wolff@BitWizard.nl ** https://www.BitWizard.nl/ ** +31-15-2049110 ****    Delftechpark 11 2628 XJ  Delft, The Netherlands.  KVK: 27239233    **f equals m times a. When your f is steady, and your m is going downyour a is going up.  -- Chris Hadfield about flying up the space shuttle._______________________________________________OpenSCAD mailing listTo unsubscribe send an email to discuss-leave@lists.openscad.org

Typo sorry. Try that againWould i be correct in saying that the Preview is rendered by the underlying graphics library on the GPU and the Render is renderd by openscad on the CPU?Sent via the Samsung Galaxy S7, an AT&T 4G LTE smartphone -------- Original message --------From: Rogier Wolff <R.E.Wolff@BitWizard.nl> Date: 12/22/22 1:22 PM (GMT+00:00) To: OpenSCAD general discussion Mailing-list <discuss@lists.openscad.org> Subject: [OpenSCAD] Re: preview difference() glitch On Tue, Dec 20, 2022 at 04:42:26PM +0000, nop head wrote:> Yes, OpenCSG is used to draw the preview without calculating any of the> geometry. It just draws all the primitive objects with different graphics> modes.What it boils down to is that most people don't understand how say "acube" ends up on the screen. A quick computer graphics lesson:Let us work towards the situation where we put: difference () {cube (10);translate ([5,5,5]) cube (10);} on the screen. But first lets do the first cube only. In practice, these things often only work on triangles, Not sure ifnowadays that's still true, but for now lets pretend we can work withsquares too.The cube has 6 faces. For each face, we first compare the normal tothe viewing vector. If it is facing away from the camera(i.e. anglebetween them is less than 90 degrees), we can ignore it.This leaves us with just three faces we need to draw. We transform thecube's coorinates to screen coordinates and simply draw the pixelsinside the quadrilaterals with the proper color depending on the anglebetween the normal, viewing angle and the light source.Now if we want to draw a second cube (not a difference, like above,but a union), things get a bit fishy: Depending on the drawing orderyou get to see faces that should be obscured by the othercube. So... for each pixel, we calculate the distance from the viewingplane and store that together with the color of the pixel.Now while drawing a pixel instead of just drawing it, we compare thedepth value. If the current depth value is further away than what'salready drawn, we ignore this pixel of this face, otherwise we draw asnormal and update the depth value.Now you can pretty quickly get a reasonable preview for multipleobjects combined.But how to draw the difference?  For the "negative" cube in my examplecase we need to turn things around: We ignore faces pointing towardsus, and draw faces pointing away from us. Also the depth rule turnsaround: We only draw pixels that are DEEPER than the pixel alreadydrawn.Now this is going to be "messy" to implement. Corner cases everywhereand things like that, but this is the principle. All in all, this isthe X billion pixels per second that graphics cards claim to be ableto handle. So this also includes all the pixels that do NOT end up onyour screen.It also explains the Z-fighting that you sometimes see: Two planesin theory at precisely the same depth so it depends on floating pointrounding errors if one is in front of the other or not. Roger. -- ** R.E.Wolff@BitWizard.nl ** https://www.BitWizard.nl/ ** +31-15-2049110 ****    Delftechpark 11 2628 XJ  Delft, The Netherlands.  KVK: 27239233    **f equals m times a. When your f is steady, and your m is going downyour a is going up.  -- Chris Hadfield about flying up the space shuttle._______________________________________________OpenSCAD mailing listTo unsubscribe send an email to discuss-leave@lists.openscad.org
NH
nop head
Thu, Dec 22, 2022 2:52 PM

Preview is rendered using OpenCSG to simulate CSG operations using OpenGL.
Render uses CGAL to compute the final geometry and the resulting
polyhedrons are drawn using OpenGL. I don't think either make heavy use of
the GPU but CGAL makes very heavy use of the CPU.

To minimise the too close problem only subtract objects just big enough to
remove the geometry, rather than way bigger.

On Thu, 22 Dec 2022 at 14:03, jay jay@jdnd.co.uk wrote:

Typo sorry. Try that again

Would i be correct in saying that the Preview is rendered by the
underlying graphics library on the GPU and the Render is renderd by
openscad on the CPU?

Sent via the Samsung Galaxy S7, an AT&T 4G LTE smartphone

-------- Original message --------
From: Rogier Wolff R.E.Wolff@BitWizard.nl
Date: 12/22/22 1:22 PM (GMT+00:00)
To: OpenSCAD general discussion Mailing-list discuss@lists.openscad.org
Subject: [OpenSCAD] Re: preview difference() glitch

On Tue, Dec 20, 2022 at 04:42:26PM +0000, nop head wrote:

Yes, OpenCSG is used to draw the preview without calculating any of the
geometry. It just draws all the primitive objects with different graphics
modes.

What it boils down to is that most people don't understand how say "a
cube" ends up on the screen. A quick computer graphics lesson:

Let us work towards the situation where we put:

difference () {cube (10);translate ([5,5,5]) cube (10);}

on the screen. But first lets do the first cube only.

In practice, these things often only work on triangles, Not sure if
nowadays that's still true, but for now lets pretend we can work with
squares too.

The cube has 6 faces. For each face, we first compare the normal to
the viewing vector. If it is facing away from the camera(i.e. angle
between them is less than 90 degrees), we can ignore it.

This leaves us with just three faces we need to draw. We transform the
cube's coorinates to screen coordinates and simply draw the pixels
inside the quadrilaterals with the proper color depending on the angle
between the normal, viewing angle and the light source.

Now if we want to draw a second cube (not a difference, like above,
but a union), things get a bit fishy: Depending on the drawing order
you get to see faces that should be obscured by the other
cube. So... for each pixel, we calculate the distance from the viewing
plane and store that together with the color of the pixel.

Now while drawing a pixel instead of just drawing it, we compare the
depth value. If the current depth value is further away than what's
already drawn, we ignore this pixel of this face, otherwise we draw as
normal and update the depth value.

Now you can pretty quickly get a reasonable preview for multiple
objects combined.

But how to draw the difference?  For the "negative" cube in my example
case we need to turn things around: We ignore faces pointing towards
us, and draw faces pointing away from us. Also the depth rule turns
around: We only draw pixels that are DEEPER than the pixel already
drawn.

Now this is going to be "messy" to implement. Corner cases everywhere
and things like that, but this is the principle. All in all, this is
the X billion pixels per second that graphics cards claim to be able
to handle. So this also includes all the pixels that do NOT end up on
your screen.

It also explains the Z-fighting that you sometimes see: Two planes
in theory at precisely the same depth so it depends on floating point
rounding errors if one is in front of the other or not.

Roger.

--
** R.E.Wolff@BitWizard.nl ** https://www.BitWizard.nl/ ** +31-15-2049110
**
**    Delftechpark 11 2628 XJ  Delft, The Netherlands.  KVK: 27239233    **
f equals m times a. When your f is steady, and your m is going down
your a is going up.  -- Chris Hadfield about flying up the space shuttle.


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

Preview is rendered using OpenCSG to simulate CSG operations using OpenGL. Render uses CGAL to compute the final geometry and the resulting polyhedrons are drawn using OpenGL. I don't think either make heavy use of the GPU but CGAL makes very heavy use of the CPU. To minimise the too close problem only subtract objects just big enough to remove the geometry, rather than way bigger. On Thu, 22 Dec 2022 at 14:03, jay <jay@jdnd.co.uk> wrote: > Typo sorry. Try that again > > > Would i be correct in saying that the Preview is rendered by the > underlying graphics library on the GPU and the Render is renderd by > openscad on the CPU? > > > Sent via the Samsung Galaxy S7, an AT&T 4G LTE smartphone > > > -------- Original message -------- > From: Rogier Wolff <R.E.Wolff@BitWizard.nl> > Date: 12/22/22 1:22 PM (GMT+00:00) > To: OpenSCAD general discussion Mailing-list <discuss@lists.openscad.org> > Subject: [OpenSCAD] Re: preview difference() glitch > > On Tue, Dec 20, 2022 at 04:42:26PM +0000, nop head wrote: > > Yes, OpenCSG is used to draw the preview without calculating any of the > > geometry. It just draws all the primitive objects with different graphics > > modes. > > What it boils down to is that most people don't understand how say "a > cube" ends up on the screen. A quick computer graphics lesson: > > Let us work towards the situation where we put: > > difference () {cube (10);translate ([5,5,5]) cube (10);} > > on the screen. But first lets do the first cube only. > > In practice, these things often only work on triangles, Not sure if > nowadays that's still true, but for now lets pretend we can work with > squares too. > > The cube has 6 faces. For each face, we first compare the normal to > the viewing vector. If it is facing away from the camera(i.e. angle > between them is less than 90 degrees), we can ignore it. > > This leaves us with just three faces we need to draw. We transform the > cube's coorinates to screen coordinates and simply draw the pixels > inside the quadrilaterals with the proper color depending on the angle > between the normal, viewing angle and the light source. > > Now if we want to draw a second cube (not a difference, like above, > but a union), things get a bit fishy: Depending on the drawing order > you get to see faces that should be obscured by the other > cube. So... for each pixel, we calculate the distance from the viewing > plane and store that together with the color of the pixel. > > Now while drawing a pixel instead of just drawing it, we compare the > depth value. If the current depth value is further away than what's > already drawn, we ignore this pixel of this face, otherwise we draw as > normal and update the depth value. > > Now you can pretty quickly get a reasonable preview for multiple > objects combined. > > But how to draw the difference? For the "negative" cube in my example > case we need to turn things around: We ignore faces pointing towards > us, and draw faces pointing away from us. Also the depth rule turns > around: We only draw pixels that are DEEPER than the pixel already > drawn. > > Now this is going to be "messy" to implement. Corner cases everywhere > and things like that, but this is the principle. All in all, this is > the X billion pixels per second that graphics cards claim to be able > to handle. So this also includes all the pixels that do NOT end up on > your screen. > > It also explains the Z-fighting that you sometimes see: Two planes > in theory at precisely the same depth so it depends on floating point > rounding errors if one is in front of the other or not. > > Roger. > > -- > ** R.E.Wolff@BitWizard.nl ** https://www.BitWizard.nl/ ** +31-15-2049110 > ** > ** Delftechpark 11 2628 XJ Delft, The Netherlands. KVK: 27239233 ** > f equals m times a. When your f is steady, and your m is going down > your a is going up. -- Chris Hadfield about flying up the space shuttle. > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
BC
Bob Carter
Thu, Dec 22, 2022 4:12 PM

Likewise I use a fiddle factor to avoid fighting in preview that is coded out when rendered
ff = $preview ? 0.1 : 0 ;

On 22 Dec 2022, at 14:52, nop head nop.head@gmail.com wrote:

Preview is rendered using OpenCSG to simulate CSG operations using OpenGL. Render uses CGAL to compute the final geometry and the resulting polyhedrons are drawn using OpenGL. I don't think either make heavy use of the GPU but CGAL makes very heavy use of the CPU.

To minimise the too close problem only subtract objects just big enough to remove the geometry, rather than way bigger.

On Thu, 22 Dec 2022 at 14:03, jay <jay@jdnd.co.uk mailto:jay@jdnd.co.uk> wrote:
Typo sorry. Try that again

Would i be correct in saying that the Preview is rendered by the underlying graphics library on the GPU and the Render is renderd by openscad on the CPU?

Sent via the Samsung Galaxy S7, an AT&T 4G LTE smartphone

-------- Original message --------
From: Rogier Wolff R.E.Wolff@BitWizard.nl
Date: 12/22/22 1:22 PM (GMT+00:00)
To: OpenSCAD general discussion Mailing-list <discuss@lists.openscad.org mailto:discuss@lists.openscad.org>
Subject: [OpenSCAD] Re: preview difference() glitch

On Tue, Dec 20, 2022 at 04:42:26PM +0000, nop head wrote:

Yes, OpenCSG is used to draw the preview without calculating any of the
geometry. It just draws all the primitive objects with different graphics
modes.

What it boils down to is that most people don't understand how say "a
cube" ends up on the screen. A quick computer graphics lesson:

Let us work towards the situation where we put:

difference () {cube (10);translate ([5,5,5]) cube (10);}

on the screen. But first lets do the first cube only.

In practice, these things often only work on triangles, Not sure if
nowadays that's still true, but for now lets pretend we can work with
squares too.

The cube has 6 faces. For each face, we first compare the normal to
the viewing vector. If it is facing away from the camera(i.e. angle
between them is less than 90 degrees), we can ignore it.

This leaves us with just three faces we need to draw. We transform the
cube's coorinates to screen coordinates and simply draw the pixels
inside the quadrilaterals with the proper color depending on the angle
between the normal, viewing angle and the light source.

Now if we want to draw a second cube (not a difference, like above,
but a union), things get a bit fishy: Depending on the drawing order
you get to see faces that should be obscured by the other
cube. So... for each pixel, we calculate the distance from the viewing
plane and store that together with the color of the pixel.

Now while drawing a pixel instead of just drawing it, we compare the
depth value. If the current depth value is further away than what's
already drawn, we ignore this pixel of this face, otherwise we draw as
normal and update the depth value.

Now you can pretty quickly get a reasonable preview for multiple
objects combined.

But how to draw the difference?  For the "negative" cube in my example
case we need to turn things around: We ignore faces pointing towards
us, and draw faces pointing away from us. Also the depth rule turns
around: We only draw pixels that are DEEPER than the pixel already
drawn.

Now this is going to be "messy" to implement. Corner cases everywhere
and things like that, but this is the principle. All in all, this is
the X billion pixels per second that graphics cards claim to be able
to handle. So this also includes all the pixels that do NOT end up on
your screen.

It also explains the Z-fighting that you sometimes see: Two planes
in theory at precisely the same depth so it depends on floating point
rounding errors if one is in front of the other or not.

Roger.

--
** R.E.Wolff@BitWizard.nl ** https://www.BitWizard.nl/ https://www.bitwizard.nl/ ** +31-15-2049110 **
**    Delftechpark 11 2628 XJ  Delft, The Netherlands.  KVK: 27239233    **
f equals m times a. When your f is steady, and your m is going down
your a is going up.  -- Chris Hadfield about flying up the space shuttle.


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org mailto:discuss-leave@lists.openscad.org


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org mailto:discuss-leave@lists.openscad.org


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

Likewise I use a fiddle factor to avoid fighting in preview that is coded out when rendered ff = $preview ? 0.1 : 0 ; > On 22 Dec 2022, at 14:52, nop head <nop.head@gmail.com> wrote: > > Preview is rendered using OpenCSG to simulate CSG operations using OpenGL. Render uses CGAL to compute the final geometry and the resulting polyhedrons are drawn using OpenGL. I don't think either make heavy use of the GPU but CGAL makes very heavy use of the CPU. > > To minimise the too close problem only subtract objects just big enough to remove the geometry, rather than way bigger. > > On Thu, 22 Dec 2022 at 14:03, jay <jay@jdnd.co.uk <mailto:jay@jdnd.co.uk>> wrote: > Typo sorry. Try that again > > > Would i be correct in saying that the Preview is rendered by the underlying graphics library on the GPU and the Render is renderd by openscad on the CPU? > > > Sent via the Samsung Galaxy S7, an AT&T 4G LTE smartphone > > > -------- Original message -------- > From: Rogier Wolff <R.E.Wolff@BitWizard.nl> > Date: 12/22/22 1:22 PM (GMT+00:00) > To: OpenSCAD general discussion Mailing-list <discuss@lists.openscad.org <mailto:discuss@lists.openscad.org>> > Subject: [OpenSCAD] Re: preview difference() glitch > > On Tue, Dec 20, 2022 at 04:42:26PM +0000, nop head wrote: > > Yes, OpenCSG is used to draw the preview without calculating any of the > > geometry. It just draws all the primitive objects with different graphics > > modes. > > What it boils down to is that most people don't understand how say "a > cube" ends up on the screen. A quick computer graphics lesson: > > Let us work towards the situation where we put: > > difference () {cube (10);translate ([5,5,5]) cube (10);} > > on the screen. But first lets do the first cube only. > > In practice, these things often only work on triangles, Not sure if > nowadays that's still true, but for now lets pretend we can work with > squares too. > > The cube has 6 faces. For each face, we first compare the normal to > the viewing vector. If it is facing away from the camera(i.e. angle > between them is less than 90 degrees), we can ignore it. > > This leaves us with just three faces we need to draw. We transform the > cube's coorinates to screen coordinates and simply draw the pixels > inside the quadrilaterals with the proper color depending on the angle > between the normal, viewing angle and the light source. > > Now if we want to draw a second cube (not a difference, like above, > but a union), things get a bit fishy: Depending on the drawing order > you get to see faces that should be obscured by the other > cube. So... for each pixel, we calculate the distance from the viewing > plane and store that together with the color of the pixel. > > Now while drawing a pixel instead of just drawing it, we compare the > depth value. If the current depth value is further away than what's > already drawn, we ignore this pixel of this face, otherwise we draw as > normal and update the depth value. > > Now you can pretty quickly get a reasonable preview for multiple > objects combined. > > But how to draw the difference? For the "negative" cube in my example > case we need to turn things around: We ignore faces pointing towards > us, and draw faces pointing away from us. Also the depth rule turns > around: We only draw pixels that are DEEPER than the pixel already > drawn. > > Now this is going to be "messy" to implement. Corner cases everywhere > and things like that, but this is the principle. All in all, this is > the X billion pixels per second that graphics cards claim to be able > to handle. So this also includes all the pixels that do NOT end up on > your screen. > > It also explains the Z-fighting that you sometimes see: Two planes > in theory at precisely the same depth so it depends on floating point > rounding errors if one is in front of the other or not. > > Roger. > > -- > ** R.E.Wolff@BitWizard.nl ** https://www.BitWizard.nl/ <https://www.bitwizard.nl/> ** +31-15-2049110 ** > ** Delftechpark 11 2628 XJ Delft, The Netherlands. KVK: 27239233 ** > f equals m times a. When your f is steady, and your m is going down > your a is going up. -- Chris Hadfield about flying up the space shuttle. > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org <mailto:discuss-leave@lists.openscad.org> > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org <mailto:discuss-leave@lists.openscad.org> > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org
TP
Torsten Paul
Thu, Dec 22, 2022 4:19 PM

On 22.12.22 17:12, Bob Carter wrote:

Likewise I use a fiddle factor to avoid fighting in preview that is coded out when rendered
ff = $preview ? 0.1 : 0 ;

I would recommend against that. In most cases this might be fine
but at the expense of more code complexity, it increases the risk
of failures at render time.

While it is needed in fewer places for render, I don't remember
any case where it was wrong to have it when it was needed for
preview.

ciao,
Torsten.

On 22.12.22 17:12, Bob Carter wrote: > Likewise I use a fiddle factor to avoid fighting in preview that is coded out when rendered > ff = $preview ? 0.1 : 0 ; I would recommend against that. In most cases this might be fine but at the expense of more code complexity, it increases the risk of failures at render time. While it is needed in fewer places for render, I don't remember any case where it was *wrong* to have it when it was needed for preview. ciao, Torsten.
JB
Jordan Brown
Thu, Dec 22, 2022 5:16 PM

Yeah, I don't think you ever need to make it conditional, and usually
you don't have to make it particularly small either.

Just make the negative and intersecting objects a little bigger in the
appropriate axes, so that they protrude beyond the object that remains.
  I use +1, and for a hole that goes all the way through use *3 and center.

a = 5;
b = a*2;

difference() {
    cube(b);
    #translate([a,a,a]) cylinder(h=a+1, d=a);
}

translate([20,0,0]) {
    intersection() {
        cylinder(h=b, d=b);
        #translate([0,-a-1,-1])
            cube([a+1, b+2, b+2]);
    }
}

translate([30,0,0]) {
    difference() {
        cube(b);
        #translate([a,a,0])
            cylinder(h=b*3, d=a, center=true);
    }
}

What's harder is if you want to make things be multiple colors, because
then you're dealing with surfaces that are supposed to be visible.

Yeah, I don't think you ever need to make it conditional, and usually you don't have to make it particularly small either. Just make the negative and intersecting objects a little bigger in the appropriate axes, so that they protrude beyond the object that remains.   I use +1, and for a hole that goes all the way through use *3 and center. a = 5; b = a*2; difference() { cube(b); #translate([a,a,a]) cylinder(h=a+1, d=a); } translate([20,0,0]) { intersection() { cylinder(h=b, d=b); #translate([0,-a-1,-1]) cube([a+1, b+2, b+2]); } } translate([30,0,0]) { difference() { cube(b); #translate([a,a,0]) cylinder(h=b*3, d=a, center=true); } } What's harder is if you want to make things be multiple colors, because then you're dealing with surfaces that are supposed to be visible.
J
jay@jdnd.co.uk
Fri, Dec 23, 2022 12:48 PM

i don't see any reason for it being conditional, but i do have to make
it as small as i can possibly get away with, otherwise it can throw
angles out quite easily without realizing and then things don't quite
fit together at the end.

i usual use "tol = 0.01; tol2=tol*2;" at the top of the file, if for any
reason i needed rid of it i could just change one value "tol" to zero;

On 2022-12-22 17:16, Jordan Brown wrote:

Yeah, I don't think you ever need to make it conditional, and usually
you don't have to make it particularly small either.

Just make the negative and intersecting objects a little bigger in the
appropriate axes, so that they protrude beyond the object that remains.
I use +1, and for a hole that goes all the way through use *3 and
center.

a = 5;
b = a*2;

difference() {
cube(b);
#translate([a,a,a]) cylinder(h=a+1, d=a);
}

translate([20,0,0]) {
intersection() {
cylinder(h=b, d=b);
#translate([0,-a-1,-1])
cube([a+1, b+2, b+2]);
}
}

translate([30,0,0]) {
difference() {
cube(b);
#translate([a,a,0])
cylinder(h=b*3, d=a, center=true);
}
}

What's harder is if you want to make things be multiple colors, because
then you're dealing with surfaces that are supposed to be visible.


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

i don't see any reason for it being conditional, but i do have to make it as small as i can possibly get away with, otherwise it can throw angles out quite easily without realizing and then things don't quite fit together at the end. i usual use "tol = 0.01; tol2=tol*2;" at the top of the file, if for any reason i needed rid of it i could just change one value "tol" to zero; On 2022-12-22 17:16, Jordan Brown wrote: > Yeah, I don't think you ever need to make it conditional, and usually > you don't have to make it particularly small either. > > Just make the negative and intersecting objects a little bigger in the > appropriate axes, so that they protrude beyond the object that remains. > I use +1, and for a hole that goes all the way through use *3 and > center. > >> a = 5; >> b = a*2; >> >> difference() { >> cube(b); >> #translate([a,a,a]) cylinder(h=a+1, d=a); >> } >> >> translate([20,0,0]) { >> intersection() { >> cylinder(h=b, d=b); >> #translate([0,-a-1,-1]) >> cube([a+1, b+2, b+2]); >> } >> } >> >> translate([30,0,0]) { >> difference() { >> cube(b); >> #translate([a,a,0]) >> cylinder(h=b*3, d=a, center=true); >> } >> } > > What's harder is if you want to make things be multiple colors, because > then you're dealing with surfaces that are supposed to be visible. > > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org
JB
Jordan Brown
Fri, Dec 23, 2022 6:34 PM

On 12/23/2022 4:48 AM, jay@jdnd.co.uk wrote:

i don't see any reason for it being conditional, but i do have to make
it as small as i can possibly get away with, otherwise it can throw
angles out quite easily without realizing and then things don't quite
fit together at the end.

i usual use "tol = 0.01; tol2=tol*2;" at the top of the file, if for
any reason i needed rid of it i could just change one value "tol" to zero;

I'd be interested to see a case where you have a problem.

The "excess" should all be in parts of the shape that do not end up in
the final model because they are negative space (for a difference) or
extend past the other object (for an intersection).

I started off with "epsilon=0.1" or something like that, but that was
too much typing and so I just started using +1 or -1, or sometimes
+2/-2, and haven't had a problem.  Almost everything else in my modeling
has dimensions in variables, so when I see "h+1" I know what's going on.

I wonder whether a fix, for difference at least, would be to bump the
negative triangles epsilon closer to the camera, so that if a negative
and positive triangle were going to collide the negative one would
always win.

On 12/23/2022 4:48 AM, jay@jdnd.co.uk wrote: > > i don't see any reason for it being conditional, but i do have to make > it as small as i can possibly get away with, otherwise it can throw > angles out quite easily without realizing and then things don't quite > fit together at the end. > > i usual use "tol = 0.01; tol2=tol*2;" at the top of the file, if for > any reason i needed rid of it i could just change one value "tol" to zero; > I'd be interested to see a case where you have a problem. The "excess" should all be in parts of the shape that do not end up in the final model because they are negative space (for a difference) or extend past the other object (for an intersection). I started off with "epsilon=0.1" or something like that, but that was too much typing and so I just started using +1 or -1, or sometimes +2/-2, and haven't had a problem.  Almost everything else in my modeling has dimensions in variables, so when I see "h+1" I know what's going on. I wonder whether a fix, for difference at least, would be to bump the negative triangles epsilon closer to the camera, so that if a negative and positive triangle were going to collide the negative one would always win.
J
jay@jdnd.co.uk
Fri, Dec 23, 2022 7:08 PM

Quote

I'd be interested to see a case where you have a problem.

this works fine

//tol = 2;
tol = 0.001;
tol2 = tol*2;

//difference()
{
size = 3;
angle = 10;

 color("red")
 cube([size, size, size]);

 color("blue")
 translate([0-tol, (size/2)-tol, -tol])
 rotate([0, 0, angle])
 cube([size*2, size*2, size+tol2]);

}

now swap out tol=2

tol = 2;
//tol = 0.001;
tol2 = tol*2;

//difference()
{
size = 3;
angle = 10;

 color("red")
 cube([size, size, size]);

 color("blue")
 translate([0-tol, (size/2)-tol, -tol])
 rotate([0, 0, angle])
 cube([size*2, size*2, size+tol2]);

}

the intersection is in completely the wrong place and the final result
is a smaller object

just saying, you have to be careful using large numbers as it can easily
affect the final shape without noticing

On 2022-12-23 18:34, Jordan Brown wrote:

On 12/23/2022 4:48 AM, jay@jdnd.co.uk wrote:

i don't see any reason for it being conditional, but i do have to make
it as small as i can possibly get away with, otherwise it can throw
angles out quite easily without realizing and then things don't quite
fit together at the end.

i usual use "tol = 0.01; tol2=tol*2;" at the top of the file, if for
any reason i needed rid of it i could just change one value "tol" to
zero;

I'd be interested to see a case where you have a problem.

The "excess" should all be in parts of the shape that do not end up in
the final model because they are negative space (for a difference) or
extend past the other object (for an intersection).

I started off with "epsilon=0.1" or something like that, but that was
too much typing and so I just started using +1 or -1, or sometimes
+2/-2, and haven't had a problem.  Almost everything else in my
modeling has dimensions in variables, so when I see "h+1" I know what's
going on.

I wonder whether a fix, for difference at least, would be to bump the
negative triangles epsilon closer to the camera, so that if a negative
and positive triangle were going to collide the negative one would
always win.


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

Quote I'd be interested to see a case where you have a problem. this works fine //tol = 2; tol = 0.001; tol2 = tol*2; //difference() { size = 3; angle = 10; color("red") cube([size, size, size]); color("blue") translate([0-tol, (size/2)-tol, -tol]) rotate([0, 0, angle]) cube([size*2, size*2, size+tol2]); } now swap out tol=2 tol = 2; //tol = 0.001; tol2 = tol*2; //difference() { size = 3; angle = 10; color("red") cube([size, size, size]); color("blue") translate([0-tol, (size/2)-tol, -tol]) rotate([0, 0, angle]) cube([size*2, size*2, size+tol2]); } the intersection is in completely the wrong place and the final result is a smaller object just saying, you have to be careful using large numbers as it can easily affect the final shape without noticing On 2022-12-23 18:34, Jordan Brown wrote: > On 12/23/2022 4:48 AM, jay@jdnd.co.uk wrote: > >> i don't see any reason for it being conditional, but i do have to make >> it as small as i can possibly get away with, otherwise it can throw >> angles out quite easily without realizing and then things don't quite >> fit together at the end. >> >> i usual use "tol = 0.01; tol2=tol*2;" at the top of the file, if for >> any reason i needed rid of it i could just change one value "tol" to >> zero; > > I'd be interested to see a case where you have a problem. > > The "excess" should all be in parts of the shape that do not end up in > the final model because they are negative space (for a difference) or > extend past the other object (for an intersection). > > I started off with "epsilon=0.1" or something like that, but that was > too much typing and so I just started using +1 or -1, or sometimes > +2/-2, and haven't had a problem. Almost everything else in my > modeling has dimensions in variables, so when I see "h+1" I know what's > going on. > > I wonder whether a fix, for difference at least, would be to bump the > negative triangles epsilon closer to the camera, so that if a negative > and positive triangle were going to collide the negative one would > always win. > > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org