• FEATURED

View more

View more

View more

Image of the Day Submit

IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

7 replies to this topic

#1Tasaq  Members

Posted 04 August 2012 - 10:01 AM

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:
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;
}

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...

#2Tasty Texel  Members

Posted 04 August 2012 - 03:12 PM

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

#3Tasaq  Members

Posted 04 August 2012 - 04:35 PM

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

gonna read this for sure 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
And about squares... I looked up different deferred shading implementations and notice them there too so i think it's ok...

Also, please use Blinn-Phong. Phong is evil. ;D

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, 04 August 2012 - 04:35 PM.

#4TiagoCosta  Members

Posted 04 August 2012 - 05:03 PM

Phong was intentional, since it's more accurate (I am aware it's slower).

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 Enery conserving Blinn-Phong.

#5InvalidPointer  Members

Posted 04 August 2012 - 08:40 PM

Phong was intentional, since it's more accurate (I am aware it's slower).

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 Enery conserving Blinn-Phong.

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
float NdL = max(0.0f, dot(Normal, LightVector));
makes me really, really angry. You wouldn't like me when I'm angry. Do
float NdL = saturate(dot(Normal, LightVector));

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, 04 August 2012 - 08:50 PM.

clb: At the end of 2012, the positions of jupiter, saturn, mercury, and deimos are aligned so as to cause a denormalized flush-to-zero bug when computing earth's gravitational force, slinging it to the sun.

#6Tasaq  Members

Posted 05 August 2012 - 03:24 AM

Do

float NdL = saturate(dot(Normal, LightVector));
For clarification, you're wasting precious GPU time with those max() operations that you could be getting for free with a saturate modifier.

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

#7InvalidPointer  Members

Posted 05 August 2012 - 08:13 AM

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, 05 August 2012 - 08:14 AM.

clb: At the end of 2012, the positions of jupiter, saturn, mercury, and deimos are aligned so as to cause a denormalized flush-to-zero bug when computing earth's gravitational force, slinging it to the sun.

#8Hodgman  Moderators

Posted 05 August 2012 - 08:23 AM

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(???)

saturate is not a valid keyword / intrinsic-function in GLSL -- search the spec for the word "saturate"... However, it does (incorrectly) 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 (and hopefully even ship their product with invalid code, so that AMD's correct driver appears broken to the consumer). That's some damn evil Microsoft-esque behaviour on the part of nVidia, and the only fault OpenGL (Khronos) 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 max in GLSL for this purpose either, but should clamp with a hard-coded 0.0 and 1.0, which will compile down to the special-case free instruction-modifier, equivalent to saturate in HLSL.

 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!

Edited by Hodgman, 05 August 2012 - 08:35 AM.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.