简体   繁体   English

GPU 在着色器中雕刻高度图

[英]GPU Heightmap sculpting in shader

i have successfully done the sculpting implementation on CPU,我已经成功地在 CPU 上完成了雕刻实现,

throw some guide on how to do this on GPU kindly …请在 GPU 上提供一些有关如何执行此操作的指南......

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 …我已将雕刻代码移至顶点着色器,但雕刻未在顶点着色器中累积并且无法在顶点着色器中修改 position ......请告诉我如何......

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...我正在为它使用 RWTexture2D ...

    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)];

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.我可以看到的另一个可能的问题是您正在从相同的数据结构(输入)读取和写入 - 虽然您只从 x 和 z 读取,并且只写入 y,但这仍然会导致麻烦,因为 xyz 仍然是单个元素,一次性设置。

changed implementation to completely different method, this wont work as i think this quantization is happening because there are vertex which are shared among triangles and sculpting adjustment is applied multiple times to same vertex, that is why spikes…将实现更改为完全不同的方法,这不会起作用,因为我认为这种量化正在发生,因为三角形之间共享顶点并且雕刻调整多次应用于同一顶点,这就是尖峰的原因......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM