# Light and Shadows example

**URL:** <https://forum.defold.com/t/light-and-shadows-example/71713>\
**Category:** The Defoldmine\
**Created:** [September 23, 2022, 5:48pm UTC](https://forum.defold.com/t/light-and-shadows-example/71713 "2022-09-23T17:48:01Z")\
**Posts on this page:** 9\
**Page:** 4

<div class="post-metadata">

**Author:** ![jhonny.goransson](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/jhonny.goransson/32/3864_2.png) [@jhonny.goransson](https://forum.defold.com/u/jhonny.goransson)\
**Post date:** [March 18, 2026, 6:30pm UTC](https://forum.defold.com/t/light-and-shadows-example/71713/61 "2026-03-18T18:30:50Z")

</div>

Glad to see it works!

---

<div class="post-metadata">

**Author:** ![gameoffate2018](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/gameoffate2018/32/20065_2.png) [@gameoffate2018](https://forum.defold.com/u/gameoffate2018)\
**Post date:** [April 11, 2026, 11:30pm UTC](https://forum.defold.com/t/light-and-shadows-example/71713/62 "2026-04-11T23:30:31Z")

</div>

Really cool demo! I’ve been messing around with lights and shadows for one of my projects.

I noticed in tiny\_world 0.1 you managed to have transparent water, I’m trying to make models fade out when the character walks into a new room.

I’ve tried using the tint.w but that just turns the models black:

After that I tried changing to the model\_alpha\_blend tag which seems to work better but it results in some strange artifacts:

How did you get the water transparency working? Is that something I need to change in the fragment program / render script?

---

<div class="post-metadata">

**Author:** ![Dragosha](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/dragosha/32/5103_2.png) [@Dragosha](https://forum.defold.com/u/Dragosha)\
**Post date:** [April 23, 2026, 10:48am UTC](https://forum.defold.com/t/light-and-shadows-example/71713/63 "2026-04-23T10:48:40Z")

</div>

Creating transparency in 3D is never easy.

In your case, for the wall model that needs to be made transparent, you need to apply a material that will be rendered after the rest of the scene. But you must take the depth buffer into account. Before calling `render.draw`, you need to enable blending using the command `render.enable_state(graphics.STATE_BLEND)`.

In the first video, your wall has blending disabled (it is disabled by default for 3D), and reducing its alpha via `tint.w` results in a black color.

In the second video, invisible edges are “showing through.” You need to remove the instruction `render.set_depth_mask(false)` before `render.draw(predicates.model_alpha_blend, draw_options_world)` in the render script.

P.S. I finally managed to access the forum; that’s why my reply was delayed (the internet is heavily blocked here, and I can’t access some resources even with a VPN).

---

<div class="post-metadata">

**Author:** ![Dragosha](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/dragosha/32/5103_2.png) [@Dragosha](https://forum.defold.com/u/Dragosha)\
**Post date:** [April 24, 2026, 4:43am UTC](https://forum.defold.com/t/light-and-shadows-example/71713/64 "2026-04-24T04:43:15Z")

</div>

- Added model **blend** material
- Removed COLLADA .dae files (prepare for the new Defold version 1.13)
- Billboard particles shader updated

---

<div class="post-metadata">

**Author:** ![Dylan\_Mines](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/dylan_mines/32/32092_2.png) [@Dylan\_Mines](https://forum.defold.com/u/Dylan_Mines)\
**Post date:** [April 28, 2026, 3:26pm UTC](https://forum.defold.com/t/light-and-shadows-example/71713/65 "2026-04-28T15:26:52Z")

</div>

I’m having trouble getting the fog of war module to work correctly. I’ve setup my project as a tilemap and a model using tilemap-to-3d. Both are using the materials from the fog-of-war branch of the repository. sceneManager sets up the fow.lua module with the map. The only different between my project and the example is that my world is setup on the XY plane instead of XZ plane. I did this so I could use 2D physics to make the player collide with the tilemap, as opposed to generating a collision shape with the generated mesh. The minimap works just fine and shows the player along with revealing parts of the map when the player goes near.

 ![Screenshot From 2026-04-28 09-21-19](https://forum-defold-uploads.b-cdn.net/original/3X/f/9/f9ed0e4da0387976f563c8a77d2453f9ca97f7ce.png)

 ![image](https://forum-defold-uploads.b-cdn.net/original/3X/1/8/1863f1883a0da51401647ce880364cd7187a0660.png)

---

<div class="post-metadata">

**Author:** ![Dylan\_Mines](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/dylan_mines/32/32092_2.png) [@Dylan\_Mines](https://forum.defold.com/u/Dylan_Mines)\
**Post date:** [April 28, 2026, 3:28pm UTC](https://forum.defold.com/t/light-and-shadows-example/71713/66 "2026-04-28T15:28:12Z")

</div>

Here’s a video of my project in action. (The chess pattern is different and works fine but video compression kinda borked it)

---

<div class="post-metadata">

**Author:** ![Dragosha](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/dragosha/32/5103_2.png) [@Dragosha](https://forum.defold.com/u/Dragosha)\
**Post date:** [May 13, 2026, 3:35pm UTC](https://forum.defold.com/t/light-and-shadows-example/71713/67 "2026-05-13T15:35:28Z")

</div>

> [@Dylan\_Mines](#):
>
> The only different between my project and the example is that my world is setup on the XY plane instead of XZ plane.

I’m not sure if a reply is still needed. But I’d guess that changing Z to Y [here](https://github.com/Dragosha/defold-light-and-shadows/blob/fog_of_war/examples/fow/materials/fog%20_of_%20war/model_fow.fp#L68) should do the trick: `var_position.z -> var_position.y`

And conversely, changing Y to Z [here](https://github.com/Dragosha/defold-light-and-shadows/blob/fog_of_war/examples/fow/materials/fog%20_of_%20war/model_fow.fp#L97).

---

<div class="post-metadata">

**Author:** ![Dragosha](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/dragosha/32/5103_2.png) [@Dragosha](https://forum.defold.com/u/Dragosha)\
**Post date:** [July 18, 2026, 5:13pm UTC](https://forum.defold.com/t/light-and-shadows-example/71713/68 "2026-07-18T17:13:38Z")

</div>

**v0.9**

- In shaders that use light and shadow, the code has been moved to an include file
- Shadow intensity has been changed (multiplication instead of subtraction); your project may require adjustments to shadow intensity (see the `sun` object)
- The “fog of war” example has been merged into the main branch of the repository
- The [demo](https://dragosha.com/defold/Light_and_Shadows/) has been updated

 ![Снимок экрана 2026-07-18 220111](https://forum-defold-uploads.b-cdn.net/original/3X/6/f/6f151a96ad545c528ea823ebf0fd9872b336d226.jpeg)

---

<div class="post-metadata">

**Author:** ![Dragosha](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/dragosha/32/5103_2.png) [@Dragosha](https://forum.defold.com/u/Dragosha)\
**Post date:** [October 5, 2026, 8:23am UTC](https://forum.defold.com/t/light-and-shadows-example/71713/69 "2026-10-05T08:23:49Z")

</div>

It seemed like the two weeks set aside for the game jam were plenty of time. And I was sure I’d have time to make something interesting. In the end, with just a few days left before the deadline, I started frantically putting together something resembling a mini-game using the new `bullet3d API`. I managed to get the basic framework of the mini-game done, so now I can take my time filling it with levels. And I finally got to use my own _Light and Shadows_ library in the project 😂

My entry for the Defold Game Jam 2026:

> **[Headless by dragosha](https://dragosha.itch.io/headless)**
>
> Put the skeleton's head back on.

[Previous page](https://forum.defold.com/t/light-and-shadows-example/71713.md?page=3)
