Howdy yall! I’m trying to make a directional lighting to be affected by the perspective/camera. Thing is, it seems that in the editor i get the desired result, but in-game its much darker:
Heres how it should look like, using lovr:
Could i be doing something wrong? I sorta used the default model material as a guide, tho i couldnt replicate it perfectly with a directional light, i tinkered with it until i made it be affected by the camera. Although it shoots straight from the camera and not at an angle as it should:
uniform mediump mat4 mtx_worldview;
uniform mediump mat4 mtx_view;
uniform mediump mat4 mtx_proj;
uniform mediump mat4 mtx_normal;
uniform highp sampler2D gradient_map;
attribute mediump vec4 position;
attribute mediump vec2 texcoord0;
attribute mediump vec3 normal;
attribute mediump float uv_factor;
attribute mediump vec3 light_direction;
varying mediump vec3 mapped_light;
void main()
{
vec3 L = -vec3(normalize(mtx_view * vec4(normalize(light_direction), 1.0)));
vec3 N = vec3(normalize(mtx_normal * vec4(normalize(normal), 1.0)));
float light_factor = .5 + dot(N, L) * .5;
mapped_light = vec3(texture(gradient_map, vec2(texcoord0.x, light_factor)));
gl_Position = mtx_proj * mtx_worldview * vec4(position.xyz, 1.0);
}
i figured it was obvious that i needed the direction in view space, but the normals i wasnt sure what to do to make it work. The normal matrix makes it relative to the camera but it shoots straight from the camera like i said (im still not sure what this normal matrix is supposed to be used for). Any help is greatly appreciated!