Jump to content

  • Log In with Google      Sign In   
  • Create Account


Silverlan

Member Since 02 May 2013
Offline Last Active Today, 11:04 AM

Posts I've Made

In Topic: [OpenGL] Cascaded shadow mapping - Render shadows to world?

18 August 2014 - 02:51 PM

When generating the shadow maps you are enclosing only the “visible” area (created by the view frustum).  This doesn’t make sense, as things above the player, even if not directly visible to the player, can still cast shadows visible to the player.

 

Lock the near plane of the shadow-map projections to include any objects above the player that can cast shadows visible to the player.

 

Right, thanks. I've changed the bounds for each cascade to be large enough to encompass the entire scene, just for testing purposes, and that does give me better results:

904f0cd679.jpg

 

 

The other problems (self-shadowing and different intensity) are directly related with the other problem I believe:

 

I'd like to see the whole fragment shader. Are you performing a comparison between the fragments position and the shadowmap value somewhere?

 

The return value from GetShadowCoefficient is literally just multiplied with the diffuse color. I've tried a comparison like so:

	[...]
	shadowCoord.w = shadowCoord.z;
	shadowCoord.z = float(index);
	shadowCoord.x = shadowCoord.x *0.5f +0.5f;
	shadowCoord.y = shadowCoord.y *0.5f +0.5f;
	float z = shadow2DArray(csmTextureArray,shadowCoord).x;
	if(z < shadowCoord.w)
		return 0.25f;
	return 1;

However that only gives me proper results for the first cascade, after that it's just cut off:

3e87c730b9.jpg


In Topic: [OpenGL] Cascaded shadow mapping - Render shadows to world?

17 August 2014 - 02:41 PM

Well, the only CSM-related part in the fragment shader is basically what I already posted before:

in vec4 csmPos[3];

uniform vec4 far_d;
uniform sampler2DArrayShadow csmTextureArray;
uniform mat4 csmMatrices[3];
float GetShadowCoefficient()
{
	int index = 3;
	vec4 shadowCoord;
	for(int i=0;i<4;i++)
	{
		if(gl_FragCoord.z < far_d[i])
		{
			shadowCoord = csmPos[i];
			index = i;
			break;
		}
	}
	shadowCoord.w = shadowCoord.z;
	shadowCoord.z = float(index);
	shadowCoord.x = shadowCoord.x *0.5f +0.5f;
	shadowCoord.y = shadowCoord.y *0.5f +0.5f;
	return shadow2DArray(csmTextureArray,shadowCoord).x;
}

The result from this function is then multiplied by the output color, that's about it. As for the vertex shader:

layout(std140) uniform ViewProjection
{
	mat4 M; // Model Matrix
	mat4 V; // View Matrix
	mat4 P; // Projection Matrix
	mat4 MVP;
};

layout(location = 0) in vec4 vertPos;

// CSM Test
uniform mat4 csmMatrices[3];
out vec4 csmPos[3];

[...] Inside the main function:
	csmPos[0] = csmMatrices[0] *(M *vertPos);
	csmPos[1] = csmMatrices[1] *(M *vertPos);
	csmPos[2] = csmMatrices[2] *(M *vertPos);

These are the only parts that use the CSM-related data.


In Topic: [OpenGL] Cascaded shadow mapping - Render shadows to world?

17 August 2014 - 01:49 PM

Thanks, that actually did the trick!

 

There are still some issues, but I'm a major step closer now!

 

What puzzles me a bit is how the shadow maps darken the further I look downwards, that doesn't seem right. Any idea what could be causing this?


In Topic: [OpenGL] Cascaded shadow mapping - Render shadows to world?

17 August 2014 - 06:43 AM

The lookup position is calculated in the vertex shader like so:

csmPos1 = csmMatrices[0] *(M *vpos);
csmPos2 = csmMatrices[1] *(M *vpos);
csmPos3 = csmMatrices[2] *(M *vpos);

Where vpos is the vertex position, M is the model matrix to transform it into world space and the respective matrix from csmMatrices is the view-projection matrix I used to render the shadows. This is then passed to the fragment shader, where I select the cascade and use shadow2DArray to grab the shadow value:

float GetShadowCoefficient()
{
	int index = 2;
	vec4 csmPos;
	if(gl_FragCoord.z < far_d.x)
	{
		index = 0;
		csmPos = csmPos1;
	}
	else if(gl_FragCoord.z < far_d.y)
	{
		index = 1;
		csmPos = csmPos2;
	}
	else if(gl_FragCoord.z < far_d.z)
	{
		index = 2;
		csmPos = csmPos3;
	}
	vec4 shadow_coord = csmPos;
	shadow_coord.w = shadow_coord.z;
	shadow_coord.z = float(index);
	return shadow2DArray(csmTextureArray,shadow_coord).x;
}

The code is just for testing purposes and not optimized yet.

Either way, the result is somewhat of a mess:

 

I don't think my shadow matrices are wrong, considering the shadow maps look more or less as they should, so I'm not sure what's going on?


In Topic: PhysX - Stick controllers to kinematic actors

15 July 2014 - 08:28 AM

Well keep in mind these are move flags, returned as the result of a move call, I believe the sides flag is means that you hit something in the direction of the move around the middle part of the controller shape, meaning you are blocked from moving sideways by something which Im guessing cant be auto stepped, PxControllerDesc::stepOffset.

 

I mean that if you move with an angle against an axis-aligned wall, your movement would stop in one axis (The one perpendicular to the wall), but the other axis wouldn't be affected. (You 'slide' against the wall)

However, since I only know if there HAS been a collision at any side, but not which one, all I can do is reset both axes to 0, which would mean the movement would come to a complete halt.

In essense it's the same problem as with slopes.


PARTNERS