java - GLSL Moving Point Light -
i have been writing point light shader lwjgl + java application. writing based off of this tutorial. problem when "walk around" camera, light moves well. also, when rotate sphere, light rotates it.
believe problem in vertex shader, put fragment shader in in case.
example 1 (no movement)
example 2 (moved left , rotated camera)
vertex shader
#version 330 in vec4 in_position; in vec3 in_normal; in vec2 in_texturecoord; uniform mat4 projection; uniform mat4 view; uniform mat4 model; uniform mat3 normal; uniform vec4 light_pos; //set 0, 3, 0, 1 out data { vec3 normal; vec3 eye; vec3 ldir; vec2 st; } out; void main(void) { vec4 vert = view * model * light_pos; vec4 pos = model * view * in_position; out.normal = normalize(in_normal); out.ldir = vec3(vert - pos); out.eye = vec3(-pos); out.st = in_texturecoord; gl_position = projection * view * model * in_position; }
fragment shader
#version 330 uniform sampler2d texture_diffuse; in data { vec3 normal; vec3 eye; vec3 ldir; vec2 st; } in; out vec4 color; void main(void) { vec4 diffuse = texture(texture_diffuse, in.st); vec4 spec = vec4(0.0); vec3 n = normalize(in.normal); vec3 l = normalize(in.ldir); vec3 e = normalize(in.eye); float = max(dot(n,l), 0.0); if (i > 0.0) { vec3 h = normalize(l+e); float intspec = max(dot(h,n), 0.0); spec = vec4(1) * pow(intspec, 50); //50 shininess } color = max(i * diffuse + spec, vec4(0.2)); }
tried solution presented in this question, did not solve problem.
just quick glance, looks you're multiplying light's position view , model matrix:
vec4 vert = view * model * light_pos;
this means whenever walk around/move camera you're changing view matrix affects light's position, , likewise when move sphere you're changing model matrix affects light's position.
in other words if want light stationary in relation world don't transform matrices.
Comments
Post a Comment