'GPU Heightmap sculpting in shader
i have successfully done the sculpting implementation on CPU,
throw some guide on how to do this on GPU kindly …
i have moved the sculpting code to vertex shader but the sculpting is not accumulating in vertex shader and cant modify position in vertex shader… kindly tell me how …
if (SculptMode.x == 1)//Raise
{
float dist = length(int2(PickedPoint.xz) - input.position.xz);
if (dist <= BrushRadius.x)
{
PositionOffset += (BrushRadius.y * (cos(PI * dist / float(BrushRadius.x)) + 1.0f) * 0.5f) * DeltaTime.x * 10.0f;
input.position.y = PositionOffset;
}
}
I am using RWTexture2D for it like ...
if (SculptMode.x == 1)//Raise
{
float dist = length(uint2(PickedPoint.xz) - input.position.xz);
if (dist <= BrushRadius.x)
{
PositionOffset[int2(input.position.xz)] += BrushRadius.y * smoothstep(0, BrushRadius.x, BrushRadius.x - dist) * DeltaTime.x * 10.0f;
}
}
but still my sculpting is in spike formation ...
then
input.position.y = PositionOffset[int2(input.position.xz)];
Solution 1:[1]
While I can't say this for certain, it looks like your issue might be that you're just not reaching some pixels. If you show the whole shader and where you dispatch it I might be able to confirm. The way that you are indexing points in the texture could be the whole problem.
The other issue I can see being possible is that you are reading and writing from the same data structure (input) - while you only read from x and z, and only write to y, this could still cause trouble as xyz are still part of a single element, which gets set all at once.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Alexander Stewart |

