Нормальные артефакты фрагментного шейдера, появляющиеся на определенных c GPU - PullRequest
0 голосов
/ 04 августа 2020

Я вычисляю нормали из карты высот в кодировке RGB:

enter image description here

float unpackFactor = vec3(256.0 * 255.0, 255.0, 255.0 / 256.0);

float unpackOffset = -32768.0;

Therefore I edited the phong shader built-in dHdxy_fwd() function:

vec2 dHdxy_fwd() {
    float texelSize = 1.0 / 256.0;
    vec2 dSTdx = vec2(texelSize, .0);
    vec2 dSTdy = vec2(.0, texelSize);

    float Hll = bumpScale * dot(texture2D(displacementMap, vUv).rgb, unpackFactors) + unpackOffset;
    float dBx = bumpScale * dot(texture2D(displacementMap, vUv + dSTdx).rgb, unpackFactors) + unpackOffset - Hll;
    float dBy = bumpScale * dot(texture2D(displacementMap, vUv + dSTdy).rgb, unpackFactors) + unpackOffset - Hll;

    return vec2(dBx, dBy);
}

The decoding of the height, unfortunately, causes artifacts around the green channel of the texture – happening on iPhone 7, iPhone XS and the Radeon 455 dedicated GPU of my Mac:

enter image description here

Those artifacts look like this:

enter image description here

Zoomed in:

enter image description here

On the Intel HD Graphics 530 (integrated GPU), however, there are no such artifacts visible – it looks perfect just as it should (ignore the tile seams for):

enter image description here

Zoomed in:

введите описание изображения здесь

Почему на некоторых (большинстве протестированных) графических процессорах появляются артефакты? Есть идеи, как от них избавиться? Похоже на некоторую числовую нестабильность, но я возился с точностью текстуры, сжав общее значение высоты, et c. пока не повезло.

...