View Full Version : how to get a lightSpaceMatrix?(make a shadow)

cl781121

07-11-2016, 06:15 PM

hi

i got white screen when draw,i think the reason is matrix wrong , but i cannot found it

please give me some advice thanks!!

here is code

glMatrixMode(GL_PROJECTION);

//glLoadIdentity();

//glOrtho(-10.0f, 10.0f, -10.0f, 10.0f, 1.0f, 7.5f);

gluPerspective(45,SHADOW_WIDTH/SHADOW_HEIGHT,1.0f,7.5f);

glGetFloatv(GL_PROJECTION_MATRIX, lightProjection);

glMatrixMode(GL_MODELVIEW);

//glLoadIdentity();

gluLookAt(lightPos.x(),lightPos.y(),lightPos.z(),0 .0f,0.0f,0.0f,0.0f,1.0f,0.0f);

glGetFloatv(GL_MODELVIEW_MATRIX, lightMatrix);

mgr->uploadMatrixData(getColorEffect(),"modelView",lightMatrix);

mgr->uploadMatrixData(getColorEffect(),"projection",lightProjection);

in glsl

layout (location = 0) in vec3 position;

uniform mat4 modelView;

uniform mat4 projection;

void main()

{

gl_Position = projection * modelView * vec4(position,1.0f);

}

i think （lightSpaceMatrix == projection * modelView ） is that right

thanks again

GClements

07-11-2016, 11:20 PM

i think （lightSpaceMatrix == projection * modelView ） is that right

Yes. But for a shadow map, there's no need to split the transformation into separate model-view and projection matrices then combine them. You can just apply all of the operations to a single matrix (the only reason for having separate model-view and projection matrices is that lighting calculations can't reasonably be performed in a projective space, so any perspective projection needs to be kept separate).

Note that if you're using the compatibility profile, there's no need to extract the fixed-function matrices with glGet() and upload them to user-defined uniforms. You can just use the compatibility uniforms gl_ModelViewMatrix and gl_ProjectionMatrix, or gl_ModelViewProjectionMatrix which contains their product. And if you aren't using the compatibility profile, the fixed-function matrix operations aren't available.

Beyond that, you should avoid using the fixed-function matrix operations in new code. Use GLM or write your own matrix functions. Extracting fixed-function matrices with glGet() shouldn't be used other than for debugging.

cl781121

07-12-2016, 05:39 PM

Yes. But for a shadow map, there's no need to split the transformation into separate model-view and projection matrices then combine them. You can just apply all of the operations to a single matrix (the only reason for having separate model-view and projection matrices is that lighting calculations can't reasonably be performed in a projective space, so any perspective projection needs to be kept separate).

Note that if you're using the compatibility profile, there's no need to extract the fixed-function matrices with glGet() and upload them to user-defined uniforms. You can just use the compatibility uniforms gl_ModelViewMatrix and gl_ProjectionMatrix, or gl_ModelViewProjectionMatrix which contains their product. And if you aren't using the compatibility profile, the fixed-function matrix operations aren't available.

Beyond that, you should avoid using the fixed-function matrix operations in new code. Use GLM or write your own matrix functions. Extracting fixed-function matrices with glGet() shouldn't be used other than for debugging.

hi GClements;

thank you for reply ,i am just start to learn opengl, my question is how to change glew to compatibity profile?

i got error : global variable gl_ModelViewMatrix is deprecated after version 120 when compile

thanks!!

GClements

07-13-2016, 12:44 AM

i got error : global variable gl_ModelViewMatrix is deprecated after version 120 when compile

The GLSL version and profile can be specified with a #version directive in the shader, e.g.

#version 150 compatibility

states that the shader uses GLSL 1.50, compatibility profile.

The OpenGL version and profile can be specified during context creation; the details depend upon the toolkit being used (GLUT, SDL, etc).

Powered by vBulletin® Version 4.2.5 Copyright © 2018 vBulletin Solutions Inc. All rights reserved.