shadows in the freecad viewport

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
User avatar
yorik
Site Admin
Posts: 8661
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

shadows in the freecad viewport

Postby yorik » Mon Feb 09, 2015 1:53 pm

Proof of concept, it works!!! It's even pretty fast!

Apparently you need a good 3D hardware. It works with my nvidia chip, but not when running on the intel...

freecad-shadows.jpg
freecad-shadows.jpg (201.43 KiB) Viewed 1448 times


Attached is the .iv file...
Attachments
shadow-test.iv
(266.83 KiB) Downloaded 76 times
User avatar
quick61
Posts: 3673
Joined: Sat Aug 24, 2013 2:49 am
Location: u.S.A.

Re: shadows in the freecad viewport

Postby quick61 » Mon Feb 09, 2015 2:37 pm

Hey Yorik, that looks great. Is it easy to position the light source, or length of shadow or whatever method is used? Like can it have a variable setting? Also, if this actually easy to implement, is it the same for other features like mirror Z, mirror texture, atmosphere, and whatever other goodies there are available?

Mark
This post made with 0.0% Micro$oft products - GOT LINUX?
User avatar
yorik
Site Admin
Posts: 8661
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

Re: shadows in the freecad viewport

Postby yorik » Mon Feb 09, 2015 2:57 pm

If you look in the .iv file you'll see how it works: You need a spotlight (IFAICS directionalLights don't work), the cutOffAngle and dropOffRate control how the shadows look like. There is more info on http://coin3d.bitbucket.org/Coin/classS ... Group.html

Implementing this FreeCAD-wide seems not specially difficult (one just needs to "encapsulate" the whole scene inside a SoShadowGroup object and add a ground plane, maybe modify the default lights too), then there could easily be some setting to switch that behaviour on/off.

About the other features, I haven't looked much yet. Fog seems easy too, same system ( http://coin3d.bitbucket.org/Coin/classS ... nment.html ), mirroring I don't remember exactly how Jürgen did it, but I think it involved copying all the scene contents... As for advanced texturing, that's a whole more complex matter, it involves implementing stuff at object level, and will ask for mch more complex controls...
balazs
Posts: 100
Joined: Thu Oct 16, 2014 3:40 pm

Re: shadows in the freecad viewport

Postby balazs » Mon Feb 09, 2015 8:08 pm

Hi Yorik,

This looks really great...

yorik wrote:If you look in the .iv file you'll see how it works: You need a spotlight (IFAICS directionalLights don't work), the


Where do you position your spotlight? From an architect point of view a SoDirectionalLight (as the model of the Sun) would be important, too. For it, a practical set of control properties would be

  • a north arrow
  • latitude of the building (or a major city, but that may come in the future)
  • month and day
  • local time

It is sure we can find a library or algorithm calculating sunlight direction from the above data. I do not know one.

What do you think about it?

Best regards: Balázs
User avatar
yorik
Site Admin
Posts: 8661
Joined: Tue Feb 17, 2009 9:16 pm
Location: São Paulo, Brazil
Contact:

Re: shadows in the freecad viewport

Postby yorik » Mon Feb 09, 2015 8:46 pm

If coin3d doesn't produce shadows from directional lights, there is little we can do unfortunately. Note that blender also doesn't do that... There must be something that prevents it, most probably it is not supported by OpenGL.

But we could still find something that allows to place a light automatically at a correct sun position.
User avatar
shoogen
Posts: 2822
Joined: Thu Dec 01, 2011 5:24 pm

Re: shadows in the freecad viewport

Postby shoogen » Mon Feb 09, 2015 8:51 pm

yorik wrote:But we could still find something that allows to place a light automatically at a correct sun position.
Like 1.5E14 mm from the origin? ;)
balazs
Posts: 100
Joined: Thu Oct 16, 2014 3:40 pm

Re: shadows in the freecad viewport

Postby balazs » Mon Feb 09, 2015 9:26 pm

shoogen wrote:Like 1.5E14 mm from the origin? ;)


Yes, something like it. A distance big enough to give a good approximate of the Sun - which itself is also far closer than infinity :)

Yorik, have you tried smoothBorder > 0 in SoShadowGroup?
User avatar
quick61
Posts: 3673
Joined: Sat Aug 24, 2013 2:49 am
Location: u.S.A.

Re: shadows in the freecad viewport

Postby quick61 » Mon Feb 09, 2015 9:29 pm

shoogen wrote:
yorik wrote:But we could still find something that allows to place a light automatically at a correct sun position.
Like 1.5E14 mm from the origin? ;)


Hey, that's only about 1.58553512 × 10^-5 light years. Hummm, sounds about right.
This post made with 0.0% Micro$oft products - GOT LINUX?
User avatar
microelly2
Posts: 2441
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: shadows in the freecad viewport

Postby microelly2 » Thu Mar 05, 2015 9:54 am

I have done some experiments with inventor/vrml-lights and the seem to work - but there is to much light by default.
Is there a way to shut off the light in the 3D scene to get a dark room?


EDIT
I have 3 spotlights to the cones, but there is still some ambient light :?
the spotlights still do not work as in the examples of the inventor mentor book
I cannot see the end of the light cones
Attachments
bn_553.png
bn_553.png (66.17 KiB) Viewed 1178 times