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

Deferred shading ugly Phong

7 posts in this topic

Hello,
I am writting deferred shading (in XNA) with 3 buffers:
1. Albedo
2. Normals moved from range [-1,1] to [0,1]
3. Depth Buffer [0,1], with inverted ViewProj reconstruction into world space

After (finally) adding phong I notice it's looking ugly. I Noticed that there are some kind of square shapes near specular. I think I did something wrong with specular. Also it looks like as I am using to small precision for depth map.
I attach 2 screenshots. First is better, but with halfVector4 for Albedo and Normals, Vector2 for Depth(I did it for test). The correct surface format I want to use is Color for Albedo and Normals, Single for depth, but second screenshot shows what happenes.
Here's the function for phong:
[CODE]
float3 doPhong(float3 Normal, float3 Position)
{
float3 LightVector = normalize(Light - Position.xyz);
float3 CameraVector = normalize(Eye - Position.xyz);
float3 LightReflect = reflect(-LightVector, Normal);
float NdL = max(0.0f, dot(Normal, LightVector));
float specular = 0.0;
specular = pow(max(0.0, dot(LightReflect, CameraVector)), 20);
return saturate(NdL * LightColor)+specular;
}
[/CODE]
For those who suspect I have bad precission my nearPlane is .1f and farPlane is 30.
I feel so stupid to post question like that since it's second DS engine I am wirtting...
0

Share this post


Link to post
Share on other sites
Your normals are too quantized. Simplest solution would be to use a higher precision normal buffer or take a look in Crytek's "Reaching the speed of light" - paper where they explain how to efficiently use 3 x 8 bit to store normals with good precision. Also, please use Blinn-Phong. Phong is evil. ;D
1

Share this post


Link to post
Share on other sites
[quote name='Bummel' timestamp='1344114779' post='4966184']
Your normals are too quantized. Simplest solution would be to use a higher precision normal buffer or take a look in Crytek's "Reaching the speed of light" - paper where they explain how to efficiently use 3 x 8 bit to store normals with good precision.;D
[/quote]
[img]http://public.gamedev.net//public/style_emoticons/default/ohmy.png[/img] gonna read this for sure :D I switched to HDRblendable (64 bit for pc), I think it's enough and not too much, since I saw recomendation for this surface format in the past [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]
And about squares... I looked up different deferred shading implementations and notice them there too so i think it's ok...
[quote name='Bummel' timestamp='1344114779' post='4966184']
Also, please use Blinn-Phong. Phong is evil. ;D
[/quote]
Phong was intentional, since it's more accurate (I am aware it's slower). I will switch to blinn later, since from my observation people that are not into graphics don't see the difference xD Edited by Tasaq
0

Share this post


Link to post
Share on other sites
[quote name='Tasaq' timestamp='1344119704' post='4966199']
Phong was intentional, since it's more accurate (I am aware it's slower).
[/quote]

Actually Blinn-Phong produces more accurate results (try both at glancing angles and you'll see how bad Phong looks!), to even better results try [url="http://renderwonk.com/publications/s2010-shading-course/hoffman/s2010_physically_based_shading_hoffman_b_notes.pdf"]Enery conserving Blinn-Phong[/url].
1

Share this post


Link to post
Share on other sites
[quote name='TiagoCosta' timestamp='1344121423' post='4966204']
[quote name='Tasaq' timestamp='1344119704' post='4966199']
Phong was intentional, since it's more accurate (I am aware it's slower).
[/quote]

Actually Blinn-Phong produces more accurate results (try both at glancing angles and you'll see how bad Phong looks!), to even better results try [url="http://renderwonk.com/publications/s2010-shading-course/hoffman/s2010_physically_based_shading_hoffman_b_notes.pdf"]Enery conserving Blinn-Phong[/url].
[/quote]
QFE. The tl;dr version is that Blinn-Phong is actually an approximation to evaluating a Gaussian centered on the halfway vector.

In more plain English, you're using some statistics hacks to guess what fraction of the total surface of the area to be shaded is angled in such a way to bounce light towards you/give you laser eye surgery if it starts out coming from the light in question.

EDIT: And for extra credit, use Toksvig filtering to account for actual texture detail in the normal map!

EDIT 2: Also
[code]float NdL = max(0.0f, dot(Normal, LightVector));[/code]
makes me really, really angry. You wouldn't like me when I'm angry. Do
[code] float NdL = saturate(dot(Normal, LightVector));[/code] instead to avoid my wrath.

For clarification, you're wasting precious GPU time with those max() operations that you could be getting for free with a saturate modifier. You might think that the compiler can optimize this. You'd be wrong, though-- remember that the dot product itself does not have a defined range and that the compiler generally lacks sufficient context to know that you're dotting normalized vectors. Edited by InvalidPointer
2

Share this post


Link to post
Share on other sites
[quote name='InvalidPointer' timestamp='1344134438' post='4966237']
Do
[code] float NdL = saturate(dot(Normal, LightVector));[/code] instead to avoid my wrath.
For clarification, you're wasting precious GPU time with those max() operations that you could be getting for free with a saturate modifier.
[/quote]
I saw a lot of people doing this the way I did, but now when you mention it... I migrated to hlsl from glsl, and there you have no saturate, and you use clamp or max to do same thing so it's like habit. Thanks for the tip, I will keep this in mind :)
0

Share this post


Link to post
Share on other sites
Yeah, reason #3289472 why OpenGL is a design trainwreck. Remember kiddos, adding a clamp instruction is fine, but adding a special-case, higher-performance one that can be implemented in terms of the former somehow breaks hardware compatibility(???)

Good job, Khronos. You make us all so very, very proud. Edited by InvalidPointer
1

Share this post


Link to post
Share on other sites
[quote name='InvalidPointer' timestamp='1344175989' post='4966361']
Yeah, reason #3289472 why OpenGL is a design trainwreck. Remember kiddos, adding a clamp instruction is fine, but adding a special-case, higher-performance one that can be implemented in terms of the former somehow breaks hardware compatibility(???)
[/quote][font=courier new,courier,monospace]saturate[/font] is not a valid keyword / intrinsic-function in GLSL -- search [url="http://www.opengl.org/registry/doc/GLSLangSpec.Full.1.20.8.pdf"]the spec[/url] for the word "saturate"... However, it does ([i]incorrectly[/i]) compile on nVidia drivers.

This isn't OpenGL's fault at all -- this is nVidia's OpenGL driver purposefully accepting invalid GLSL code, in order to make developers think that AMD's GL driver is broken ([i]and hopefully even ship their product with invalid code, so that AMD's correct driver appears broken to the consumer[/i]). That's some damn evil Microsoft-esque behaviour on the part of nVidia, and the only fault OpenGL ([i]Khronos[/i]) has in this particular matter is that they're unable to hold IHV's accountable for these harmful tactics.

These are the same dirty tactics that gave us the browser wars, and browser incompatibility issues of the 90's...

Yes, you shouldn't use [font=courier new,courier,monospace]max[/font] in GLSL for this purpose either, but should [font=courier new,courier,monospace]clamp[/font] with a hard-coded 0.0 and 1.0, which will compile down to the special-case free instruction-modifier, equivalent to [font=courier new,courier,monospace]saturate[/font] in HLSL.


[edit] Sorry, I down-voted your post where you recommend the use of saturate, because I misread this as advising the use of it in GLSL, rather than in HLSL. It was actually a very good post. Forgive me! [img]http://public.gamedev.net//public/style_emoticons/default/wub.png[/img] Edited by Hodgman
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