Skip to content
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

Issue where the positions of the cursor and brush do not match #400

Open
bakase opened this issue Sep 23, 2023 · 5 comments
Open

Issue where the positions of the cursor and brush do not match #400

bakase opened this issue Sep 23, 2023 · 5 comments
Labels
bug Something isn't working

Comments

@bakase
Copy link

bakase commented Sep 23, 2023

The position of the cursor and the brush are different.
Look inside the red square area.

The farther away you are, the more out of place it becomes.

When you work in that state, the action occurs at the position of the cursor.
sdfdsfsdfdsfdsf

godot 4.1.1 hterrain 1.7.2 win10 gtx1070

@Zylann
Copy link
Owner

Zylann commented Sep 23, 2023

Looks like this happens specifically when using very small brush size and very close to the terrain. Looks also like an issue with the decal rather than the functionality, since you noticed it still performs the action at the right position.

@Zylann
Copy link
Owner

Zylann commented Sep 23, 2023

The issue happens because that decal was implemented at a time Godot did not have any decal system. Therefore, it's actually a small plane placed just above the terrain. That works well enough for common usages, however:

image

The downside of that is that if you are very close with a tiny brush, the offset becomes too apparent, leading to that discrepancy. You can especially notice with a cube rendered at the location of the decal.

There are some solutions, but they all have drawbacks:

  • Reduce displacement in the decal shader: there is a number that can be be reduced in decal.gdshader so that the cursor is rendered closer to the terrain. However this doesn't work on slopes, because there isn't enough geometry to cover error margins (needs some investigation though, maybe there is something to improve here):
    image

  • Render cursor directly with the terrain shader: while efficient, this has a number of annoying drawbacks regarding shader maintainance:

    • It requires every terrain shader to include code and parameters to position and render the cursor (there are more than one shader this plugin provides)
    • As a result, it also requires to somehow remove that extra code when exporting the game, because that would be unnecessary overhead to process editor-only features there. Does Godot have a predefined shader #define symbol telling whether it runs in editor at least?
    • It requires users with custom terrain shaders to also include that code just so they can see the cursor
  • Use an actual decal: Godot 4 added decals, which then could be used instead. However, by default, decals would project on everything, including all things placed on top of terrain. That could be solved by putting terrain in a specific render layer, but that also messes with the choice of layers users might have made. At the very least, it requires to reserve a specific render layer for terrain ground, just to fix that discrepancy, hoping users don't need that layer for other things...

  • Disable depth-test: if the issue is clipping with ground, we could disable depth-testing and remove the vertical offset so that the cursor always renders on top, even if it is behind stuff. The drawback is like with decals: it will still render even if there are props in front, including grass.

image

@Zylann Zylann added the bug Something isn't working label Sep 23, 2023
@bakase
Copy link
Author

bakase commented Sep 23, 2023

decal.gdshader .......
...........
......

depth_test_disabled
.
.
//VERTEX += 1.0 * n;
.
Turned off Z-depth testing and removed adjustment of specific displacement values.
I like this setup.

thank you

@Zylann
Copy link
Owner

Zylann commented Sep 23, 2023

I found the decal didn't apply a half-pixel offset terrain shaders are applying (therefore heights of the decal were slightly off).
That fixed some of the issues with reducing the distance from ground, but still wasn't good enough on higher slopes.
So I also increased the amount of subdivisions at low brush sizes, and dynamically adjusted distance from ground based on the size of the brush, and now it looks mostly fine.

Did the changes in 616088d

@bakase
Copy link
Author

bakase commented Sep 23, 2023

I plan to just slightly modify the current shader.
.
It seems like a change occurred in decal.gd...
.
First of all, I plan to use a slightly modified version of the shader.
.
This is pretty good too ^^
.
If hterrain is updated to a later version, I will update the entire thing at that time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants