Search Issue Tracker
By Design
Votes
0
Found in [Package]
5.0.6
5.2.1
5.3.1
Issue ID
WBTRB-144
Regression
No
Height values of the terrain in specific areas are incorrect when height stamping is executed
How to reproduce:
1. Open the “TerrainBug“ project
2. Open the “SampleScene”
3. Click on the “Terrain” GameObject in the Hierarchy
4. In the Inspector, click on “Generate Bug” button
5. Observe the “Terrain” GameObject in the Scene view
Expected result: There are no borders or walls on the terrain
Actual result: There are two walls on the terrain
Reproducible with: 5.0.6 (2022.3.61f1), 5.2.1 (6000.0.47f1, 6000.1.0b14, 6000.2.0a9)
Reproducible on: Windows 10, Windows 11
Not reproducible on: no other environment tested
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- ”Last item reached” warning is thrown when no search results are found in UI Toolkit Layout Debugger
- UI Elements overlap in the Shortcuts window when docked and resized to a smaller window size
- UIBuilder DataSourcePath dropdown fails to show properties when binding to abstract classes
- Errors are logged when importing an asset at a path with Firebase
- Entering too big of a number in 2D Renderer Lightmode Tags freezes the Editor
Resolution Note:
Hello,
The problem occurs because your 60×60 terrain uses a 513×513 heightmap. Each heightmap pixel covers 60/512 = 0.1171875 world units, but the paint context must process all 513×513 pixels, creating total coverage of 513 × 0.1171875 = 60.117×60.117 world units.
Your brush covers exactly 60×60 world units, but the paint context extends to 60.117×60.117. This creates a coordinate mapping mismatch that Unity must resolve through scaling. Unity compensates for this mismatch by applying a scale factor of 513/512 = 1.001953 in the coordinate transformation, with _PCUVToBrushUVScales = 1.001953, 0, 0, 1.001953. This is done in TerrainPaintUtility.SetupTerrainToolMaterialProperties .
The shader transform uses the formula brushUV = pcUV × scaleFactors + offset. When the shader processes edge pixels where pcUV = 1.0 (representing the last row/column of the heightmap), the transform calculation becomes brushUV = 1.001953 × 1.0 + (-0.0009765625) = 1.0009765625. This result exceeds 1.0, placing it outside the valid brush texture coordinate range.
The out-of-bounds check all(saturate(brushUV) == brushUV) in PaintHeight.shader StampHeight function (located in the terrainTools package) detects this condition and sets the out-of-bounds multiplier to 0.0, effectively disabling the brush effect for these edge pixels. This creates the visual artifact where the outer edges appear unaffected by the stamp operation.
The issue is fundamentally that your brush doesn't cover the entire area that needs to be painted. To fix your issue, you should make your brush scale match the actual paint context coverage:
var terrainSize = Terrain.terrainData.size.x;
var heightmapRes = Terrain.terrainData.heightmapResolution;
var requiredBrushSize = terrainSize * heightmapRes / (heightmapRes - 1);