-
-
Notifications
You must be signed in to change notification settings - Fork 21.1k
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
Implement vertex shading #83360
Implement vertex shading #83360
Conversation
mmm I guess I did vertex shadow not vertex lighting, fixing it. Edit : lol, it is actually the opposite, shadow calculation should be added in vertex. |
I guess I need an advice from the Rendering Team, currently I am almost duplicating functions for the vertex-shading, should I just use Preprocessor to move every thing to vertex shading, or should I keep duplicating the stuff, because we may remove features from the vertex shading ? |
Regarding why the second light with shadows disappear, remember that Godot 4's GLES3 performs multipass lighting if you use multiple lights with shadows. This is different from Godot 3 GLES3 (and more comparable to Godot 3 GLES2, although it used multipass for non-shadowing lights too).
Yes, real-time shadows can't be received by vertex-lit surfaces. Only baked lightmap shadows can be seen on them. In GLES3 (unlike GLES2), it should be possible to sample the shadowmap texture in |
so do you think I should remove shadows from vertex-lighting ? |
I think you can remove them for now. Support for receiving shadows in vertex-lit materials can be implemented in a future PR (if it's feasible at all) 🙂 |
Now Compatibilty/GLES3/OpenGL Rendering should be ready for Vertex-Lighting testing and regression testing. I will continue work on Vulkan Mobile + Vulkan Forward+ |
My comment on shadows for vertex lighting : I think it is possible to cast shadows using vertex_shading. But I think vertex shading is mainly useful for performance reasons, and probably realtime shadows are costly. So it doesn't make a lot of sense to have realtime shadows in vertex lighting. I may implement shadows in another PR if there is a demand for it. Personally I don't need shadows in my game for vertex lighting. |
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. This is a great start 🙂
Testing projects:
There are some rendering issues:
- When using Forward+, vertex lighting doesn't render unless you get very close to the light node (the objects far away use per-pixel shading for comparison):
simplescreenrecorder-2023-10-19_20.03.01_forward_plus.mp4
This may be related to the light clustering system.
- When using Mobile, vertex lighting occasionally flickers in and out on specific objects when moving the camera (this may be hard to reproduce):
simplescreenrecorder-2023-10-19_20.04.02_mobile.mp4
In the testing project, the plane is subdivided so it can receive vertex lighting correctly.
Another issue is that when using lightmaps, DirectionalLights with the Static bake mode still affect lightmapped surfaces:
Current appearance | Expected appearance (light is hidden) |
---|---|
This isn't an issue with omni or spot lights. You can hide the directional light after baking as a workaround, but then it won't affect dynamic objects.
@Calinou |
Recording.2023-10-20.162439.mp4It seems some polygons become unlit if they become partially out of view? EDIT: I am on Forward+ by the way. |
@AnalogFeelings Yes this happens to me too, I think this is light clustering in Forward+ and not a bug. Maybe calinou knows. |
I also noticed setting the viewport to lighting only causes HEAVY artifacts. SPOILER_20231020-1433-32.5621820.mp4 |
Interesting, I'll check it out. |
Lighting mode replaces all materials in the scene with a basic ShaderMaterial that uses per-pixel lighting (it might just be the fallback material). It can't know whether the original material used vertex shading or not. The Lighting debug draw mode's appearance will probably have to be toggled with a project setting. |
Just fixed some bugs that I noticed from my work. |
This PR has been rebased, squashed, and fixed up! It should be ready to merge anytime now. I have tested it with the following:
I believe that covers all the permutations in the shaders. At any rate, I think it is broad enough coverage that I feel confident this is ready to merge PerformanceUsing Calinou's test project and an intel i7-1165G7 with integrated graphics. To be clear, the goal of this PR is not necessarily performance. Ideally performance would improve, but these days the benefit of vertex shader is mostly for people who want to recreate styles from older games Forward+
Mobile
Compatibility
|
I have tested the new changes, everything works great except that now no shadows for vertex lighting in Forward+/Mobile ? |
For positional lights ya. This is the same limitation we had in Godot 3 GLES3. There isn't a way to accurately calculate shadows for all light types when doing single pass rendering. We discussed this on the rendering chat and agreed with sticking to the same limitation as Godot 3, which is that the first directional light in the scene tree can cast shadows. All other lights won't have shadows. For the Compatibility renderer all lights can cast shadows since it does multipass lighting. |
Just tested it out, it works great. Thanks a lot for the hard work. |
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 in all rendering methods.
I've also tested vertex shading combined with SDFGI, VoxelGI and ReflectionProbe and it looks correct. Note that the appearance of GI techniques is not affected by vertex shading, but real-time lights are still affected as expected.
I noticed an oddity when Force Vertex Shading is enabled on surfaces that receive VoxelGI or SDFGI though: Per-vertex shadingPer-vertex shading on a per-pixel material with Force Vertex Shading enabledNotice how per-pixel shading still appears to be partially used. The vertex-lit specular lobe is also missing. I restarted the editor after enabling the setting. Per-pixel shadingNo visual difference is seen on surfaces that don't receive VoxelGI or SDFGI. For context, I'm working on a follow-up PR that modifies the |
@Calinou Can you share that test project? I'm not sure what would cause that other than, perhaps VoxelGI is overwriting the color somehow |
The test project is test_pr_83360.zip (same as the one I used previously) with SDFGI enabled, or VoxelGI added and baked at its default position and extents. I reduced the material's roughness value to a value around 0.5 and increased metallic to 1.0. |
For release maintainers: This is fine to merge as is (once conflicts are resolved), the oddity noticed by Calinou is not critical and can be looked at in a follow-up issue/PR. |
0f26a12
to
068a48e
Compare
So rebased to reslove the conflicts, @clayjohn the issue was with this section https://github.com/godotengine/godot/pull/83360/files#diff-94158bc3d510819bb8d7ebd62a8890eeebad49608d9e934d148b73b6b65aeff9L1422 which you removed anyway previously so I just accepted the incoming result "the vertex shading commit changes" also for some reason your name does not show again in the commit even though I didn't change anything in the commit message ?! can this be solved ? |
That makes sense. It looks fine now
I'm not sure why that is. I wouldn't worry about it, the attribution is in the commit message anyway |
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.
Ready to merge :)
This adds support in all backends, but the Compatibility renderer works the best. Mobile and Forward+ can only support one directional light shader (the first in the tree) While the Compatibility renderer supports any number of shadows. Co-authored-by: Clay John <[email protected]>
068a48e
to
0a9ad8f
Compare
That was because the commit description was missing a separation line between the first paragraph and the "Co-authored-by:" line. GitHub is very picky about this, that line needs to be properly separated from the rest of the commit message. I amended the description to fix it. |
Would be nice if more flexibility were given to this over time,, for example Toon Shading with vertex-shading. Funfact Wii is essentially a repackaged Gamecube, the big differences are.. more RAM and better GPU for the Wii but anyway what i meant is the vertex shading mode should be able to handle more than just a basic diffuse shader |
Implements Vertex Shading
resolves #43093
Bugs :
Vertex Shading receives shadows from one light source in GLES3No Shadows will be casted in Vertex Lightingvarying
in gdshader, it errors outNote: This PR implements Vertex-Lighting without shadows.Note: This PR implements Vertex-Lighting with Pixel-Shadows.
Production edit: Pixel shadows are only available for the first DirectionalLight3D in the scene. Omni and spot lights cannot cast shadows on vertex-shaded materials (like in Godot 3.x), except in the Compatibility rendering method where lights with shadows are rendered with a multipass approach.