0
\$\begingroup\$

I'm developing a puzzle with a ball with cracks on it. Inside the ball there's a point light. Its light rays come out of the cracks and hit some platforms (walls/ceiling/floor).

To solve the puzzle the player must rotate the ball to match the light coming out of the cracks with some pre-lit pattern on the platforms.

I don't know how to do the pre-lit pattern. I don't want it to be manually done using a texture editing tool like Photoshop or GIMP. I remembered this could probably be done using light baking. I think what I need is to bake the light from only that point light into a lightmap and use it only on those platforms, but don't know how to do that.

Can someone help me with a solution?

\$\endgroup\$
5
  • 1
    \$\begingroup\$ Have you considered keeping a second point light in your scene, shadowed by an invisible copy of your ball at the desired orientation? \$\endgroup\$
    – DMGregory
    Commented Apr 11, 2019 at 1:02
  • \$\begingroup\$ @DMGregory Thank you very much for your comment. I followed your advice (or at least what I understood from it!) and did the following: - Set all the platforms where I want the prebaked light pattern to 'Lightmap static' - Duplicated both the original light object and occluder object (ball), set them to static, set the Light's Mode to 'Baked' and the Ball's Cast Shadows to 'Shadows only'. Was this your suggestion? This works but the baked occluder blocks the light from the original light. I can write a script to disable it on Start and it solves this. Is there a better aproach? \$\endgroup\$ Commented Apr 11, 2019 at 18:06
  • 1
    \$\begingroup\$ I did not say anything about baking — you can do this wholly at runtime if you prefer. Did you try using layers/culling masks to ensure the occluder does not block the original light? \$\endgroup\$
    – DMGregory
    Commented Apr 11, 2019 at 18:10
  • \$\begingroup\$ @DMGregory Oh sorry, I misinterpreted! I just tried messing with the layer culling and it worked (no scripts required!). About baking, yes I would rather not bake it since it's a hassle to keep track of static objects and so forth. Can you elaborate your initial suggestion? Was it only duplicating the objects and adjusting the layer culling of both? About the 'invisible copy of the ball', did you had in mind making it 'Shadows only' or another method? \$\endgroup\$ Commented Apr 11, 2019 at 18:24
  • \$\begingroup\$ It sounds like you have everything you need for a solution. Anything you're missing? If not, you can just post your solution as an answer. \$\endgroup\$
    – DMGregory
    Commented Apr 11, 2019 at 19:44

1 Answer 1

1
\$\begingroup\$

I've managed to implement two solutions for my problem.

  1. Light baking
    I set all surfaces where the light pattern was needed to 'Lightmap static'.
    Then, duplicated both the point light and the ball with cracks (occluder), set them to 'static', set the light's 'Mode' to 'Baked' and the ball's 'Cast Shadows' to 'Shadows Only' (makes the mesh invisible but keeps its occluder properties).
    To avoid the duplicate occluder to occlude the original light, I created a new Layer 'ShadowsOnly', set the duplicate occluder's layer to it and removed this layer from the original light's 'Culling Mask' (this will let the light from the original light to ignore the duplicate occluder).

  2. Layer culling
    I duplicated the light and occluder.
    Set 'Cast Shadows' on the duplicate occluder to 'Shadows Only'.
    Created a new layer 'ShadowsOnly' and 'Surfaces'.
    Applied 'Surfaces' to my surfaces and 'ShadowsOnly' to the duplicate occluder.
    Next, removed 'ShadowsOnly' from the 'Culling Mask' of the original light and set the duplicate light's to 'ShadowsOnly' + 'Surfaces' (makes the duplicate light only hit its occluder and the surfaces).

Both solutions worked for me and have some advantages and disadvantages over the other:

  • The first (light baking) will guarantee a better performance since it's precomputed, unlike the second (layer culling) which is realtime.
  • The second is easier to implement, understand, maintain and modify.

I would like to thank @DMGregory for the amazing help on the comments. Without him, I probably would've never done this. I hope this helps someone else too!

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .