cormullion / Thebes.jl

Thebes.jl is a simple little package that provides 3D services to Luxor.jl.
https://cormullion.github.io/Thebes.jl/
Other
31 stars 3 forks source link

How hard would be to implement a “light” object? #11

Open davibarreira opened 2 years ago

davibarreira commented 2 years ago

I saw that in the example of the Julia like spheres, you’ve coded in a way that the spheres have shadow. I was wondering how hard would be to implement a sort of “light pole” such that a shadow could be caste in the correct direction. For example, if I wish to perceive a sphere, I’d need a shadow like the one you hard coded.

cormullion commented 2 years ago

Hi Davi! Thebes isn't really 3D, more 2.5D, and it's a bit of a con, really 😃 By changing the colours of 3D planes according to the angles of their surface normals, we can give the illusion of lighter and darker surfaces. Using the eyepoint as the basis for measuring these angles works for this example ... so if you had a different point other than the eyepoint for calculating the colours, the illusion would work for that point, I think, but you would keep the calculations for hidden-surface removal the same. It might work.

But "casting shadows" suggests that there's some interaction between different objects - at the moment, everything is completely independent of everything else.

I sometimes wonder whether developing some kind of output function to Makie or Blender would be more productive than pursuing realistic images: making shapes is easier than developing a ray-tracing rendering function. But then, why not go straight to Makie or Blender? 😃

davibarreira commented 2 years ago

Hmm, now I understand the idea a bit better. I didn't actually thought about "casting shadows", only about the color gradient stuff you just described, in order to give the illusion of 3D. As for why using Thebes. First, cause is awesomely easy :D Second, the fact that it's all Luxor makes 2D and 2.5D sort of one thing. So, everything is very light weight, which is great.

So, is the gradient functionality already implemented under the hood for the eyepoint? I mean, do I need to personally implement the gradient functionality if I wish to plot a sphere?

davibarreira commented 2 years ago

I realized that my question was wrongly posed for what I actually meant. I'm not interested in actually having a light that creates shadows, but in this nifty implementation of rendering according to eyeypoint, in order to perceive objects are 3D.

cormullion commented 2 years ago

do I need to personally implement the gradient functionality if I wish to plot a sphere?

Yes, you’d have to write a rendering function that determines how you want to draw the faces. The default ones are quite basic. If you just want to colour them with random Julia colours, that’s fine 😂 - but you still have to work out which ones are hidden… If you also want to adjust the colours according to the angle the surface points in, then that example code should be a good start. Ray-tracing - why not!?