• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Wh0p

SSAO artefacts

11 posts in this topic

Hi,

I followed this article about ssao: http://www.gamedev.net/page/resources/_/technical/graphics-programming-and-theory/a-simple-and-practical-approach-to-ssao-r2753

 

But i encountered some difficulties as you can see below:

 

1) Why do the edges of the triangles reappear in the OcclusionBuffer and there for are visible in the final image (Thought that wouldn't be if i calc the normalized normals in pixel shader)?

2) If I look down on a plane surface this surface appears to be occluded (grows dark), should it be that way?

3) Artefacts like the black curvy lines and those rectangles nicly seen in the 3rd picture.

 

Here are the images:

ssao1.jpg

ssao2e.jpg

ssao3e.jpg

 

As far as i can tell the normals and positions seem correct, but anyway:

 

This is how i generate my normal and position buffer:

PS_INPUT VSMAIN (in VS_INPUT input)
{
	PS_INPUT Out;

	// viewspace position
	Out.viewpos = mul (float4 (input.position, 1.0f), WorldMatrix);
	Out.viewpos = mul (Out.viewpos, ViewMatrix);

	// projectited position
	Out.position = mul (Out.viewpos, ProjMatrix);

	// viewspace normals
	Out.normal = mul (float4 (input.normal, 0.0f), WorldMatrix);
	Out.normal = mul (Out.normal, ViewMatrix);
	

	return Out;
}

struct PS_OUTPUT
{
	float4 normal : SV_Target0;
	float4 viewpos : SV_Target1;
};

PS_OUTPUT PSMAIN (in PS_INPUT In)
{
	PS_OUTPUT Out;
	
	Out.normal =  float4((normalize(In.normal)).xyz * 0.5f + 0.5f, 1.0f);
	Out.viewpos = In.viewpos;

	return Out;
}

This is the ssao algorithm (pretty much the one from the article):

float3 getPosition (in float2 uv)
{
	return PositionBuffer.Sample (LinearSampler, uv).xyz;
}

float3 getNormal (in float2 uv)
{
	return DepthNormalBuffer.Sample (LinearSampler, uv).xyz;
}

float2 getRandom (in float2 uv)
{
	return normalize (RandomTexture.Sample (LinearSampler, uv).xy * 0.5f + 0.5f);
}

float doAmbientOcclusion (in float2 tcoord, in float2 occluder, in float3 p, in float3 cnorm)
{
	// vector v from the occludee to the occluder
	float3 diff = getPosition (tcoord + occluder) - p;
	const float3 v = normalize (diff);

	// distance between occluder and occludee
	const float d = length (diff) * Scale;

	return max (0.0, dot (cnorm,v) - Bias) * (1.0 / (1.0 + d) * Intensity);
}


float PSMAIN (in PS_INPUT In) : SV_Target
{
	const float2 vec[4] = {
		float2 (1,0), float2 (-1,0),
		float2 (0,1), float2 (0,-1)
	};

	float3 p = getPosition (In.tex);
	float3 n = getNormal (In.tex);
	float2 rand = getRandom(In.tex);

	// amboent occlusion factor
	float ao = 0.0f;
	float rad = Radius / p.z;

	int iterations = 4;
	for (int j = 0; j < iterations; ++j)
	{
		float2 coord1 = reflect(vec[j], rand) * rad;
		float2 coord2 = float2 (coord1.x*0.707 - coord1.y*0.707,
		                        coord1.x*0.707 + coord1.y*0.707);

		ao += doAmbientOcclusion (In.tex, coord1*0.25, p, n);
		ao += doAmbientOcclusion (In.tex, coord2*0.5, p, n);
		ao += doAmbientOcclusion (In.tex, coord1*0.75, p, n);
		ao += doAmbientOcclusion (In.tex, coord2, p, n);
	}
	ao /= (float)iterations*4.0;

	return 1 - ao;
}

Thank you if you are still reading :)

1

Share this post


Link to post
Share on other sites

So I got an update on this:

 

the issue with the rectangles was surprisingly easy solved by using a linear filter and not a point filter for the random texture...

 

however the other problems remain...

 

Applying a blur to the occlusion buffer did not hide those lines, as well I do have no clue how to get rid of the primitive edges.

 

Please help!

0

Share this post


Link to post
Share on other sites


the issue with the rectangles was surprisingly easy solved by using a linear filter and not a point filter for the random texture...

 

Now you haven't solved it but hidden the problem further, I think. Looks like you stretch your random texture across the full screen, both from your implementation and your screenshot. Compare your getRandom to the one of the article: The idea is to repeat it (wrapping adressing mode), tiling the whole screen, so to speak. For this you need to feed the right values for g_screen_size and random_size. Also, the sample uses denormalization (*2 - 1) of the texture sample, you do quite the opposite (one could use a SNorm texture though).

 

It helps using "debugging" output, e.g. output the random values only, to narrow problems down.

0

Share this post


Link to post
Share on other sites

The idea is to repeat it (wrapping adressing mode), tiling the whole screen, so to speak.

 

Aparently I did that too and gave the other modification the credit for the result.

But anyway those lines didn't dissapear and are only masked by the blur, but if you whatch really carefully you can still see them.

 

Is there realy noone here, whose got an idea to get rid of the primitive edges?

 

If it helps, the final output is calculated this way:

Out = In.color * ao * Ia;

if (NdotL > 0.0f) 
{
	Out += diffuseIntensity;
	Out += specularIntensity;
}

return Out;

where Ia is the ambient intensity, and ao the abient occlusion factor from the buffer.

0

Share this post


Link to post
Share on other sites

Good job on the article!

I indeed implemented a upper bound for the depth and that along with tweaking the bias value for the dot product got rid of occluding the plane surfaces that much.

 

However the primitive edges still give me a hard time... 

0

Share this post


Link to post
Share on other sites

 

However the primitive edges still give me a hard time... 

 

 

Are you sure your normals are correct? Are you using smooth normals? Do you see the primitive edges if you just use standard lighting, no AO?

0

Share this post


Link to post
Share on other sites

Yeah I do calculate the smooth normals. The normal buffer as well as the positions buffer look correct to me. Well you can't see a lot in the positions buffer just the four colors but if I choose a smller scaled model you might see that the possitions are smoothly interpalated.

 

ssao1.jpg

 

ssao2.jpg

 

ssao3.jpg

 

If the images don't match up with your experiences, tell me!

 

The term in the pixelshader to normalize the normals I use is:

Out.normal =  float4((normalize(In.normal)).xyz * 0.5f + 0.5f, 1.0f);

But I am wondereing what the * 0.5f + 0.5f is about. I haven't found any reason in tutorials, nor could I come up with one myself.

 

 

Edit:

I just realized that the primitives especially become visible if I cran up the intensity value.

I'll just show you how it looks right now and if you tell me its good and be done with it i do so,

however if you find anything off please report back :)

 

[url=http://postimg.org/image/vtxxdwvx1/]ssao2e.jpg[/url]

Edited by Wh0p
0

Share this post


Link to post
Share on other sites

What formats are your g-buffer targets?

 

Also, the * 0.5 + 0.5 brings the normalized normals from range [-1, 1] to range [0, 1].

0

Share this post


Link to post
Share on other sites

I'm using DXGI_FORMAT_R16G16B16A16_FLOAT the thing with the positive range I knew, what is was wondering about is that the occlusion term should be evaluated wrong for points with negative components in their normal.

0

Share this post


Link to post
Share on other sites

Ok, its all settled now.

The main problem was, that I had configured a value for the radius that was much too small. Which toggled the points to occlude themselves. It look allright now.

I appreciate your help, Thaks!

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0