diff --git a/render/basic_lights_2d/example.md b/render/basic_lights_2d/example.md index b2c34698..d916182c 100644 --- a/render/basic_lights_2d/example.md +++ b/render/basic_lights_2d/example.md @@ -90,7 +90,7 @@ Passing `mtx_view` also keeps the material correct if the scene would later use The include declares the engine-owned light buffer and provides two helpers used here: - `ambient_light()` returns the accumulated Ambient Light contribution. -- `diffuse_lambert(normal, position)` evaluates the active Directional, Point, and Spot lights up to `MAX_LIGHT_COUNT`. +- `diffuse_lambert(normal, position, var_view)` evaluates the active Directional, Point, and Spot lights up to `MAX_LIGHT_COUNT`, using the view matrix to transform the lights into view space. Sprites have positions and texture coordinates, but no normal vertex attribute. This example treats every sprite as a flat surface facing positive Z diff --git a/render/basic_lights_2d/example/lit_sprite.fp b/render/basic_lights_2d/example/lit_sprite.fp index c2494975..970231c2 100644 --- a/render/basic_lights_2d/example/lit_sprite.fp +++ b/render/basic_lights_2d/example/lit_sprite.fp @@ -15,6 +15,6 @@ void main() { vec4 color = texture(texture_sampler, var_texcoord0); vec3 normal = normalize((var_view * vec4(0.0, 0.0, 1.0, 0.0)).xyz); - vec3 light = ambient_light() + diffuse_lambert(normal, var_position.xyz); + vec3 light = ambient_light() + diffuse_lambert(normal, var_position.xyz, var_view); out_fragColor = vec4(color.rgb * light, color.a); } diff --git a/render/directional_light_shadows/example/materials/directional_shadow_receiver.fp b/render/directional_light_shadows/example/materials/directional_shadow_receiver.fp index 4056e9a4..225345b5 100644 --- a/render/directional_light_shadows/example/materials/directional_shadow_receiver.fp +++ b/render/directional_light_shadows/example/materials/directional_shadow_receiver.fp @@ -4,7 +4,7 @@ in highp vec4 var_position; in mediump vec3 var_normal; in mediump vec2 var_texcoord0; -// Required by /builtins/materials/lighting.glsl. Its helper functions use this +// Passed to /builtins/materials/lighting.glsl. Its helper functions use this // matrix to transform light positions and directions from world to view space. in highp mat4 var_view; @@ -40,7 +40,7 @@ uniform fs_uniforms #include "/example/materials/shadows.glsl" -// Equivalent to Defold's diffuse_lambert(view_normal, view_position), +// Equivalent to Defold's diffuse_lambert(view_normal, view_position, var_view), // except that directional-light contributions are multiplied by shadow visibility. // Point and spot lights are not affected by this directional shadow map. vec3 shadowed_diffuse_lambert(vec3 view_normal, vec3 view_position) @@ -58,14 +58,14 @@ vec3 shadowed_diffuse_lambert(vec3 view_normal, vec3 view_position) } // Calculate the light contribution for the current light. - vec3 light_contribution = diffuse_lambert(i, view_normal, view_position); + vec3 light_contribution = diffuse_lambert(i, view_normal, view_position, var_view); // If the light is directional, calculate the shadow visibility. if (int(lights[i].params.x) == LIGHT_DIRECTIONAL) { // This is the same normalized direction convention used internally // by Defold's directional branch in diffuse_lambert(). - highp vec3 direction_to_light = -world_to_view_dir(lights[i].direction_range.xyz); + highp vec3 direction_to_light = -world_to_view_dir(lights[i].direction_range.xyz, var_view); // Calculate the shadow visibility for the current light. light_contribution *= directional_shadow_visibility(