Normal map lighting for 2D Pixel Art sprites

The issue is clearly visible - direction of light is somehow always “pointing” to/from the left bottom center. How could I make it point from viewers point of view (middle of screen, with Z around 100)? To make circular like light, like I would be pointing with a flashlight where I click? :flashlight: :sweat_smile:

// Get Light Direction
lowp vec3 light_dir = normalize(point_light_pos.xyz - var_world_coord0.xyz);

Where position of mouse point_light_pos is set from script:

function on_input(self, action_id, action) 
    if action.released then
	    msg.post("@render:", "set_point_light", {pos = vmath.vector4(action.screen_x, action.screen_y, 100,0)})
    end
end

Vertex program of the sprites defines var_world_coord0 as in default sprite material:

void main()
{
    gl_Position = view_proj * vec4(position.xyz, 1.0);
    var_texcoord0 = texcoord0;
    var_world_coord0 = position.xyz;
}

Phong_Lighting_dIRECTION

Gif is banding colours, tomorrow I will record mp4.

11 Likes