opengl - Keeping the sun in the same position -
i drawing circle in opengl using simple circle drawing shader draws circle around point passed in. point needs in screen space coordinates i,e, 1 -1 in x , y.
the problem circle drawn doesn't stay in same position real sun would, seems on rotate compared other objects in scene. due moving out of sync skybox.
the matrix passed skybox is:
m_activecamera.m_projectionmatrix * m_activecamera.m_viewmatrix * glm::translate(mat4(1.0), m_activecamera.m_position)); the calculation light sun position far:
vec4 returnpos = pos; returnpos.w = 1.0f; returnpos = projection * (view * returnpos); return vec2(returnpos.x / returnpos.w, returnpos.y / returnpos.w); the position passed in function (pos) is:
sun.position + m_activecamera.position the view , projection matrix belong m_activecamera.
pictures explain issue:
if move camera left right sun stays in place, relative sky box.
if rotate camera sun moves out of place skybox.
the problem "getndccoords" function returning point between -1 , 1 in x , y if sun on screen of course. function draws circle needs position in screen space 0 1. solved simple formula:
screenpos.x = ndc.x * 0.5 + 0.5; screenpos.y = ndc.y * 0.5 + 0.5; now sun stays fixed in place.



Comments
Post a Comment