-
Notifications
You must be signed in to change notification settings - Fork 2.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
Clip posteffect color to respective nodes #15055
base: master
Are you sure you want to change the base?
Conversation
PR is ready for review now! |
6078e4a
to
54f46c3
Compare
Squashed and rebased. |
54f46c3
to
ad86e0f
Compare
Rebased. I noticed the polygons aren't drawn with the "opengl3" video driver, because it has no |
ad86e0f
to
5ce0473
Compare
Fixed. (Also, trivially rebased.) |
198164c
to
6a1c184
Compare
6a1c184
to
3078a20
Compare
Trivially rebased, and removed the no-shader workaround, thanks to #15421. |
FWIW if someone were to work on batching all the 2D drawcalls we have, this function would have to be implemented anyway. |
3078a20
to
4f1cb53
Compare
Rebased.
(I'm still not doing that in this PR, fyi, for complexity reasons, and because the current method used here works.) |
@Desour rebase needed |
4f1cb53
to
e3ff58a
Compare
Thanks for the notification! Rebased. |
e3ff58a
to
07b1776
Compare
Rebased. |
(disregard me mentioning this PR, it's unrelated, I was too hasty) |
Screenshots
If there's no backface:
Posteffect fullscreen plus shaped:
A thin line between:
Torch triggers different triangulation of water (not new in this PR. but PR needs to take this into account):
How it works
In master
For comparison, in master, the camera position is used to determine node whose post effect color should be used. Then a rectangle is drawn over the whole screen. It is drawn after the 3D scene and after the wield hand.
In PR
For PR, imagine how the near plane lies in the world. Because it is small, it will only intersect with nodes in a 2x2x2 block around the camera pos.
If the near plane intersects with a node, the respective are on the screen is inside the node, and needs posteffect. We want to draw a shape with the posteffect color for this area.
Wieldhand
If we drew the wieldhand before the posteffect shapes, the wieldhand would often be partly covered by such a shape, which is ugly. This is why the wieldhand is rendered after the posteffect step.
To color the wield hand appropriately, there's a new uniform for the object shader (used for wieldhand).
If the whole screen is filled with one posteffect color, it looks exactly like in master.
If shaders are off, the node light color is abused. It looks different. But shaders off support will be dropped soonish anyways.
How the shapes are determined
Imagine a node with drawtype normal for now, it is just a cube. More generally it is a convex polytope. A convex polytope is just an intersection of a bunch of half spaces, given via oriented planes, which are represented by 4D vectors.
These planes are transformed to clip space, and the intersection with the near plane (an oriented 2D line) is gotten (see
clip_polygon_by_objsp_plane()
).To get the shape, we start with a rectangle filling the whole screen, and then cut off parts of it with one of the oriented 2D lines from above (see
ConvexPolygon::clip()
). The result (and all steps in between) are a convex polygon.In the general case, we have more than one convex polytope for a node, and end up with multiple convex polygons.
A note about liquids
Liquids (e.g. water) can wave. The vertices at the top are moved up and down. It's still just two convex polygons. We cut the node by it's top face quad diagonal, which depends on lighting. There's also flowing liquid. Most of the changed lines outside of
clientmap.cpp
are devoted to either exposing the necessary information for this, or to coloring the wieldhand.Other drawtypes
For the sake of backwards compatibility, other drawtypes than flowing liquid, liquid source, and normal still work similar as in master: They fill the whole screen and are only drawn if and only if the camera is inside the node.
This means that multiple post effect polygons can overlap. Check out the screenshots to see how this looks like.
Known issues
The wield shading doesn't work correctly without shaders.We no longer support the fixed function pipeline./teleport 30140 0 10
for example. (Idk why.)Possible future PRs
To do
This PR is ready for review.
How to test
enable_shaders
,enable_waving_water
,water_wave_*
,3d_mode
, noclip,smooth_lighting
, camera mode (1st pers, 2nd pers, 3rd pers),video_driver