• 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
gchewood

SSAO camera angle issue

4 posts in this topic

Trying to get some decent SSAO running and I've come upon an annoying problem. These 3 images are of the same area in the level. The first 2 are roughly correct (I hope). Ignore the weird background, separate issue.

See images:

 

[attachment=16442:ssao1.jpg][attachment=16443:ssao2.jpg][attachment=16444:ssao3.jpg]

 

For about 75% of viewing angles it looks consistent. However when the camera then faces one direction (image 3), it starts playing up and darkening most objects. What could be causing this? The depth map and normal map both look fine and it's not the gaussian blur either. The main hlsl shader code is as follows:

float Radius;
float MaxRadius;
float RandomTile;
float Bias;
float FarClip;

texture DepthBuffer;
sampler2D depthSampler = sampler_state
{
	Texture = <DepthBuffer>;
	MipFilter = NONE;
	MagFilter = POINT;
	MinFilter = POINT;
	AddressU = Clamp;
	AddressV = Clamp;
};

texture NormalBuffer;
sampler2D normalSampler = sampler_state
{
	Texture = <NormalBuffer>;
	MipFilter = NONE;
	MagFilter = LINEAR;
	MinFilter = LINEAR;
	AddressU = Clamp;
	AddressV = Clamp;
};

texture RandomMap;
sampler2D randomSampler = sampler_state
{
	Texture = <RandomMap>;
	MipFilter = NONE;
	MagFilter = POINT;
	MinFilter = POINT;
	AddressU = Wrap;
	AddressV = Wrap;
};


struct VertexShaderInput
{
    float4 Position : POSITION0;
	float2 TexCoord : TEXCOORD0;
};

struct VertexShaderOutput
{
    float4 Position : POSITION0;
	float2 TexCoord : TEXCOORD0;
};



VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{
    VertexShaderOutput output = (VertexShaderOutput)0;
	
	output.Position = float4(input.Position.xyz,1);
    output.TexCoord = input.TexCoord;  
	
	return output;
}

half3 DecodeNormal (half4 enc)
{
	float kScale = 1.7777;
	float3 nn = enc.xyz*float3(2*kScale,2*kScale,0) + float3(-kScale,-kScale,1);
	float g = 2.0 / dot(nn.xyz,nn.xyz);
	float3 n;
	n.xy = g*nn.xy;
	n.z = g-1;
	return n;
}

#define SAMPLE_COUNT 13
float3 RAND_SAMPLES[SAMPLE_COUNT] = 
{
      float3( 0.5381, 0.1856,-0.4319), 
	  float3( 0.1379, 0.2486, 0.4430),
      float3( 0.3371, 0.5679,-0.0057), 
	  float3(-0.6999,-0.0451,-0.0019),
      float3( 0.0689,-0.1598,-0.8547), 
	  float3( 0.0560, 0.0069,-0.1843),
      float3(-0.0146, 0.1402, 0.0762), 
	  float3( 0.0100,-0.1924,-0.0344),
      float3(-0.3577,-0.5301,-0.4358), 
	  float3(-0.3169, 0.1063, 0.0158),
      float3( 0.0103,-0.5869, 0.0046), 
	  float3(-0.0897,-0.4940, 0.3287),
	  float3( 0.0352,-0.0631, 0.5460)
  };


float4 PixelShaderFunction(VertexShaderOutput input): COLOR0
{
        float depth =tex2D(depthSampler,input.TexCoord).r;	
	clip(-depth + 0.9999f);
	float totalOcclusion = 0;
	depth *= FarClip;    
	float scale = min(MaxRadius,Radius / max(1,depth));
	half3 normal = DecodeNormal(tex2D(normalSampler, input.TexCoord));
	normal.y = -normal.y;
	half3 normalScaled = normal * 0.25f;
	half3 randNormal = (tex2D(randomSampler, input.TexCoord*RandomTile).rgb* 2.0 - 1.0);
	for (int i = 0; i < SAMPLE_COUNT; i++)
	{
		half3 randomDirection = reflect(RAND_SAMPLES[i], randNormal);	
		randomDirection *= sign( dot(normal , randomDirection) );
		randomDirection += normalScaled;
		half modifiedDepth = depth -(randomDirection.z * Radius.x);
		half2 offset = randomDirection.xy * scale;
		float newDepth = tex2D(depthSampler, input.TexCoord + offset).r * FarClip;
		float deltaDepth = saturate(modifiedDepth - newDepth );
		totalOcclusion += (1-deltaDepth)*(deltaDepth > Bias);			      
	}
	totalOcclusion /= SAMPLE_COUNT;
	
    return totalOcclusion;
}


technique SSAO
{
    pass Pass1
    {
        VertexShader = compile vs_3_0 VertexShaderFunction();
        PixelShader = compile ps_3_0 PixelShaderFunction();
    }
}

Help!

Thanks in advance people!

0

Share this post


Link to post
Share on other sites

Ok so it's definitely a problem with the normal buffer. Not entirely sure what though.....?

0

Share this post


Link to post
Share on other sites

- Some thing to check : are you normalizing normals before encoding them? 

- I had issues with the used encoding/decoding method : I had to negate the normal before encoding and after decoding (logically).

normal.y = -normal.y; <- why?

 

Cheers!

Edited by kauna
0

Share this post


Link to post
Share on other sites

Figured it out, finally. I wasn't getting the normals into view space so they were only correct for what I assume is the default view. That's sorted but now I'm having further issues with halo-ing. On 80% of models, it works as intended. However, if you look at the palm tree in the first image for example, you'll see it's darkening the right-hand side of the tree. I'm finding that I get an annoying amount of halo-ing for any radius that's sufficiently large. To get rid of it, I seeem to have to shrink the radius to so small a value that the effect is barely noticeable :-|

Ideas?

Thanks

0

Share this post


Link to post
Share on other sites

Is the darkening happening on the object or on the background behind the object? If the latter, then you should be able to fix it by ignoring the occlusion term when deltaDepth is bigger than some value (a good value to start with is your AO radius). It looks like you already do this for small terms too? (What is "Bias"?).

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