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

[D3D10, SSAO] Need help with finishing SSAO implementation

1 post in this topic

Hi Everyone!

I'm seeking some help in implementing SSAO. I'm basing on John Chapman's tutorial -> [url="http://www.john-chapman.net/content.php?id=8"]http://www.john-chap...ontent.php?id=8[/url] . Well the tutorial seems quite simple, and I think I've implemented each part of it correctly. Unfortunatelly results shows that somethings deffinitelly is wrong. If You could help, I'd appreciate that. So, here it goes:

HLSL code (shader 4.0 Dx10)

First part is storing:
linear normalized depth
viewspace normals
colour

[source]struct VS_I_POS_TEX
{
float4 position : POSITION;
float2 textureCoordinates : TEXCOORD;
};
//-------------------------------------------------------------------------
struct VS_O_POS_TEX_EYE
{
float4 position : SV_POSITION;
float2 textureCoordinates : TEXCOORD0;
float3 eyePosition : TEXCOORD1;
};
//-------------------------------------------------------------------------
struct PS_I_POS_TEX_EYE
{
float4 position : SV_POSITION;
float2 textureCoordinates : TEXCOORD0;
float3 eyePosition : TEXCOORD1;
};
//-------------------------------------------------------------------------
struct PS_O_COLOR_NORM_DEPTH
{
float4 color : SV_Target0;
float4 normal : SV_Target1;
float normalizedLinearDepth : SV_Target2;
};

VS_O_POS_TEX_EYE VS_MRTRendering(VS_I_POS_TEX vsInput)
{
VS_O_POS_TEX_EYE vsOutput = (VS_O_POS_TEX_EYE)0;

vsOutput.position = mul(vsInput.position, matrix_view);
vsOutput.eyePosition = vsOutput.position.xyz;
vsOutput.position = mul(vsOutput.position, matrix_projection);
vsOutput.textureCoordinates = vsInput.textureCoordinates;

return vsOutput;
}
//-------------------------------------------------------------------------
PS_O_COLOR_NORM_DEPTH PS_MRTRendering(PS_I_POS_TEX_EYE psInput)
{
PS_O_COLOR_NORM_DEPTH psOutput = (PS_O_COLOR_NORM_DEPTH)0;

if(!disableTextures) psOutput.color = texture_diffuse.Sample(Sampler_anisotropic, psInput.textureCoordinates);
else psOutput.color = float4(1.0f, 1.0f, 1.0f, 1.0f);

psOutput.normal.xyz = normalize(cross(ddx(psInput.eyePosition.xyz), ddy(psInput.eyePosition.xyz)));
psOutput.normalizedLinearDepth = psInput.eyePosition.z / farClip;

return psOutput;
}[/source]

And the second part is computing occlusion

[source]struct VS_I_POS_TEX_CORID
{
float3 position : POSITION;
float2 textureCoordinates : TEXCOORD;
float cornerId : CORNERID;
};
struct VS_O_POS_TEX_CORID_VSRAY
{
float4 position_SS : SV_POSITION;
float2 textureCoordinates : TEXCOORD0;
float cornerId : CORNERID;
float3 frustumPointCoordinateVS : TEXCOORD1;
};
VS_O_POS_TEX_CORID_VSRAY VS_RenderOcclusion(VS_I_POS_TEX_CORID vsInput)
{
VS_O_POS_TEX_CORID_VSRAY vsOutput = (VS_O_POS_TEX_CORID_VSRAY)0;

vsOutput.position_SS = float4(vsInput.position, 1.0f);
vsOutput.textureCoordinates = vsInput.textureCoordinates.xy;
vsOutput.frustumPointCoordinateVS = aFrustumCornerPosition_VS[vsInput.cornerId];
return vsOutput;
}
//-------------------------------------------------------------------------
float PS_RenderOcclusion(VS_O_POS_TEX_CORID_VSRAY psInput) : SV_Target
{
float3 viewRay = float3(psInput.frustumPointCoordinateVS.xy, farClip);

float3 origin = viewRay * (float)texture_linearDepth.Sample(Sampler_point, psInput.textureCoordinates);

//I've tested it, and it seems reconstruction works correctly.
//Here's how I tested it:
//I took viewRay.xy and muliplied it by projection matrix, and then divided by w component
//Then I've done some scaling and compared it to the psInput.position.xy
//They match so this part looks correct for me


float3 normal = texture_normals.Sample(Sampler_point, psInput.textureCoordinates).xyz;

normal = normalize(normal);

float3 noiseSample = float3(texture_noiseSamples.Sample(Sampler_point, psInput.textureCoordinates * noiseScale).xy, 0.0f) * 2.0f - 1.0f;

float3 tangent = normalize(noiseSample - normal * dot(noiseSample, normal));

float3 bitangent = cross(normal, tangent);

float3x3 tbn = float3x3(tangent, bitangent, normal);
tbn = transpose(tbn);

float occlusion = 0.0f;

int samplesCount = 16;
float radius = 0.5f;

for(int i = 0; i < samplesCount; ++i)
{
float3 sample = mul(aRandomSamples[i], tbn);

sample = sample * radius + origin;

float4 offset = float4(sample, 1.0);

offset = mul(offset, matrix_projection);
offset.xy /= offset.w;
offset.xy = offset.xy * 0.5 + 0.5;

float sample_depth = (float)texture_linearDepth.Sample(Sampler_point, offset.xy);

occlusion += (sample_depth <= sample.z ? 1.0 : 0.0);
}

occlusion = 1.0 - (occlusion / samplesCount);

return occlusion;
}[/source]

That's mainly it. Here's the results(fulscreen quad with only occlusion texture)

[img]http://i.imm.io/fZTs.jpeg[/img]

[left]It's a sponza model, and the camera is looking from the flor to the sky. Only looking to the sky shows some results.[/left]

[left]Well, what do You think of it? I have no idea what could be possibly wrong with this implementation.[/left]


[left][color=#fafafa !important][/color][img]http://www.google.com/uds/css/small-logo.png[/img][/left]
0

Share this post


Link to post
Share on other sites
Ok. I found one mistake.

On the line:
[source]float sample_depth = (float)texture_linearDepth.Sample(Sampler_point, offset.xy);[/source]

I forgot to multiply by farClip value. After correction the output is far from being ok.

Actual output:
[img]http://i.imm.io/g10G.jpeg[/img][left]
[color=#fafafa !important][size=4][/size][/color][img]http://www.google.com/uds/css/small-logo.png[/img][/left]
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