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

SSAO and skybox artifact

11 posts in this topic

I'm running into an ugly artifact with my SSAO where when geometry against the skybox is being occluded by the skybox and vice versa, I was able to fix the skybox being occluded by simply skipping the ssao calculation as soon as I know that the pixel is a skybox. I still have the problem with the skybox occluding my geometry creating an ugly dotted line, the skybox is black in the gbuffer and at depth 1.0 but after trying uselessly to skip sampling the skybox using a step function, I decided to ask here. Anyway here is my glsl shader code based heavily on code from [url="http://www.gamerendering.com/2009/01/14/ssao/"]here[/url]:

[CODE]

uniform sampler2D depth_texture;
uniform sampler2D color_texture;
uniform sampler2D normal_texture;
uniform float scr_w;
uniform float scr_h;

uniform vec3 pSphere[10] = vec3[]( vec3(-0.010735935, 0.01647018, 0.0062425877),
vec3(-0.06533369, 0.3647007, -0.13746321),
vec3(-0.6539235, -0.016726388, -0.53000957),
vec3(0.40958285, 0.0052428036, -0.5591124),
vec3(-0.1465366, 0.09899267, 0.15571679),
vec3(-0.44122112, -0.5458797, 0.04912532),
vec3(0.03755566, -0.10961345, -0.33040273),
vec3(0.019100213, 0.29652783, 0.066237666),
vec3(0.8765323, 0.011236004, 0.28265962),
vec3(0.29264435, -0.40794238, 0.15964167));
varying vec2 vTexCoord;
#define STRENGTH 0.09
#define FALLOFF 0.0 //0.00002
#define RAD 0.006
#define SAMPLES 10
#define INVSAMPLES 1.0/SAMPLES
vec4 height_normal(in vec2 texcoord)
{
vec4 normaltexel;
normaltexel.rgb = (texture2D(normal_texture, texcoord).xyz * 2.0) - vec3(1.0);
normaltexel.a = texture2D(depth_texture, texcoord).x;

return normaltexel;
}
void main(void)
{
// get a random normal
vec3 fres = normalize((texture2D(color_texture, vTexCoord * (scr_w / 64)).xyz * 2.0) - vec3(1.0));

//grab depth and a normal vector
vec4 currentPixelSample = height_normal(vTexCoord);

vec3 samplepos = vec3(vTexCoord.xy, currentPixelSample.a);

float blacklevel = 0.0;

float depthDiff;
vec4 occluderFragment;
vec3 ray;

if(length(currentPixelSample.xyz) <= 1.0) //dont calculate ssao because the pixel is in skybox
{
for(int i = 0; i < SAMPLES; ++i)
{
// trace a ray from a random normal to a random position
ray = (RAD / samplepos.z) * reflect(pSphere[i], fres);

occluderFragment = height_normal(samplepos.xy + (sign(dot(ray, currentPixelSample.xyz)) * ray.xy)); //get the position of the occluder

depthDiff = samplepos.z - occluderFragment.a;

blacklevel += step(FALLOFF, depthDiff) * (1.0 - dot(currentPixelSample.xyz, occluderFragment.xyz)) * (1.0 - smoothstep(FALLOFF, STRENGTH, depthDiff));
}
}

// output the result
gl_FragColor = vec4(vec3(1.0 - (blacklevel * INVSAMPLES)), 1.0);

}
[/CODE]

attached is a picture of my problem the the offending pixels circled. Anyone know how to fix this?
0

Share this post


Link to post
Share on other sites
if the skybox is exactly at 1.0 (zfar) by writing gl_FragDepth = 1.0 in the atmosphere shader,
you can avoid it by using a branch: if (depth < 0.99) { do stuff }
It will reduce performance of your SSAO shader, but i think it will work :)

in your example this could be:
if (normaltexel.a < 0.999)
{
do ssao
} Edited by Kaptein
1

Share this post


Link to post
Share on other sites
When dealing with shaders, ALL code is executed, including ALL branches, all function calls, etc. The ONLY exception for this is if something is known at compile time that will allow the compiler to remove a particular piece of code.

This is how all graphics cards work, AMD, NVIDIA, etc. So, your additional cost is of the if statement, and in your example, you are adding an extra if instruction. This is a zero cost on gpus. If you want to read on it, check out vectors processors and data hazards.

If you somehow split our shader up and added an if statement to the middle thinking that it would speed up your code, you would get NO speedup. because ALL paths will be executed.
-2

Share this post


Link to post
Share on other sites
Do a depth bound test (can be setup on engine side, no shader if branches) with max range 0.99999f, this will ensure you're not computing SSAO on the sky (which should be at 1.0). I'm not familiar with OpenGL so I don't know the setup for a depth-bound test (but I'm sure it can be done), but you can do this on CPU side in D3D.
1

Share this post


Link to post
Share on other sites
[quote name='CryZe' timestamp='1354868138' post='5008035']
A warp consists of either 16 or 32 threads grouped together.
[/quote]

I think you mean "32 or 64" [img]http://public.gamedev.net//public/style_emoticons/default/tongue.png[/img]
0

Share this post


Link to post
Share on other sites
[quote name='smasherprog' timestamp='1354892867' post='5008130']
When dealing with shaders, ALL code is executed, including ALL branches, all function calls, etc. The ONLY exception for this is if something is known at compile time that will allow the compiler to remove a particular piece of code.

This is how all graphics cards work, AMD, NVIDIA, etc. So, your additional cost is of the if statement, and in your example, you are adding an extra if instruction. This is a zero cost on gpus. If you want to read on it, check out vectors processors and data hazards.

If you somehow split our shader up and added an if statement to the middle thinking that it would speed up your code, you would get NO speedup. because ALL paths will be executed.
[/quote]

This is completely wrong, even for relatively old GPU's (even the first-gen DX9 GPU's supported branching on shader constants, although in certain cases it was implemented through driver-level shenanigans). I'm not sure how you could even come to such a conclusion, considering it's really easy to set up a test case that shows otherwise. Edited by MJP
2

Share this post


Link to post
Share on other sites
[quote name='MJP' timestamp='1354934346' post='5008334']
[quote name='CryZe' timestamp='1354868138' post='5008035']
A warp consists of either 16 or 32 threads grouped together.
[/quote]
I think you mean "32 or 64" [img]http://public.gamedev.net//public/style_emoticons/default/tongue.png[/img]
[/quote]

I thought a Wavefront on AMDs architecture consists of 16 execution units. Or am I wrong? (I just used warp as a general term, because I like it more :D) Edited by CryZe
0

Share this post


Link to post
Share on other sites
[quote name='CryZe' timestamp='1354971856' post='5008480']
[quote name='MJP' timestamp='1354934346' post='5008334']
[quote name='CryZe' timestamp='1354868138' post='5008035']
A warp consists of either 16 or 32 threads grouped together.
[/quote]
I think you mean "32 or 64" [img]http://public.gamedev.net//public/style_emoticons/default/tongue.png[/img]
[/quote]

I thought a Wavefront on AMDs architecture consists of 16 execution units. Or am I wrong? (I just used warp as a general term, because I like it more [img]http://public.gamedev.net//public/style_emoticons/default/biggrin.png[/img])
[/quote]

Nah there's 64 threads in a wavefront. In their latest architecture (GCN) the SIMDs are 16-wide, but they execute each instruction 4 times to complete it for the entire wavefront (so a single-cycle instruction actually takes 4 cycles to execute). Edited by MJP
1

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