-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
OpenGL: Implement rendering of lightmaps #85120
Conversation
FYI, here's some images of the visual differences... In both, you can see some "lines" by the edges of the triangles, but it's much more noticeable on the Compatibility renderer, and the light seems dimmer overall. I'm surprised that the difference is so big (at least relatively speaking) given that it's the exact same lightmap (it was baked with the editor using the Mobile renderer) and the exact same shader math (I copy-pasted it from the Mobile renderer). Any advice would be appreciated! |
This is due to sRGB vs linear rendering. The mobile renderer has higher precision available (RGB10A2 with 2.0 maximum exposure). Compatibility is RGBA8, which is similar to Godot 3.x GLES2. This result looks 100% expected to me – as good as it can be when using RGBA8 sRGB rendering, that is. To get a better result, you can play with the Tonemap properties in Environment depending on the rendering method, as visual differences in tonemapping between rendering methods are expected (though Forward+ and Mobile are usually close to each other).
The lines are due to bilinear interpolation coupled with low lightmap texel density, which makes it obvious. Godot 4.x doesn't support bicubic sampling in lightmaps yet, unlike Godot 3.x where it's present and enabled by default. |
@Calinou Ah, thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested locally, it mostly works as expected.
Testing project: test_lightmapgi_opengl.zip
One issue is that light sampling for all light types isn't skipped on meshes that use the Static global illumination mode and have had lightmaps baked on them. This is done by design when using Forward+ and Mobile to avoid double lighting and improve performance.
Edit: I noticed Mobile has broken behavior too. --rendering-method mobile
doesn't actually work, even though the command line output says it's using Vulkan Mobile… it keeps using Forward+ if the project is configured to do so.
Forward+ | Mobile | Compatibility |
---|---|---|
The torus closest to the camera uses the Disabled GI mode, while the torus on the back uses the Dynamic GI mode. The rendering issue on Mobile is tracked in #84846.
Dynamic object lighting also appears to not influence the object enough compared to other rendering methods.
@Calinou Thanks for the feedback!
I think this is fixed in my latest push. It got kind of messy, because there's just so many ways a light can be rendered, so there needed to be checks in a whole bunch of places. Also, I had to add 16 bytes to the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested locally, it works as expected. Light shadow sampling for static lights is now skipped on lightmapped surfaces. This brings performance up from 1600 FPS (0.62 mspf) to 2050 FPS (0.48 mspf) in 4K on a RTX 4090 in the testing project linked above.
It also works in the web export (FPS is V-Synced to 120 Hz):
Also working on a Samsung Galaxy Z Fold4 running Android 13:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That really weird :-/ I just recompiled (after making the suggested I'm not sure what could be the difference. I'm on Linux with an nvidia card. What's your environment like? |
On linux with an intel integrated GPU |
Ah, I just tried rebasing on master, and now I'm seeing what you're seeing too. |
Diff with the fix:
In the end this wasn't really a regression. The case of UV2s just needed special handling as they can be accessed either by the shader, or inside the shader with a particular specialization constant. So we need to ask for UV2s whenever we enable the spec constant that needs them. Prior to #85092 we just used all vertex arrays all the time which was bad for performance |
Thanks so much! Your patch fixes it in my testing too, so I've rebased, added your patch and pushed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! Tested locally with Calinou's test project and I can confirm it now works.
Thanks! |
This PR aims to add rendering of lightmaps (via
LightmapGI
) when using the GL Compatibility renderer.Note: This doesn't add lightmap baking when using the GL Compatibility renderer. Lightmaps still need to be baked using Vulkan.
This marked as a draft because while it's "working", the result looks worse than I'd expect. I want to see if I can get to the bottom of that first.UPDATE: Eh, it looks good enough to get some review :-)UPDATE 2: In a comment below, @Calinou (who knows rendering much better than me) says it looks as good as he'd expect given the way the Compatibility renderer works, so I guess this just needs code review now!