Search Issue Tracker
By Design
By Design in 5.3.X
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
- Required SpriteMask class (ID 331) is stripped when "Strip Engine Code" is enabled
- “Maximized serialized file backup not found” error is thrown when minimizing a window in a newly opened project
- Build stack trace contains invalid lines when building with IL2CPP using scripts with delegates containing generic types in the signature
- Entities Systems window has a “Show Full Player Loop” dropdown which does nothing when clicked after enabling “Show Full Player Loop”
- Entities Hierarchy Search “Show/Hide” button’s Lens Icon is blurry when the Editor is on an external monitor
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);
Resolution Note (5.3.X):
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);