Code Monkey home page Code Monkey logo

Comments (5)

Zylann avatar Zylann commented on June 9, 2024 2

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

from godot_heightmap_plugin.

Zylann avatar Zylann commented on June 9, 2024

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.

from godot_heightmap_plugin.

bakase avatar bakase commented on June 9, 2024

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

from godot_heightmap_plugin.

Zylann avatar Zylann commented on June 9, 2024

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

from godot_heightmap_plugin.

bakase avatar bakase commented on June 9, 2024

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.

from godot_heightmap_plugin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.