Light and Shadows example

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

5 Likes

Thanks for sharing! Looks lovely!

3 Likes

Another example how you can use this opensource lib:

20 Likes

it looks great!

2 Likes

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

16 Likes

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

2 Likes

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!

4 Likes

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

5 Likes

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 https://github.com/Dragosha/defold-light-and-shadows/blob/e8222cdee81fdb0d839b0e45d58e7fa04a5b0a47/light_and_shadows/light_and_shadows.lua#L46 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!

6 Likes

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: https://github.com/Dragosha/defold-light-and-shadows/blob/e8222cdee81fdb0d839b0e45d58e7fa04a5b0a47/light_and_shadows/materials/sprite/sprite.fp#L149

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

2 Likes

Ok, it’s working better now, this is vulkan:

I copied the varying specification from the vertex shader to the fragment shader. So now I just need to figure out if we can catch this early, or avoid it happening. Thanks for the report!

5 Likes

There are some build errors for simple_input.lua
Line 56: registered_node[node] = nil
‘Undefined global registered_node’
These don’t stop it ‘working’ though, so I guess it is no big deal.
(tag: v0.4.0,e8222cd)

1 Like

yep, should be ‘registered_nodes’, I’ve fixed this typo mistake. Thanks.

4 Likes