Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

Specular Power = 0


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.

  • You cannot reply to this topic
4 replies to this topic

#1 TiagoCosta   Crossbones+   -  Reputation: 1074

Like
0Likes
Like

Posted 28 June 2012 - 11:53 AM

Hi,

Today I found a new bug in my engine, after some debugging I found that it happened because I added a new material that had a specular power = 0, so when the HdV = 0 it caused an exception 0^0, and the luminance calculated at those pixels was a NaN and the average luminance of the scene was also NaN so the tonemapped scene resulted in black screen.

I fixed it by adding a small value (0.0001) to the specular power stored in the gbuffer before doing HdV^power, but I was wondering if this is usual or I'm doing something else wrong...
Tiago Costa
Aqua Engine - my DirectX 11 game "engine" - In development

Sponsor:

#2 kunos   Members   -  Reputation: 1312

Like
0Likes
Like

Posted 28 June 2012 - 11:59 AM

ya i had the same problem and stuck an if (isnan(blabla)) in my pixel shader as a temporary fix, I am interested to hear better ways to solve this.
Stefano Casillo
Lead Programmer
TWITTER: @KunosStefano
AssettoCorsa - netKar PRO - Kunos Simulazioni

#3 MJP   Moderators   -  Reputation: 5488

Like
2Likes
Like

Posted 28 June 2012 - 12:19 PM

Yeah that will happen because of the way GPU's typically approximate the pow() function. A lot of renderers I know of won't actually work with specular power for the most part, and will instead work with some [0, 1] value that they call "glossiness" or "shininess". This is usually more intuitive for artists, and is also more conducive to storing the value in a G-Buffer or a specular map. Then as a final step you just convert it to a specular power if you're doing Blinn-Phong, and as part of that you can make sure that your power never goes below 1.0. So for instance you might do something simple like "specPower = 1.0f + glossiness * 4095.0f", or something a little more complicated like "specPower = exp2(glossiness * 12.0f)".

#4 pcmaster   Members   -  Reputation: 292

Like
0Likes
Like

Posted 29 June 2012 - 08:22 AM

Exactly, I ran into this a dozen times. But not only with specular shaders, also everywhere else, where you call the pow() function. Just be sure NOT to call it with a negative number as the first parameter. Clamp. It's similar as with not dividing by zero :-)

#5 Zoner   Members   -  Reputation: 228

Like
0Likes
Like

Posted 12 July 2012 - 06:51 PM

zero bases break pow as well on GPUs since the pow is basically:

float pow(float base, float exponent)
{
return exp2(log2(v), exponent);
}

The fix is to either call max(v, very_small_number ) or something like


float mypow(float base, float exponent)
{
return base > very_small_number ? exp2(log2(v), exponent) : 0;
}


And you get to sit down and tune your own very_small_number for whatever you are working on.




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.



PARTNERS