Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion render/basic_lights_2d/example.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion render/basic_lights_2d/example/lit_sprite.fp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)
Expand All @@ -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(
Expand Down
Loading