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

Terrain brush precision controls #661

Merged
merged 12 commits into from
Jul 3, 2024
Merged

Conversation

b-guild
Copy link
Contributor

@b-guild b-guild commented Jun 30, 2024

I have overhauled the terrain to give the user more precise control over terrain editing. This includes:

  • Separating out the target of the brush operation from the mode, so now the user can perform all the same operations on masks as they can perform on heights.
  • Hardness: The strength of a brush can now fade as it gets further from the brush's center. When hardness is 0, it means the fade starts at the center. Hardness of 1 means there is no fade all the way to the edges. Negative hardness causes to fade to start even before the center.
  • Alpha: All brush modes now support an alpha value that allows the original value of the texture to be averaged with the value produced by the brush operation. This includes height operations, to allow the user to make subtle adjustments in height by setting alpha near to 0. Negative alpha causes the effect of the brush to be inverted while alpha greater than 1 amplifies the brush's effect.
  • Transform matrix: Allows the brush's shape to be linearly transformed, so that circular brushes can be stretched and skewed and rectangular brushes can be rotated to any angle. This required the addition of a property editor for a 2x2 matrix.
  • Uniformity across each brush stroke: An brush operation is applied once across the whole of the brush stroke from the moment the user presses down the mouse button until the mouse button is released, not once for each mouse motion event. This means that brush operations do not accumulate if the mouse is wiggled in one place, and if the brush is dragged across areas already covered by the current stroke, the brush operation is still applied only one in those areas. This gives the user finer control over precisely where each brush operation is applied.
  • Brush smearing: Instead of just repeatedly stamping the brush shape at each mouse position, when the mouse moves a smear of the brush shape is created from the brush's previous position to its new position, filling in all the space between the two positions and creating a continuous brush stroke regardless of how quickly the user drags the mouse. This required the creation of a line segment module in the math library.
  • Multi-threading: Much of each brush operation is performed in a background thread. This allows the user to perform large and complex brush operations without concern for causing the editor's UI to lag. When the operation is slow, the brush still moves smoothly, even if the brush's effect upon the terrain lags behind the brush. This is especially noticeable when the brush mode is set to "Smooth" with a large kernel size.

Brush modes now include:

  • "Raise or Lower" which adds or subtracts a fixed amount from everything the brush touches,
  • "Assign Value" which sets everything the brush touches to a given value,
  • "Flatten" which sets everything the brush touches to match the value the brush first touches. The value that flatten uses is no longer stored in the mode enum, since setting that value is not part of the brush mode.
  • "Smooth" which calculates an average from the surrounding pixels everywhere the brush touches. The radius of surrounding pixels can be chosen by the user. This is called the kernel radius.

Each brush stroke now keeps track of which chunks it touches, and copies are made of the relevant texture of each chunk before the texture is modified, allowing the undo command to now keep copies of only the modified textures rather than textures for every chunk.

@mrDIMAS
Copy link
Member

mrDIMAS commented Jun 30, 2024

Very cool, thank you! The PR seems to be quite big and will take a day or so to review it, I'll try to do this quickly.

@b-guild
Copy link
Contributor Author

b-guild commented Jun 30, 2024

There is no rush. The automated CI test has revealed a potentially serious problem with the brush rasterization that was not apparent when I was playing with the brushes in an open editor. I am going to need time to track down the source of the problem.

Edit: It turned out to just be a small bug in the test, not a problem in brush rasterization at all.

@b-guild b-guild marked this pull request as draft June 30, 2024 20:27
@b-guild b-guild marked this pull request as ready for review June 30, 2024 20:38
Copy link
Member

@mrDIMAS mrDIMAS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is hard to grasp such amount of code at review, so I basically checked for obvious mistakes and there are two tiny comments.

fyrox-impl/src/scene/terrain/brushstroke/mod.rs Outdated Show resolved Hide resolved
fyrox-impl/src/scene/terrain/mod.rs Outdated Show resolved Hide resolved
@mrDIMAS mrDIMAS merged commit b0d86b0 into FyroxEngine:master Jul 3, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants