Wonky specular in reflections - Printable Version
+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: Wonky specular in reflections (/thread-2619.html)
Wonky specular in reflections - TomorrowPlusX - May 23, 2008 05:24 AM
I've got simple planar reflection rendering, and by and large it looks pretty good. The reflection rendering is done by setting a householder planar-reflection transform after setting the camera transform and before setting lights and rendering scene geometry.
Diffuse lighting in reflections looks great, but specular is completely wrong. Here's a few screenshots:
Specular goes incorrect as the camera's distance from the reflection plane increases:
And specular approaches correctness as camera approaches the reflection plane:
Now, my guess is that what's wrong is that the camera's position is not reflected. This is screwing up my specular.
So, the way I see it, my only option is to take this into account in my shaders somehow. What's my best option?
Should I pass the planar reflection matrix if I'm rendering a reflection and an identity matrix if not? I'm not really certain what's the best way to fix this.
Wonky specular in reflections - DoG - May 24, 2008 02:37 AM
I suspect this has to do with a right vs. left handed coordinate system for the reflections, which messes with the normal calculations, but that doesn't really explain why things get better as you approach the reflection plane.
Wonky specular in reflections - PowerMacX - May 24, 2008 07:47 AM
Perhaps you are swapping the X & Y axes?
Wonky specular in reflections - TomorrowPlusX - May 28, 2008 04:11 AM
Sorry to have posted and run -- I've been busy. Holidays, birthdays, etc.
My gut feeling is that the reflection transform is, like DoG says, changing handedness. But for the life of me I can't come up with a rational solution. I've experimented a bit, but I'm going to post below the vanilla shader code, before I started experimenting.
The following are two lit non-textured simple shaders. I do multipass lighting, so this doesn't take into account emission or global ambient. And I also specialize on light type, so this is just directional lighting, not positional or spot ( though I see the same specular weirdness with those shaders too ).
Does anything jump out at you guys?
I'm beginning to despair of a solution here. I know there's a way to make this work, but my mind's drawing a blank. I suspect I've spent too long working on geometry and physics, and the part of my brain that handles GLSL has gone dormant
Wonky specular in reflections - Weebull - Jun 1, 2008 05:55 AM
I doubt it's anything to do with your shader as such, but more to do with the values being passed into it.
My gut instinct is the the normal is getting messed up somehow (or maybe not modified at all). I'd be debugging by setting the fragment colour to the normal, the eye vector, the reflection vector, etc, etc