• 9
• 9
• 11
• 12
• 9

# Shadowmapping with Large terrains part 2

This topic is 4325 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have my frustum drawn out now so I can see whats going on. I now have noticed that the FOV for sure affects the IQ of my shadows. So I am trying to move my shadowmaps frustum around to to follow my camera, but having no luck with that... I noticed if I move it moves in the opposite direction? I think if I can follow my camera's view around I may have solved the issue with the shadows looking like crap on large terrain areas. Thanks for any help. part 1 thread http://www.gamedev.net/community/forums/topic.asp?topic_id=387857

##### Share on other sites
is the sm cast from the sun?
if so then u shouldnt be using a perspective frustum but a orthogonal one

##### Share on other sites
Quote:
 Original post by zedzeekis the sm cast from the sun?if so then u shouldnt be using a perspective frustum but a orthogonal one

Hey Zed, yeah it's from the sun POV. Changing to a Orthogonal frustum still isn't going to follow my camera around... And if it does I guess I don't understand how. Thanks

##### Share on other sites
Hi MARS_999,

How do you calculate the mvp for the light?
Suppose it's a spot light with a pespective projection, maybe this will help:

Vec3 sunDir; // You should already have that.Vec3 camPos; // This too...Vec3 camDir; // This too...// Calculate a point in front of the cameraVec3 pointInFrontOfCam = camPos + camDir * offset;// From that and from the sun direction calculate sun's positionVec3 sunPos = pointInFrontOfCam - sunDir * sunDistance;// Setup a lookat matrix using this position...gluLookAt(sunPos.x, sunPos.y, sunPos.z, pointInFrontOfCam.x, pointInFrontOfCam.y, pointInFrontOfCam.z, 0.0f, 1.0f, 0.0f);

Have you tried that? What happens?
I haven't read your old thread, so sorry if this is completely irrelevant, but you said you are trying to make the frustum follow the camera, so i think this will do it.

Hope that helps.

HellRaiZer

##### Share on other sites
Quote:
 Original post by HellRaiZerHi MARS_999,How do you calculate the mvp for the light?Suppose it's a spot light with a pespective projection, maybe this will help:*** Source Snippet Removed ***Have you tried that? What happens? I haven't read your old thread, so sorry if this is completely irrelevant, but you said you are trying to make the frustum follow the camera, so i think this will do it.Hope that helps.HellRaiZer

Hey HellRaiZer, been awhile! It's a directional light with a perspective projection I am using... I am trying to allow my shadowmaps frustum follow me around the terrain. I am trying to move it around by giving my glTranslatef() xyz values to follow me around. Thanks

##### Share on other sites
Are you saying that you set your light looking at the origin and then you translate the frustum to the camera's position?
How are you doing that?

I think (if i understood it correctly) you are doing something like this:

void UpdateShadowmap(){  glMatrixMode(GL_PROJECTION);  glLoadMatrix(Light_Proj);  glMatrixMode(GL_MODELVIEW);  glLoadMatrix(Light_View);  glTranslatef(cam_pos.x, cam_pos.y, cam_pos.z);  RenderScene();}

Is that right?
If it is, i think it is normal that your frustum is moving in the opposite direction. What you are doing isn't translating the light's frustum around the camera, but translating the world around the origin (which the light is looking). If you really want to make it this way then try to translate the world in the opposite direction. Otherwise use the code i posted previously. In other words, try to put the camera position inside the light's view matrix.

HellRaiZer

##### Share on other sites
I am moving my lights POV I guess here is my code that I am altering

void CTerrain::StoreLightMatrix(void){	memset(modelViewMatrix, 0, sizeof(float) * 16);	memset(modelProjectionMatrix, 0, sizeof(float) * 16);	glPushMatrix();		glPushMatrix();			glLoadIdentity();			gluLookAt(lightPosition[0],  lightPosition[1],  lightPosition[2], 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);			glTranslatef(moveShadowPosX, 0.0f, moveShadowPosZ);			glRotatef(37.5f, 0.0f, 1.0f, 0.0f);			glGetFloatv(GL_MODELVIEW_MATRIX, modelViewMatrix);		glPopMatrix();		glLoadIdentity();		gluPerspective(20.0f, 1.0f, 200.0f, 300.0f);		//glOrtho(0.0, gWidth, 0.0, gHeight, 200.0, 400.0);		glGetFloatv(GL_MODELVIEW_MATRIX, modelProjectionMatrix);	glPopMatrix();}

Now I am also trying to do a orthographic projection but that isn't working out to well either... I just figured all I had to do was change my gluPerspective to glOrtho but the shadows look like round blobs...

##### Share on other sites
with your method youre wasting large part of SM on stuff that is offscreen, instead of covering the whole terrain, u want to focus on the area infront of the camera
eg
gluLookAT( campos+cam_forward_dir*100 )
also u can take the suns direction relative to the camera into consideration

##### Share on other sites
Quote:
 Original post by zedzeekwith your method youre wasting large part of SM on stuff that is offscreen, instead of covering the whole terrain, u want to focus on the area infront of the cameraeggluLookAT( campos+cam_forward_dir*100 )also u can take the suns direction relative to the camera into consideration

Hi Zedzeek, yeah you are correct. That is what I am trying to do. I moved my frustum and WOW when its closer and a smaller FOV the shadows are really nice vs. covering the whole terrain. I just need to get the shadowmap frustum to move with my camera. So this gluLookAT( campos+cam_forward_dir*100 ) is that formula only for the camera position? I will give your idea a shot. Will you be on much longer? Thanks