“Black border problem” in Compute Shaders

von Jens -

Ein Bild

“Black border problem” in Compute Shaders

Have you ever seen black borders in the resulting images of your compute shaders? Here is the solution!

The following image demonstrates what the problem is. Black pixels at the borders of images created oder altered with a compute shader.

The problem is caused by the division of two integer type numbers. Usually the compute shaders are dispatched by using the dimensions of the image divided by the local_size values of the compute shader (example below).

layout (local_size_x = 16, local_size_y = 16) in;
Dispatch(cmd, image.Width / 16, image.Height / 16, 1);

This calculation is usually a division with a remainder as these are integer values. So if there is a remainder the group counts do not use all pixels of the image for the calculations. The solution is just to add 1 to each of the dimensions.

Dispatch(cmd, image.Width / 16 + 1, image.Height / 16 + 1, 1);
Ein Bild
Compute ShaderVulkan

Diesen Beitrag Teilen

Über Jens

Hi! Ich bin Jens, Doktor der Naturwissenschaften! Als Doktorand in Anorganischer Chemie an der Technischen Universität Braunschweig erforschte ich in der Arbeitsgruppe von Prof. Dr. Martin Bröring die faszinierende Welt der Porphyrinoide. Diese Strukturen, inspiriert von der Natur, stehen hinter lebenswichtigen Molekülen wie Häm, dem roten Blutfarbstoff, und Chlorophyll, dem grünen Pflanzenfarbstoff. Neben der Wissenschaft gehört die Softwareentwicklung zu meinen Interessen. Meine Reise begann mit einer frühen Faszination für die Softwareentwicklung, die in der Schule mit dem programmierbaren Taschenrechner geweckt wurde. In meiner Zeit als Doktorand kombinierte ich meine Forschung mit der Entwicklung von Software, um wissenschaftliche Erkenntnisse voranzutreiben.

[object Object]