Skip to main content
GameDev.net gamedev.net
🔒 Locked

SSAO issue with NDC to Texture Space

Started by Paul C Skertich Aug 9, 2015 at 11:47 PM 3 replies 4.2k views
Original Post
Paul C Skertich
Paul C Skertich

I recently found out why my SSAO isn't looking so grand. The following was grabbed from Frank Luna's SSAO code:


	
	XMMATRIX T = XMMATRIX(
		0.5f, 0.0f, 0.0f, 0.0f,
		0.0f, -0.5f, 0.0f, 0.0f,
		0.0f, 0.0f, 1.0f, 0.0f,
		0.5f, 0.5f, 0.0f, 1.0f);
	
//	T = XMMatrixTranspose(T);
	XMVECTOR det2;

//	XMMATRIX P = XMMatrixTranspose(PROJ);

	XMMATRIX PT = XMMatrixMultiply(PROJ,T);
	screenCB->gViewToTexSpace = PT;

The depth being sent to the final SSAO shader file is the input.position.z by world * view * projection.

Inside the SSAO shader where ProjQ is muliplied by the gViewToTexSpace (bringing NDC to Texture Space);



		// Project q and generate projective tex-coords.
		
		float4 projQ = mul(float4(q, 1.0f), gViewToTexSpace);
		
		projQ /= projQ.w;
	

I get the following result with blurred on top of it:

[attachment=28511:ScreenCaptured_nossao04207225.jpg]

As you can see it's pretty messy and doesn't look like Frank Luna's SSAO or any other typical SSAO.

It's a bummer too and I would like to get this to work. I'm bad at matrix math but I'm guessing the projected texspace is taking the projection matrix * 0.5f + 0.5f;

So here I am stuck

Paul C Skertich
Paul C Skertich

To me I don't think this is correct projected texture space. [0,1]

In addition you'll see as I do see why it screws up the SSAO

[attachment=28512:ScreenCaptured_nossao46441625.jpg]

Is this correct or am I correct this is not correct projected texture space

swiftcoder
swiftcoder




To me I don't think this is correct projected texture space. [0,1]

It sounds like the right space to me.

NDC coordinates are [-1, 1] (at least in the x and y dimensions), so you need to multiply by 0.5 and add 0.5 to obtain the range [0, 1].

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]
Paul C Skertich
Paul C Skertich

I went back to my SSAO sample for my engine after reading some others complaints getting it running. I viewed youtube video and it clearly doesn't look like mine. When you reconstruct the position from depth isn't it suppost to look like how normals in view space? Also is it the inversed perspective multiplied by the view when calculating the SSAO term on a screen quad? Or is it ortho and view inversed multipled?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.