-
Notifications
You must be signed in to change notification settings - Fork 135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Right-Handed Projection Matrix #3
Comments
It is correct that the library currently only works with right-handed coordinate systems. The only other place where the winding order should matter is in the computation of the hemisphere/hemicube direction here: What exactly does your coordinate system look like? |
What I'm actually doing is porting lightmapper to bgfx: And the projection functions in bgfx default to left-handed (I think X and Y are the same but Z goes into the screen instead of towards you). Below is a comparison of lightmaps produced by the original + 3 variations from my port. The right-hand projection is pretty close, just a few artifacts to try to clean up. The left-hand projection is darker than the right-hand one and swapping v1 and v2 seems to have made things worse. Original (from lightmapper): BGFX port with right-hand projection: BGFX port with left-hand projection: BGFX port with left-hand projection + v1 and v2 swapped: |
"What I'm actually doing is porting lightmapper to bgfx" The lightmapper rotates the hemi-cubes according to a 3x3 lightmap pixel pattern and adds some jitter to the rotation by calling rand(). This prevents banding artifacts at low hemi-cube resolutions and introduces noise instead which can be filtered reasonably well in postprocessing steps. It seems very odd to me that both left-handed solutions result in similar results (even if darker) at all. Can you show what your mesh looks like and what the output of the lightmapper is without any postprocessing? Do you plan to open source your code? |
My port is actually behind a bit and I don't yet have your changes merged that added interpolation. I plan to add them over the weekend. Perhaps that will change the situation. I do plan to release it, and under the same license as you did. My only delay was that I wanted to get it fully functional before releasing, but I think either way I'll put the code up this weekend. I'll let you know when it's up. |
The added interpolation shouldn't fix the problems... Thanks for planning to open source it :) |
Hey, sorry for disappearing I had some life things get in the way of personal projects. Anyway, I've pushed my bgfx port here: https://github.com/andr3wmac/bgfx as example number 32. You can find the actual ported lightmapper.h here: I assume you're unfamiliar with bgfx, the build instructions are here if you need them: DX11 is the only working API at the moment. |
No worries. I'm on holidays anyway :). I will return in about 24h and will look into this over the following days. The header/license is totally fine :). It is PD anyways. I know about bgfx, but never got to use it. This would be a perfect occasion :). Thanks! |
I ran your code and was able to exactly reproduce your first result. The computation was quite slow though. Now going to learn some bgfx and try to understand your changes :). Since I will be somewhat busy over the next few days, this may take a while... |
I believe the source of the slowness is the fact that after filling up the available views in bgfx, we have to call bgfx::frame() to submit the work and that causes a backbuffer flip. Branimir (bgfx author) is planning to add a variation that won't present at the end to avoid this. No worries on the time, I'm not in a rush. |
Okay, thanks! That's good to know. |
I believe both problems (the slightly darker result and the artifacts) could be caused by the translation to floating point sampling coordinates in the shaders and bilinear interpolation instead of nearest sampling. |
Hey thanks for looking into that. I had wondered if that was impacting it. The hemisphere textures are initialized with BGFX_TEXTURE_MIN_POINT | BGFX_TEXTURE_MAG_POINT, so they should be using point sampling. Even with float coordinates that should have the same net effect, no? The reason I avoided texelFetch is because its only available in the later OpenGL versions and I wanted to try to have support for all the APIs. For instance there is no equivalent for DX9. |
The projection matrix code in lm_setView is right-handed. When used in a renderer that's left-handed the culling has to change based on whether its a lightmap render or a regular scene render. Could you add a setting, perhaps in lmCreate, where left/right handedness could be specified?
Also, does the library make that assumption, or any other assumption about handedness/winding order/culling anywhere else? I ask because I switched the projection function to left-handed and the result was darker leading me to believe the library relies on that handedness to some degree.
The text was updated successfully, but these errors were encountered: