Jump to content

Spotlights and Cookies in Unity


Recommended Posts

I'm currently developing a series of docking ports with toggleable built-in lights.

So far, I've set up the emissives that would make the lights appear to glow, but I'm also interested in setting up actual light entities to illuminate nearby parts.

1) What sort of settings do folks like Lack of LLL and bac9 of B9 Aerospace use in Unity? I presume it's the Spot light option, but I'm interested in knowing what ranges/spot angles/intensities they use.

2) Also, since my illuminators are depicted as 3 x 5 banks of red/white Jumbo LEDs as per my attached image (currently lacking a normal map), I've been thinking about using Spot Light Cookies to give the effect of the individual LEDs. Anyone have any experience working with these?

ksp_fustek_iacbm_1_25m_wip_21_aug_2013_by_sumghai-d6j2nk2.png

Edited by sumghai
Solved
Link to comment
Share on other sites

Looking good so far sumghai!

Regarding your question towards settings and intensities, etc. I would suggest you to simply download some lighting related mods (like the ones you listed), and take a look in the source files which should be freely available in any of them. From them, you can propably get almost everything you need, just adapt the code and use it for your needs (at least I can give you the permission regarding my source files).

Greetings,

BigNose

Link to comment
Share on other sites

Regarding your question towards settings and intensities, etc. I would suggest you to simply download some lighting related mods (like the ones you listed), and take a look in the source files which should be freely available in any of them. From them, you can propably get almost everything you need, just adapt the code and use it for your needs (at least I can give you the permission regarding my source files).

Unfortunately, the range and intensity values are hard-coded into the MU model files exported out of Unity - the CFGs only specify animation names. Also, the source code you've provided is for a custom plugin-based solution rather than standard stock light behaviour. With a few exceptions, I'd rather my project not be too dependent on third-party plugins.

That being said, I've picked up some choice tips from Artyom (Bac9), which mostly answers my question. I'll be making a separate post with this info right after this, so that hoojiwana can directly link to it without the superfluous text.

Link to comment
Share on other sites

1) Light objects are NOT the same thing as emissive textures

The former will actually cast real light and shadows onto faces/parts within its range, whilst the latter simply makes part of the texture glow without illuminating anything else nearby.

Therefore, an authentic-looking illumination lamp requires a combination of both.

2) Avoid making lights too bright

Shaders in KSP are twice as bright as stock Unity shaders, so its is strongly recommended that directional light intensity should not exceed 0.5 (otherwise, nearby illuminated parts would get washed out in glowing white fills).

3) Light decay with distance is non-linear

Real light sources (mostly) follow the Inverse-Square Law, which states that the intensity of the light is inversely proportional to the square of the distance from the light source. In layman's terms, this means that if you double your distance from the light, the intensity at that position is 1/4 of that at the light source itself; if you triple your distance, the intensity drops further to 1/9, and so forth.

Unity does a fairly reasonable job of emulating this behaviour, so when developing illuminators to cover a distance such as headlights, it is wise to select an intensity value that is still visible at the furthest of your design range, but not so bright as to white-out anything closer. Bac9 suggests using standard Unity cubes and spheres positioned at regular intervals to help calibrate light intensity/range settings.

4) Sample recommended settings in Unity

Point (Omnidirectional) Lights

The light rays are cast out in all directions from a single point, much like a sphere.

Intensities of up to 5.0 work well for short (1~2 m) range omni lights, such as navigation lights

0.5~1.0 are preferred for longer (5~15 m) range omni lights.

Spot Lights

The light rays are cast out within a fixed angle cone

Cone angles of 20~30 degrees are suited to focused long-range beams, while close-range illuminators work best with 45 degree cones

5) KSP ModuleLight configuration

MODULE
{
name = ModuleLight
lightName = someLight // name of actual light object in Unity (multiple ones can be separated by commas e.g. someLight1, someLight2)
useAnimationDim = true // not sure what this is
lightBrightenSpeed = 1 // Higher values means faster speed
lightDimSpeed = 1 // Ditto
resourceAmount = 0.01 // How much ElectricCharge to consume per second
animationName = someAnimation /// name of animation in Unity that controls lights (may include emissives)
useResources = true // specify if light should consume ElectricCharge
}

6) Making lights toggleable (and not glowing all the time or even at the start/VAB/SPH)

There may be other, more efficient ways of doing this, but for me:

- The light objects themselves in Unity have their ranges and intensities defined to desired values

- The initial color, however, is black (no light)

- In the Animation timeline, I add Keyframes to actually change the RGB values of these light objects

- I then reference this animation as per 5) above

7) KSP (currently) does not support light cookies

Light cookies are essentially texture masks for light sources - this would allow for grille effects on lights, or using a single light transform to emulate multiple sets of lights pointing in the same direction.

Unfortunately, as of KSP 0.23.5, the corresponding KSP PartTools 0.23 does not export light cookie textures required for this effect to work.

Special thanks to Artyom (Bac9) for many of these pointers.

Edited by sumghai
Added info about KSP not supporting light cookies
Link to comment
Share on other sites

  • 2 weeks later...
  • 5 months later...
  • 4 months later...
any final word on using light cookies? I tried with spotlights and it doesnt' seem like cookie maps settings stick once in KSP.

Light cookies definitely don't work in KSP 0.23.5 :(

KSP PartTools 0.23 does not export the cookie textures required for the desired effect.

Link to comment
Share on other sites

  • 2 months later...
6) Making lights toggleable (and not glowing all the time or even at the start/VAB/SPH)

There may be other, more efficient ways of doing this, but for me:

- The light objects themselves in Unity have their ranges and intensities defined to desired values

- The initial color, however, is black (no light)

- In the Animation timeline, I add Keyframes to actually change the RGB values of these light objects

- I then reference this animation as per 5) above

Just wanna say that if you use RGB (color) keyframes in animating the light toggling, the color tweaking won't work but if you want it to work, using intensity instead will do. Works with me.

Link to comment
Share on other sites

  • 2 weeks later...

Thanks to everyone above for the help already; can anyone help with setting up the color of the emissive texture on the lamp "bulb" change color in accordance with the color of the light itself? Tweaking the RGB values in VAB changes the light just fine but I'm unable to figure out how to make it so the "bulb" itself changes color as well.

Link to comment
Share on other sites

Wow, you're totally correct! Not sure why I was under the impression that the stock headlights emissive textures changed color along with the light beam itself! Thanks for making me take another look before beating my head against this further!

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

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.

×
×
  • Create New...