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
- Crash on mono_dump_native_crash_info when changing a Particle System Renderer’s Material Shader to Standard Unlit
- VFX Prefab doesn’t have Preview icon in Project window and Preview window is empty in Inspector window
- Visual Effect Graph error message does not disappear and lasts forever until the Visual Effect Graph is reopened even when the error causing connection/node is deleted and Visual Effect Graph is saved
- “RenderSettings customReflection texture has invalid type” error keeps getting thrown even when Environment Reflections was set back to Skybox from Custom with an invalid texture
- Particle System with the custom Material breaks the Scene view when the material is using a Shader Graph with the Texture with the power of negative value
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);