Jump to content


specular exponent in pixel shaders


30 replies to this topic

#1 john

    Member

  • Members
  • PipPip
  • 84 posts

Posted 04 September 2004 - 04:27 PM

Is there a way to get around the precision issues caused when doing per-pixel specular lighting in pixel shaders? The problem is, when doing the specular exponent in shaders, it causes banding and most of the time the specular value is ugly. What do you guys suggest?

#2 Altair

    Valued Member

  • Members
  • PipPipPip
  • 151 posts

Posted 04 September 2004 - 06:31 PM

Which shader model are you using?
"Only two things are infinite, the universe and human stupidity, and I'm not sure about the former." - Albert Einstein

#3 john

    Member

  • Members
  • PipPip
  • 84 posts

Posted 06 September 2004 - 04:41 PM

I'm using pixel shader 2.0

#4 Kenneth Gorking

    Senior Member

  • Members
  • PipPipPipPip
  • 939 posts

Posted 07 September 2004 - 09:08 AM

Try to use floats, if possible, and check your computations: you might be using half datatypes somewhere, which gives some banding.
"Stupid bug! You go squish now!!" - Homer Simpson

#5 Altair

    Valued Member

  • Members
  • PipPipPip
  • 151 posts

Posted 12 September 2004 - 03:59 PM

With ps2.0 you can make a look-up to a specular texture, where x=saturated dot prod between light vector and view-reflection about the normal, and y=specular exponent. Alternatively you can use pow instruction.
"Only two things are infinite, the universe and human stupidity, and I'm not sure about the former." - Albert Einstein

#6 davepermen

    Senior Member

  • Members
  • PipPipPipPip
  • 1306 posts

Posted 12 September 2004 - 06:43 PM

both solutions shouldn't have any precicion issues. the specular texture was possible with ps1.4, too, and made faked solutions with ps1.1 - ps1.3 look really ugly.

there should not be any issues with ps2.0 at all..
davepermen.net
-Loving a Person is having the wish to see this Person happy, no matter what that means to yourself.
-No matter what it means to myself....

#7 Altair

    Valued Member

  • Members
  • PipPipPip
  • 151 posts

Posted 12 September 2004 - 08:25 PM

You can use the specular look-up even on ps1.1, but that's more tricky and you have to use half-vector approach which doesn't quite give correct results. ps2.0 has no challenge ;)
"Only two things are infinite, the universe and human stupidity, and I'm not sure about the former." - Albert Einstein

#8 davepermen

    Senior Member

  • Members
  • PipPipPipPip
  • 1306 posts

Posted 12 September 2004 - 08:45 PM

it will not be per pixel correct as the code will not be independent on the vertex-layout of your mesh (you can't just subdivide and get the same image..).

i'm only talking about solutions that give a real solution, not some approx.. else yes, 1.1 can fix the precision issue like 1.4 can..
davepermen.net
-Loving a Person is having the wish to see this Person happy, no matter what that means to yourself.
-No matter what it means to myself....

#9 Altair

    Valued Member

  • Members
  • PipPipPip
  • 151 posts

Posted 13 September 2004 - 02:44 AM

Quite often approximations are real solution in practice :) Half-vector specular lighting is very commonly used technique.
"Only two things are infinite, the universe and human stupidity, and I'm not sure about the former." - Albert Einstein

#10 davepermen

    Senior Member

  • Members
  • PipPipPipPip
  • 1306 posts

Posted 13 September 2004 - 04:35 AM

it's just a very commonly used technique because on pre-ps1.4, other solutions simply don't fit well into the shaders at all.. doesn't make it useful. (per-vertex-half-vector with interpolation, that is.. you can evaluate it per pixel, thats a non-issue and of course and works fine).
davepermen.net
-Loving a Person is having the wish to see this Person happy, no matter what that means to yourself.
-No matter what it means to myself....

#11 Altair

    Valued Member

  • Members
  • PipPipPip
  • 151 posts

Posted 13 September 2004 - 09:22 PM

davepermen said:

it's just a very commonly used technique because on pre-ps1.4, other solutions simply don't fit well into the shaders at all.. doesn't make it useful. (per-vertex-half-vector with interpolation, that is.. you can evaluate it per pixel, thats a non-issue and of course and works fine).

View Post

Not only because it suits well to <ps1.4, but because it's also cheaper in latter models as well and quite often suitable solution. Depends on the case what kind of solution you should use (i.e. your poly density).
"Only two things are infinite, the universe and human stupidity, and I'm not sure about the former." - Albert Einstein

#12 davepermen

    Senior Member

  • Members
  • PipPipPipPip
  • 1306 posts

Posted 14 September 2004 - 06:34 AM

sure. anyways, i'd continue to only suggest general solutions that work no mather in what situation, and, if later needed, optimisations for special situations.. this is one.
davepermen.net
-Loving a Person is having the wish to see this Person happy, no matter what that means to yourself.
-No matter what it means to myself....

#13 Altair

    Valued Member

  • Members
  • PipPipPip
  • 151 posts

Posted 14 September 2004 - 12:42 PM

When working with artists, it's actually better to go other way around. If you start with half-vector approach they can tweak the data from the start to reach required accuracy. Anyway, it of course depends how much you can gain by using half-vector approach (performance/quality/compatibility) if you should see the trouble of supporting both approaches.
"Only two things are infinite, the universe and human stupidity, and I'm not sure about the former." - Albert Einstein

#14 davepermen

    Senior Member

  • Members
  • PipPipPipPip
  • 1306 posts

Posted 14 September 2004 - 12:45 PM

well, i never worked personally with pre-dx9 hw-shaders at all, so i won't ever care anymore about it.. requiring dx9 isn't a big issue anymore, as long as the other requirements are quite high-end, too (means, it's worth the dx9-requirements), and then, those tweaks won't ever mather.
davepermen.net
-Loving a Person is having the wish to see this Person happy, no matter what that means to yourself.
-No matter what it means to myself....

#15 Altair

    Valued Member

  • Members
  • PipPipPip
  • 151 posts

Posted 14 September 2004 - 08:49 PM

It's not big issue if you are not planning to sell a lot of copies ;) As I said, even in latter shader models you want the shading to perform well.
"Only two things are infinite, the universe and human stupidity, and I'm not sure about the former." - Albert Einstein

#16 davepermen

    Senior Member

  • Members
  • PipPipPipPip
  • 1306 posts

Posted 15 September 2004 - 04:32 AM

you don't have any performance advantage in not doing it correctly in dx9. thats what i'm saying.
davepermen.net
-Loving a Person is having the wish to see this Person happy, no matter what that means to yourself.
-No matter what it means to myself....

#17 Altair

    Valued Member

  • Members
  • PipPipPip
  • 151 posts

Posted 15 September 2004 - 05:17 PM

Oh really? Can you tell me how do you do that without any performance hit?
"Only two things are infinite, the universe and human stupidity, and I'm not sure about the former." - Albert Einstein

#18 davepermen

    Senior Member

  • Members
  • PipPipPipPip
  • 1306 posts

Posted 15 September 2004 - 05:43 PM

just put the ordinary equation in.. i have not discovered any real performance-hit.. the math is minimal to do it 'correctly' (correct phong).
davepermen.net
-Loving a Person is having the wish to see this Person happy, no matter what that means to yourself.
-No matter what it means to myself....

#19 Altair

    Valued Member

  • Members
  • PipPipPip
  • 151 posts

Posted 15 September 2004 - 06:17 PM

Heh, well last time I checked (nvshaderperf), on nv40 calculating reflection vector in pixel shader results 2 cycle performance hit, which may be significant depending on what you are doing.
"Only two things are infinite, the universe and human stupidity, and I'm not sure about the former." - Albert Einstein

#20 davepermen

    Senior Member

  • Members
  • PipPipPipPip
  • 1306 posts

Posted 15 September 2004 - 06:25 PM

you can still do halfangle (if you double the angle afterwards again:D). but teh ending math is about the same then. if you do halfangle per pixel, it works great. but for ps1.3 you have to do it per vertex, where it's inherently wrong. thats why i didn't suggest it by myself.

reflection is a dot, a mul, a sub.. halfangle requires two normalized vecs to get added, renormalized, then dotted, and then the angle-cosine doubled with some trigonometric identity.. takes longer. at least, on paper.
davepermen.net
-Loving a Person is having the wish to see this Person happy, no matter what that means to yourself.
-No matter what it means to myself....





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users