Light and Shadows example

Glad to see it works!

6 Likes

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?

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

7 Likes

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

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.

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

1 Like

I’m not sure if a reply is still needed. But I’d guess that changing Z to Y here should do the trick: var_position.z -> var_position.y

And conversely, changing Y to Z here.

1 Like

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 has been updated

13 Likes