GLVisualize.jl icon indicating copy to clipboard operation
GLVisualize.jl copied to clipboard

Light is given in model space and not in eye space in standard mesh rendering

Open TsurHerman opened this issue 8 years ago • 1 comments

Hi Simon, in util.vert function render

void render(vec3 vertex, vec3 normal, mat4 viewmodel, mat4 projection, vec3 light[4])
{
    vec4 position_camspace = viewmodel * vec4(vertex,  1);
    // normal in world space
    o_normal               = normal;
    // direction to light
    o_lightdir             = normalize(light[3] - vertex);
    // direction to camera
    o_vertex               = -position_camspace.xyz;
    // screen space coordinates of the vertex
    gl_Position            = projection * position_camspace;
}

which is used for the standard mesh rendering, the light position is relative to the vertex which is in model space , it should be relative to ~~model*vertex (world space)~~ the position in camspace

~~I would issue a PR but in entails changing the signature of render , which in turn would cause a wide change in the various calls to render.~~

TsurHerman avatar Jul 25 '17 18:07 TsurHerman

A quick run through some openGL tutorials reveals that the convention is that light position is given in eye (Camera) space. therefore it is easy to issue a PR , I am on it.

TsurHerman avatar Jul 25 '17 18:07 TsurHerman