Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Dual Paraboloid Shadow Mapping


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
No replies to this topic

#1 Migi0027   Crossbones+   -  Reputation: 2132

Like
0Likes
Like

Posted 21 February 2014 - 03:29 AM

Hi guys!

 

So here I am, again, trying to get my dual paraboloid shadow mapper to work, but no. So I've tried countless times and it never really succeeded, and at some point I've copy pasted out of lost patience, and yet it didn't work, so I'm starting to suspect that I'm doing something wrong on the cpu side. So basically this is how I do it:

 

Creating the view matrix ( from the light ):

.. Cut and scippets from different places, so it might seem disconnected, but it's not
pos = GetPosition(); - Get the light position
target = CEVector3f(0,0,0); - Lookat to 0,0,0

// Generate view matrix, up = (0,1,0)
D3DXMatrixLookAtLH(GetSMAP()->GetViewMatrix(), GetSMAP()->GetPosition(), GetSMAP()->GetTarget(), &up);

// Generate View Frustum for occlusion
....

// Transpose the view matrix
D3DXMatrixTranspose(GetSMAP()->GetViewTMatrix(),GetSMAP()->GetViewMatrix());

No projection matrix is created as paraboloid mapping is a projection in itself.

 

Render the point lights dp shadow map:

until(pointLights.size())
{
	if (pointLights[i]->m_bCastShadows == false)
		continue;

	pointLights[i]->Update();
	_until(offset, pointLights[i]->GetSMCount()) RenderDPShadowDepth(&pointLights[i]->GetShadowMap()[offset], offset, pointLights[i]->GetSMSurface());
}

RenderDPShadowDepth::

void C3DEngineObject::RenderDPShadowDepth(ShadowMap *smap, int lI, CeSURFACE *pSurface)
{
    .. Not 'actual' code
    SetViewport(512, 512); , width, height

    ApplyNoCulling()
    DisableDepthTesting()
    
    SetShader();
    SetRenderTarget()

    // A small hackish thing
    int dir = 1;
    if (lI == 1)
        dir = -1;

    For all meshes
        SendMeshBuffers()
        RenderTheMesh()

    EnableDepthTesting()
    BackFaceCulling()
}

For the SendMeshBuffers all I'm doing there is preparing the mesh, such as index/vertex and instancing buffers, nothing fancy there.

 

Now, as the problem may still lie in there, the shader:

cbuffer ConstantObjectBuffer : register (b0)
{
	matrix worldMatrix;
	matrix viewMatrix;
	matrix projectionMatrix;

	float gDir; - Direction
	float gNear; - Near Clip
	float gFar; - Far Clip
	float _instance; - Instancing
};

struct VOut
{
    float4 position    : SV_POSITION;
    float clip	: CLIP;
    float depth   : DEPTH;
};

VOut VShader(float4 position : POSITION, float4 normal : NORMAL, float2 texcoord : TEXCOORD, float3 instancePosition : INSTANCEPOS)
{
	// Zero out our output.
	VOut output = (VOut)0;	

	// Instancing
	if (_instance == 1)
	{
		position.xyz += instancePosition;
	}

	// Transform it into view space
	output.position = mul(mul(float4(position.xyz, 1.0f), worldMatrix), viewMatrix);
	output.position = output.position / output.position.w;
	
	// Flip Direction if needed
	output.position.z = output.position.z * gDir;
	
	float L = length( output.position.xyz );		
	output.position = output.position / L;								
	
	output.clip = output.position.z;										
	output.position.z = output.position.z + 1;							

	output.position.x = output.position.x / output.position.z;					
	output.position.y = output.position.y / output.position.z;					

	output.position.z = (L - gNear) / (gFar - gNear);	
	output.position.w = 1;									
	
	output.depth = output.position.z;

    return output;
}

float4 PShader(VOut input) : SV_TARGET
{
	clip( input.clip );
        
        // Yeah I know, why not just use a single channel texture...
	return float4(input.depth,input.depth,input.depth, 1);
}

The data sent to the shader is fine. ( Checked it )

 

EDIT: Actually checking for shadows:

float GetDPOcclusion(float3 posWS)
{
	float4 vPosDP = mul( float4(posWS, 1), lightViewMatrix );
	float fLength = length( vPosDP.xyz );
	vPosDP /= fLength;

	float fSceneDepth = ( fLength - gNear ) / ( gFar - gNear );		
	float fDPDepthBack;
	float fDPDepthFront;
	float fDPDepth;
		
	if ( vPosDP.z >= 0.0f ) {
		//Project to front map
		float2 vTexFront;
		float posX_Front = vPosDP.x / ( 1.0f + vPosDP.z );	
		float posY_Front = vPosDP.y / ( 1.0f + vPosDP.z );
		vTexFront.x = posX_Front * 0.5f + 0.5f;
		vTexFront.y = 1.0 - ( posY_Front * 0.5f + 0.5f );
		fDPDepth = t_smap_dp1.SampleLevel(ss, vTexFront, 0 );
	} else {
		//Project to back map
		float2 vTexBack;
		float posX_Back = vPosDP.x / ( 1.0f - vPosDP.z );	
		float posY_Back = vPosDP.y / ( 1.0f - vPosDP.z );
		vTexBack.x = posX_Back * 0.5f + 0.5f;
		vTexBack.y = 1.0 - ( posY_Back * 0.5f + 0.5f );
		fDPDepth = t_smap_dp2.SampleLevel(ss, vTexBack, 0 );
	}

	if ( (fDPDepth + SHADOW_EPSILON) < fSceneDepth ) {
		return 0;
	} else {
		return 1;
	}
}

Yeah, this is a lot of code I just threw on you, isn't it? Well, the problem is really that I've got no idea where the problem may be, so I though that if anyone had some time, maybe they could skim it through. sad.png

 

PS: If any other information is needed, please inform me.

 

Anyway, thanks for reaching the bottom. wink.png

-MIGI0027


Edited by Migi0027, 21 February 2014 - 04:38 AM.

Hi! Cuboid Zone
The Rule: Be polite, be professional, but have a plan to steal all their shaders!

Sponsor:



Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS