I am using glsl to render a magic eye image in a compute shader, but there is a duplicate of the image, one in front of the background and one behind it. i learnt that you have to shift the 3d pixels to the left or right which is what i did but it creates another copy behind it
Example Of Broken Code
This Is Meant To Be An Image Of An Apple But There Is Another Copy That has the opposite depth of the main apple
The Depthmap Used
This Is My Glsl Code:
#version 430
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
layout(std430, binding = 0) buffer Input {
uint inputData[];
};
layout(std430, binding = 1) buffer StripBuffer {
uint stripData[];
};
layout(std430, binding = 2) buffer SizeBuffer {
uint SizeData[];
};
layout(std430, binding = 3) buffer Output {
uint outputData[];
};
void main() {
uint index = gl_GlobalInvocationID.x;
uint sizex = SizeData[0];
uint sizey = SizeData[1];
uint x = index % sizex;
uint y = index / sizex;
uint stripSizex = SizeData[2];
uint stripSizey = SizeData[3];
uint numStrips = sizex / stripSizex;
float Foffset = inputData[index] / 255.0 * stripSizex;
uint offset = uint(Foffset - 1.0);
uint outX = 0;
uint outY = y % stripSizey;
outX = (x + offset) % stripSizex;
uint value = stripData[outX * sizey + outY];
inputData[index] = value;
outputData[index] = (255 << 24) | (value << 16) | (value << 8) | (value << 0);
}
user22236292 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.