Jump to content

Questions about shadows


Kesshi
 Share

Recommended Posts

Hi,

in my application i would like to add shadows on the ground but i have some questions:

1. Is it possible to have a light which casts a shadow without emitting light? I ask this because i have a fixed light setup which i don't want to change but i need a shadow under my objects. The shadow should come exaclty from the top but i dont want to make my objects brighter as they already are. I would need some kind of shadow only light.

2. In order to have shadows i need to fill the renderlist of the shadow map with my meshes. That means i need to sync the renderlist with my scene all the time. For me it would be much easier if i could write a predicate function to define which mesh should cast a shadow. Something like the "canAffectMesh" of lights. Would it be possilbe to add something like this.

Link to comment
Share on other sites

Hi Kesshi, good to hear from you again.  Yes, you have some options, there.  Take a look... http://playground.babylonjs.com/#Y8WGP#3

See lines 55 and 56?  Almost exactly the same as your "canAffectMesh" hope.  Cool, huh?

Both lights are creating shadows, yet neither light is adding illumination to the torus.  Hope this helps for #1.

For #2... hmm.  There are few options, for that.  We have a tags system.  It would allow you to discriminate by name.  For example, all mesh whose name ends in "_shadowed"... could be quickly gathered with the tags system.  But you still need to do some processing. 

You could also add BABYLON.AbstractMesh.castsShadows = true/false (prior to any creation), but I don't do predicates real well, so you'll need to code that yourself.

Here's a little test.  http://playground.babylonjs.com/#Y8WGP#7

Line 25 - establish .castsShadows Boolean property on all future-made mesh.
Lines 51 and 55 - NOP (de-activated). No renderlist pushing, yet.  :)
Line 59 - set torus.castsShadows flag = true;
Lines 75 thru 83 - constantly update the shadow casters ... and add delicious CPU bog.  :)

Ok, that's all the ideas I have.  Others are much smarter than I... they will have comments.  Be well, talk soon.

PS: For the kids  :)  There is a slight red glow on the BLUE follow-spotlight cone.  It comes from scene ambientColor.  Two requirements... line 3 and line 32.  They work together... as a team.  Yay team!  Also, I "illegally over-powered" the blue channel on the light2 diffuse (line 23).  The brown terrain was sucking-up all the blue intensity.  I even tried light2.intensity = 50... it didn't work.  I want to BLAST that blue spotlight... but no... can't fig how to get more power from it...  yet.

Link to comment
Share on other sites

Thank you for your answers.
For #1: i'm sure that i tried the "light.excludedMeshes" already and it didn't work ... maybe i was sleeping at that time ;)
Anyway i think that will work. thx

For #2: I need to dig a bit more in the BJS source maybe i find some workaround for this.
If not i have to do something like in your example but maybe with some kind of delay to prevent updating in every frame.
I could also react on the scene.onNewMeshAdded / onMeshRemoved events i think.
 

Link to comment
Share on other sites

Nod.  But why have a onNewMeshAdded event... when YOU are the one adding the mesh?  Just set the shadow on/off when you create the mesh.  Even if some "foreign entity" (like a server) creates the mesh, just tell the server to set the mesh's shadow factor right afterwards.  You'll know when new mesh are added... because you are the one who does it, right?

Now... that other idea you had... hmm.  The LOD system has some sort of "monitor-for-distance" system inside it... but that is surely done once per frame, too, so it is the same as adding your own distance tester (and making sure built-in LOD is OFF).  I see an interesting line right here.  *shrug*  The framework is JS, and you are coding in JS.  Your code runs just as fast as things that are "built-in" to the framework.  So, there's a trade-off.  Sometimes it's wise to modify something engine-ish, and sometimes you lose ground by not writing it yourself.  Whether YOU run that distance-checker line once per frame, or the framework does it, both have load costs.

Shadow LOD... an interesting thought, Kesshi.  WebGL is predominantly light-less by definition, so, I don't think we'll see hardware-powered shadowLOD anytime soon. 

To be frank, I know so little about this, that I should just shut the heck up.  :)  Sorry if I've gotten in the way.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...