Jump to content

Light a Mesh From All Sides


jangerhofer
 Share

Recommended Posts

I am trying to create a representation of an LED (i.e. light bulb) which emits light of varying colors in all directions. Additionally, it must do so independently of other LEDs on the canvas such that each diode can have its own color.

When I first found Babylon, I thought it was logical to simple use a PointLight -- an LED is just a point which emits light -- however it seems to me that a mesh must reflect the light in order for it to be visible. Working under that assumption, I have tried to light a sphere with a DirectionalLightand a HemisphericLight, but neither lights one a single sphere while lighting every surface of the sphere.

Is there an easy solution here or do I need to put multiple lights of some kind on each "bulb"?

Link to comment
Share on other sites

You can add a pointlight to 'emit' the light, and set the emisiveColor of the material of the bulb to the same color.

var light = new BABYLON.PointLight(....);
light.diffuse = BABYLON.Color3.Green();
light.position.copyFrom(bulb.position);
bulb.material = new BABYLON.StandardMaterial('LED', scene);
bulb.material.emissiveColor = BABYLON.Color3.Green() ; // If your light is green

Not tested, but it should work :)

Link to comment
Share on other sites

Hiya @jangerhofer, welcome to the forum.  Hi Temechon, too.

led.material.emissiveColor = [some Color3]  ... that will make the "bulb" evenly-lit, even without any lights.  You can think of it as SELF-illumination but... it is NOT a light, so it cannot add light to other mesh or materials, and cannot be used as a source light in a shadowGenerator.  But still, it's pretty handy.

I once made a LiteBrite demo.  http://www.babylonjs-playground.com/#18TRYT#29

It looks pretty good.  Want to tour it with me?  I knew you did.  :)

Lines 11-37 are the makeLight func... pretty important.  See lines 17-23?  I once tried to put a REAL pointLight inside each bulb.  But there were problems with that.  The black backboard would lose its material and become see-thru... IF # of lights exceeded ~7 in Firefox, or exceeded ~82 in IE.  An issue with shader, and Deltakosh was kind enough to submit a FF bug report FOR ME.  What a guy!

Still, there are some limitations that make it implausible to... well... make real-acting xmas light strings.  :) (where each bulb can cast light and make shadows, important in xmas tree apps)  So, pointLight-adding code is remarked-out.

In lines 39-50, I create a "highLightLayer" which is a post-processing "effect".  That causes a "glow" around the bulbs that ALMOST makes it appear that the lights are illuminating an area of the back-board.  They are not, of course.  They are not lights.   :)  Still, the effect works ok.  In line 35, you can see each bulb get added to the highLight layer.

Lines 64-98 is the sign maker.  I'll let you run-with-it from here.  Feel free to make edits, make more saves, you can't hurt anything by playing with the playground or its demos.  Use this code for yourself, it is free to use in ANY way.  With emissiveColor and perhaps some highLightLayer... you can make some viable LED's.

Line 14:  You may now use...  color = BABYLON.Color3.Random();   ...if you wish.  :)

Write back, as wanted, of course.  Party on!

Link to comment
Share on other sites

Howdy?  Thank you both for the pointer to emissiveColor!!  It provides exactly the effect I wanted.  I suppose I got hung up on wanting a LIGHT and didn't read the docs for materials.  

@Wingnut: that's super cool!  The glow effect is particularly impressive.  Like your demo, I'm planning to arrange my "LEDs" into a grid so I will undoubtedly refer back to your matrix-loop in the sign maker.

In case anyone happens upon this thread in the future... I made a quick demo that is not nearly as impressive as your PG, but is slightly less complex.

Many thanks, once more, to you both!  I would not have found this property on my own.

 

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...