Light and Shadows example

As part of the ongoing jam, I prepared an asset that includes a pack of shaders, materials and scripts for creating a 3D/2.5D game with shadows and light.

And here it is:

Html5 demo: Light and Shadows 0.3

  • Press and hold left mouse button to move the camera.
  • Click on coins to collect them.
  • Works on mobile as well.

Really good! Can’t wait to see what devs do with this. :star_struck:


Such beautiful lights and shadows - stunning work! Thank you so much for sharing this with us :smiling_face_with_three_hearts:


Having this available opens up a whole niche of an artstyle subgenre for devs, this is awesome!


Thanks for sharing! Looks lovely!


Another example how you can use this opensource lib:


it looks great!


Kinematic walker by @astrochili + Light and shadows by me is here:


This is sooo cool! :heart_eyes: Thank you so much for sharing! :heart:


Awesome! Making these kinds of features accessible to the community is so important!

I’d like to see someone implement 3D sound with something like FMOD next!


Just a note, seems like this might be broken in Defold 1.6.4 - Console comes up with hundreds of ‘tex1 cannot be empty’ for each of the game objects. Setting it to anything that exists (builtin/particle blob) does seem to work though, not sure of the side effects of doing so.

Maybe similar to the issue in Illumination — Ready-to-use forward shading lighting for 3D games - #27 by astrochili

Definitely a great example and many thanks for sharing!

There are no any side effects. The second texture sampler remapped in a render script to a shadowmap render target, so no matter what the field contains in the editor.

btw the example updated to supporting Defold v 1.7.0


Appreciate the explanation and update, I can see now where the custom render script runs.

Still getting used to the render pipeline but this example helps a great deal.

I would like to use this lib with Vulkan(for metal on macos) but it fails. It seems like a shader problem( user(locn2)) but can’t understand it. Any idea why?

[mvk-error] VK_ERROR_INITIALIZATION_FAILED: Render pipeline compile failed (Error code 3):
Fragment input(s) `user(locn2)` mismatching vertex shader output type(s) or not written by vertex shader.
ERROR:GRAPHICS: Vulkan Error (../src/vulkan/graphics_vulkan.cpp:1540) VK_ERROR_INITIALIZATION_FAILED
Assertion failed: (0), function GetOrCreatePipeline, file graphics_vulkan.cpp, line 1540.

Edit: I guess it is related to sprite tex1 on fp

[mvk-error] VK_ERROR_INITIALIZATION_FAILED: Shader library compile failed (Error code 3):
program_source:103:165: error: cannot reserve 'texture' resource location at index 0
fragment main0_out main0(main0_in in [[stage_in]], constant _DMENGINE_GENERATED_UB_FS_0& _130 [[buffer(0)]], texture2d<float> tex1 [[texture(0)]], texture2d<float> tex0 [[texture(0)]], sampler tex1Smplr [[sampler(0)]], sampler tex0Smplr [[sampler(0)]])
program_source:103:228: error: cannot reserve 'sampler' resource location at index 0
fragment main0_out main0(main0_in in [[stage_in]], constant _DMENGINE_GENERATED_UB_FS_0& _130 [[buffer(0)]], texture2d<float> tex1 [[texture(0)]], texture2d<float> tex0 [[texture(0)]], sampler tex1Smplr [[sampler(0)]], sampler tex0Smplr [[sampler(0)]])

Edit: It works without fog lines on fp but not as expected. Shaders with Vulkan cause issues like flickering and misplacement.

    // Fog
    // float dist = abs(var_view_pos.z);
    // float fog_max = fog.y;
    // float fog_min = fog.x;
    // float fog_factor = clamp((fog_max - dist) / (fog_max - fog_min) + fog_color.a, 0.0, 1.0 );
    // frag_color = mix(fog_color.rgb, frag_color, fog_factor);

Which Defold version do you use? If version before 1.7 please try previous example release or uncomment this line and comment next line instead.

I’m using 1.7.
flickering happens when using @jhonny.goransson 's examples with Vulkan too. I solve the issue on his libs by using local vertex space for static(without skeleton or animation) models. But of course I have no idea about the actual issue here.

I found (and fixed) a flickering issue with vulkan when using render targets this week. Let me take a look at this example as well and make sure it works :+1: my plan is to make vulkan the default renderer for osx very soon, so I need to squash every bug I can find!


Which shader did you change that contains these lines, all of them?

I clean up the project for better understanding the issue, just tested with ‘one’ sprite so I changed this one:

Cheers, I have something small to work with now. It’s definitely something wrong with the shaders, but I need to make it a bit more robust - it should work the same as opengl