FreshRSS

Normální zobrazení

Jsou dostupné nové články, klikněte pro obnovení stránky.
PředevčíremHlavní kanál

Height gradient generation from height map,using compute shader has weird artifacts

I am trying to generate the height gradient (the slope) for a heightmap of mine using a compute shader in Unity, and the result has weird ringing artifacts and I completely lost what could be wrong. I thought about it being a precision issue, but increasing the magnitudes of the height values or moving to doubles from floats didn't solve the issue... Height map: height map I want to use for gradient calculation Resulting gradient map, with values of the Y axis in the green channel pictured here:ringing artifacts in the resulting gradient

I also exported the texture to disk to check in Photoshop, and the artifacts are also there so this isn't a display issue...

My compute shader is super simple:

SamplerState samplerInput
{
    Filter = MIN_MAG_LINEAR_MIP_NEAREST;
    AddressU = Clamp;
    AddressV = Clamp;
};

float3 calcHeightandGrad(int posX, int posY)
{
    float x = posX;
    float y = posY;
    float res = 2048 - 1;
    double sample = Input.SampleLevel(samplerInput, (float2(x, y) / res), 0).x * 100;
    double topSample = Input.SampleLevel(samplerInput, (float2(x, y - 1) / res), 0).x * 100;
    double rightSample = Input.SampleLevel(samplerInput, (float2(x - 1, y) / res), 0).x * 100;
    
    double dx = rightSample - sample;
    double dy = topSample - sample;
    
    return float3(sample, dx, dy);
}
❌
❌