shadows in the freecad viewport

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
carlopav
Posts: 1363
Joined: Mon Dec 31, 2018 1:49 pm
Location: Venice, Italy

Re: shadows in the freecad viewport

Postby carlopav » Tue May 05, 2020 12:22 pm

realthunder wrote:
Tue May 05, 2020 10:21 am
You are using Windows right? Did you see the shadow? On my Windows machine, I see blank when using SoShadowDirectionalLight or SoShadowSpotLight. Changing to SoDirectionalLight shows the object and ground but no shadow. Changing to SoSpotLight shows the shadow, but the whole scene disappears as long as I move my mouse over any object, and will reappear if I rotate the scene. There is no problem on my Linux machine.

Can you please open this test file with FC and check if there is anything wrong.
Win 10: I see the shadows, and I get the illegal storage. Cannot test the file right now.
Win 7: I do not see the shadows, and I get the illegal storage.

File test with windows 7: I operend the file, i do not see anything in the scenegraph until I pan or obit the view. While moving the view I can see the checked plane with 3 obects moving over it, no shadows. When I stop moving the camera, i just see an empty background, every object disappears (also if i add objects to the scene, I can see them only while moving the camera). If I switch display mode to shadows, i can't see anything also while orbiting.

Edit: I had some problem one year ago with the win7 laptop and I had to disable some environment variables for the problem of black freecad window (and also selected faces sometimes are not displayed properly), so I guess my old Nvidia 540m is not the best for fc. Perhaps this is related to the viz problems...
Last edited by carlopav on Tue May 05, 2020 8:18 pm, edited 1 time in total.
follow my experiments on BIM modelling for architecture design
carlopav
Posts: 1363
Joined: Mon Dec 31, 2018 1:49 pm
Location: Venice, Italy

Re: shadows in the freecad viewport

Postby carlopav » Tue May 05, 2020 2:09 pm

realthunder wrote:
Tue May 05, 2020 10:21 am
Can you please open this test file with FC and check if there is anything wrong.
Tested the file with with:

Code: Select all

OS: Windows 10 (10.0)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.20886 +2210 (Git)
Build type: Release
Branch: LinkStage3
Hash: 4a200e528f883f8b40f5a278e58e404c7e0b9541
Python version: 3.6.8
Qt version: 5.12.1
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: Italian/Italy (it_IT)
No shadows but i can see the objects moving over the checked plane (all the other display mode work as expected). If I click them they become transparent (i guess this is the standard for selected objects), and I can add objects without problems.
If I pan on the dark corner direction, every object becomes black, as if there is a limit of a spotlight moving with the camera.
Hope this can help :)

Cattura.JPG
Cattura.JPG (54.6 KiB) Viewed 564 times
follow my experiments on BIM modelling for architecture design
realthunder
Posts: 1580
Joined: Tue Jan 03, 2017 10:55 am

Re: shadows in the freecad viewport

Postby realthunder » Tue May 05, 2020 10:54 pm

carlopav wrote:
Tue May 05, 2020 12:22 pm
Edit: I had some problem one year ago with the win7 laptop and I had to disable some environment variables for the problem of black freecad window (and also selected faces sometimes are not displayed properly), so I guess my old Nvidia 540m is not the best for fc. Perhaps this is related to the viz problems...
Yeah, I think this shadow rendering is pretty sensitive to underlying graphics card and driver. I have yet to find a setup that's working on my 7 year old Windows laptop.
Try Assembly3 (latest version 0.11) along with my custom build of FreeCAD at here.
And if you'd like to show your support, you can donate through patreon, liberapay, or paypal
nic
Posts: 71
Joined: Thu Apr 18, 2019 1:14 pm
Location: France

Re: shadows in the freecad viewport

Postby nic » Thu May 07, 2020 8:32 am

Hi @realthunder

Same here with the following configuration:

Code: Select all

OS: Ubuntu 19.10 (Regolith:GNOME-Flashback:GNOME/regolith)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.20886 +2210 (Git) AppImage
Build type: Release
Branch: LinkStage3
Hash: 4a200e528f883f8b40f5a278e58e404c7e0b9541
Python version: 3.7.6
Qt version: 5.12.1
Coin version: 4.0.0
OCC version: 7.4.0
Locale: French/France (fr_FR)
My graphic card:

Code: Select all

% sudo lshw -c video   
  *-display                 
       description: VGA compatible controller
       produit: HD Graphics 620
       fabricant: Intel Corporation
       identifiant matériel: 2
       information bus: pci@0000:00:02.0
       version: 02
       bits: 64 bits
       horloge: 33MHz
       fonctionnalités: pciexpress msi pm vga_controller bus_master cap_list rom
       configuration : driver=i915 latency=0
       ressources : irq:131 mémoire:de000000-deffffff mémoire:c0000000-cfffffff portE/S:f000(taille=64) mémoire:c0000-dffff
       
The shadow rendering crash on Freecad file with the following stack:

Code: Select all

Received signal 11 <unknown> 000000000000
#0 0x7f84e1a6f94e <unknown>
#1 0x7f84e1a6fdfa <unknown>
#2 0x7f84e1a70345 <unknown>
#3 0x7f850c615470 <unknown>
#4 0x7f850dc2f426 SoSeparator::GLRenderInPath()
#5 0x7f850f1c92c1 Gui::SoFCSelectionRoot::_renderPrivate()
#6 0x7f850f1c9785 Gui::SoFCSelectionRoot::renderPrivate()
#7 0x7f850dc2f510 SoSeparator::GLRenderInPath()
#8 0x7f850f1b43ab Gui::SoFCUnifiedSelection::GLRenderInPath()
#9 0x7f850d9d123a SoAction::traverse()
#10 0x7f850d9d961e SoGLRenderAction::beginTraversal()
#11 0x7f850d9d1b9a SoAction::apply()
#12 0x7f850d9d8c54 SoGLRenderActionP::renderSingle()
#13 0x7f850d9d8fce SoGLRenderActionP::render()
#14 0x7f850d9d95eb SoGLRenderAction::beginTraversal()
#15 0x7f850d9d20a2 SoAction::apply()
#16 0x7f850f1d288a Gui::SoBoxSelectionRenderAction::apply()
#17 0x7f850dd09e75 SoRenderManager::renderScene()
#18 0x7f850dd0afcb SoRenderManager::actuallyRender()
#19 0x7f850dd0b197 SoRenderManager::renderSingle()
#20 0x7f850dd0b7d0 SoRenderManager::render()
#21 0x7f850dd0964d SoRenderManager::render()
#22 0x7f850f292d0a Gui::View3DInventorViewer::renderScene()
#23 0x7f850f251085 SIM::Coin3D::Quarter::QuarterWidget::paintEvent()
#24 0x7f850f257aa5 SIM::Coin3D::Quarter::SoQTQuarterAdaptor::paintEvent()
#25 0x7f850d36d129 QWidget::event()
#26 0x7f850d3d651f QFrame::event()
#27 0x7f850d550aeb QGraphicsView::viewportEvent()
#28 0x7f850f25115a SIM::Coin3D::Quarter::QuarterWidget::viewportEvent()
#29 0x7f850cb23101 QCoreApplicationPrivate::sendThroughObjectEventFilters()
#30 0x7f850d34187e QApplicationPrivate::notify_helper()
#31 0x7f850d347551 QApplication::notify()
#32 0x7f850ef5c519 Gui::GUIApplication::notify()
#33 0x7f850cb256f8 QCoreApplication::notifyInternal2()
#34 0x7f850d367bef QWidgetPrivate::sendPaintEvent()
#35 0x7f850d34bcfa <unknown>
#36 0x7f850d34c3f0 <unknown>
#37 0x7f850d35d7cd QWidgetPrivate::syncBackingStore()
#38 0x7f850d36d4ae QWidget::event()
#39 0x7f850d417627 QMainWindow::event()
#40 0x7f850f36bf8c Gui::MainWindow::event()
#41 0x7f850d34188e QApplicationPrivate::notify_helper()
#42 0x7f850d347551 QApplication::notify()
#43 0x7f850ef5c519 Gui::GUIApplication::notify()
#44 0x7f850cb256f8 QCoreApplication::notifyInternal2()
#45 0x7f850cb2593f QCoreApplicationPrivate::sendPostedEvents()
#46 0x7f850cb54d68 <unknown>
#47 0x7f8509ba257b g_main_context_dispatch
#48 0x7f8509ba27c1 g_main_context_iterate.isra.23
#49 0x7f8509ba284e g_main_context_iteration
#50 0x7f850cb5491d QEventDispatcherGlib::processEvents()
#51 0x7f850cb2221b QEventLoop::exec()
#52 0x7f850cb25fab QCoreApplication::exec()
#53 0x7f850eec73bd Gui::Application::runApplication()
#54 0x56220a3ab7cd main
#55 0x7f850c5f61e3 __libc_start_main
#56 0x56220a3ac51f <unknown>
  r8: 00005622168575f8  r9: 0000562216857620 r10: 00007ffdc89e5a97 r11: 00005622169295e0
 r12: 00005622168f2ed0 r13: 0000000000000000 r14: 0000000000000000 r15: 7400630065006c00
  di: 00005622168f2ed0  si: 0000000000000000  bp: 0000562217e2e830  bx: 0000000000000002
  dx: 0000562217e2e830  ax: 0000000000000000  cx: 0000000000000000  sp: 00007ffdc89e5b10
  ip: 00007f850dc2f426 efl: 0000000000010246 cgf: 002b000000000033 erf: 0000000000000000
 trp: 000000000000000d msk: 0000000000000000 cr2: 0000000000000000
[end of stack trace]
Calling _exit(1). Core file will not be generated.
zsh: exit 1     ./FreeCAD_0.19-realthunder.AppImage
With the test file, I can see the yellow ball moving, but no shadow.
realthunder
Posts: 1580
Joined: Tue Jan 03, 2017 10:55 am

Re: shadows in the freecad viewport

Postby realthunder » Sat May 09, 2020 2:21 pm

New image uploaded.

The crash should have been fixed. I have studied a bit of Coin's shadow code. And found a bug that is causing the crash. There is another bug causing Spot lighted scene not showing. I added a work around, and spot light is sort of working on my laptop. You can use preferences -> colors -> draw style to change default shadow light type. If you find your 3D view flashes when mouse over the model, then you computer is affected by the bug. Still can't get directional light working on my laptop yet.

Also, you can now create new views of the same document with independent draw style, with optional binding cameras that can be saved and restored. See here and here for more details.
Try Assembly3 (latest version 0.11) along with my custom build of FreeCAD at here.
And if you'd like to show your support, you can donate through patreon, liberapay, or paypal
carlopav
Posts: 1363
Joined: Mon Dec 31, 2018 1:49 pm
Location: Venice, Italy

Re: shadows in the freecad viewport

Postby carlopav » Sat May 09, 2020 5:19 pm

realthunder wrote:
Sat May 09, 2020 2:21 pm
New image uploaded.
I confirm the crash is fixed with:

Code: Select all

OS: Windows 7 SP 1 (6.1)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.20886 +2245 (Git)
Build type: Release
Branch: LinkStage3
Hash: 5fa0248e91142a5a97c5dba14ef50bd182bec634
Python version: 3.6.8
Qt version: 5.12.1
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: Italian/Italy (it_IT)
And I can also use the shadows on my laptop!! ( :oops: I spotted FreeCAD was not using Nvidia graphics card but the Intel one, when forced windows to run FreeCAD with nvidia 540m, everything perfect!)
follow my experiments on BIM modelling for architecture design
OficineRobotica
Posts: 186
Joined: Thu Feb 21, 2019 8:17 am

Re: shadows in the freecad viewport

Postby OficineRobotica » Sun May 17, 2020 7:54 am

realthunder wrote:
Sat May 09, 2020 2:21 pm
I was going to write an essay about how much I love this feature but I'm saving that for the overlay ui thread.

I would like to make 2 quick suggestions:

1) In my humble opinion, the defaults for the shadowed display should be a bit different for out of the box awesomeness.
-flat lines should default to true
-ground color default to neutral gray #7d7d7d (this should play well with dark and light themes, anything but white)
-ground placement to -1 , this should fake ambient occlusion at the base of the model (debatable, but only my opinion)
-light color #f0fdff(mild blue sky color) or #fffef0(warm sun color). This small change, from my fiddling with settings, gives both architectural and mechanical scenes a big realistic effect.

defaultsModified.gif
defaultsModified.gif (892.66 KiB) Viewed 282 times

2) Can the ground have a third option other than on and off? Grid. That is a grid instead of the solid ground but that catches shadows. Transparent ground not just a overlayed grid on the solid ground. I can only imagine how cool that would look.

I posted 2 screenshots in the "call for screenshots" thread and Freecad looks just beautiful and modern.
realthunder
Posts: 1580
Joined: Tue Jan 03, 2017 10:55 am

Re: shadows in the freecad viewport

Postby realthunder » Wed May 20, 2020 10:43 am

OficineRobotica wrote:
Sun May 17, 2020 7:54 am
2) Can the ground have a third option other than on and off? Grid. That is a grid instead of the solid ground but that catches shadows. Transparent ground not just a overlayed grid on the solid ground. I can only imagine how cool that would look.
How about this, texture with bump map. I spent great effort to make this work, because Coin3D has trouble showing bump mapped surface that also receives shadow from other objects. I need to patch Coin3D to make it work. It still has a few glitches, but at least working to some extent. I think it is a proof of concept that we can have those realistic looking materials shown in those commercial CAD.
shadow-bump.gif
shadow-bump.gif (668.85 KiB) Viewed 201 times
Try Assembly3 (latest version 0.11) along with my custom build of FreeCAD at here.
And if you'd like to show your support, you can donate through patreon, liberapay, or paypal
User avatar
pablogil
Posts: 834
Joined: Wed Nov 26, 2014 3:19 pm
Location: Badajoz (Spain)
Contact:

Re: shadows in the freecad viewport

Postby pablogil » Wed May 20, 2020 1:22 pm

Very cool @realthunder!

Would it be possible to cast a shadow with a transparent ground? I mean, a way to only show the shadow but let it "blend" with the 3D view background (color or gradient)

Thanks
Dark and Light stylesheets v2.0 to theme your FreeCAD UI, more information here
realthunder
Posts: 1580
Joined: Tue Jan 03, 2017 10:55 am

Re: shadows in the freecad viewport

Postby realthunder » Wed May 20, 2020 1:28 pm

pablogil wrote:
Wed May 20, 2020 1:22 pm
Would it be possible to cast a shadow with a transparent ground? I mean, a way to only show the shadow but let it "blend" with the 3D view background (color or gradient)
You can change the ground color to match the background, or increase the ground scale so that the edge won't show easily when you zoom out.
Try Assembly3 (latest version 0.11) along with my custom build of FreeCAD at here.
And if you'd like to show your support, you can donate through patreon, liberapay, or paypal