How to stop PImage flickering in 3D
in
Programming Questions
•
1 year ago
Apologies if this is an obvious question, but I can't work it out:
I've made a basic 3D scene, using PImage to render textures on the sides of simple cubes. That's all fine, but I'm using lots of shapes, many of which are very near each other. Sometimes when they get too near, they start to flicker. For an example, I've uploaded a test render to www.youtube.com/watch?v=N4j2i5LJIaU. You can see some of the flickering at, eg. 6:30.
So it's basically when two flat PImages are almost occupying the same space, they flicker. I've tried to make them always be a few pixels apart, but I still get a bit of flickering.
Any ideas would be welcomed. Thanks.
Here's the class I'm using for each cube:
class textBox{
int x, y, z, w, h;
String myTexture;
PImage myImage;
PImage myRoof;
textBox(int _x, int _y, int _z, int _w, int _h, PImage _myTexture){
x = _x;
y = _y;
z = _z;
w = _w;
h = _h;
myImage = _myTexture;
// The roof of every boz has the same texture
myRoof = loadImage( "skyscrapers/myRoof.jpg" );
}
void update(
int x, int y, int z, int w, int h, int d){
// Render boxos
// Top
pushMatrix();
translate( x, y, d );
image( myRoof, - (w /2 ), - (h /2 ), w, h);
popMatrix();
// Bottom: no need to render this, as it is never visible
// pushMatrix();
// translate( x, y, z );
// image(myImage, - (w /2 ), - (h /2 ), w, h);
// popMatrix();
// Side 1
pushMatrix();
translate( x - (w / 2) , y , 0);
rotateY(-PI / 2);
image(myImage, x, y - (h /2 ), d, h);
popMatrix();
// Side 2
pushMatrix();
translate( x + (w / 2) , y , 0);
rotateY(-PI / 2);
image(myImage, x, y - (h /2 ), d, h);
popMatrix();
// Side 3
pushMatrix();
translate( x , y - (h /2 ), 0);
rotateY(-PI / 2);
rotateX(-PI / 2);
image(myImage, x, y - (w /2 ), d, w);
popMatrix();
// Side 4
pushMatrix();
translate( x , y + (h /2 ), 0);
rotateY(-PI / 2);
rotateX(-PI / 2);
image(myImage, x, y - (w /2 ), d, w);
popMatrix();
}
}
I've made a basic 3D scene, using PImage to render textures on the sides of simple cubes. That's all fine, but I'm using lots of shapes, many of which are very near each other. Sometimes when they get too near, they start to flicker. For an example, I've uploaded a test render to www.youtube.com/watch?v=N4j2i5LJIaU. You can see some of the flickering at, eg. 6:30.
So it's basically when two flat PImages are almost occupying the same space, they flicker. I've tried to make them always be a few pixels apart, but I still get a bit of flickering.
Any ideas would be welcomed. Thanks.
Here's the class I'm using for each cube:
class textBox{
int x, y, z, w, h;
String myTexture;
PImage myImage;
PImage myRoof;
textBox(int _x, int _y, int _z, int _w, int _h, PImage _myTexture){
x = _x;
y = _y;
z = _z;
w = _w;
h = _h;
myImage = _myTexture;
// The roof of every boz has the same texture
myRoof = loadImage( "skyscrapers/myRoof.jpg" );
}
void update(
int x, int y, int z, int w, int h, int d){
// Render boxos
// Top
pushMatrix();
translate( x, y, d );
image( myRoof, - (w /2 ), - (h /2 ), w, h);
popMatrix();
// Bottom: no need to render this, as it is never visible
// pushMatrix();
// translate( x, y, z );
// image(myImage, - (w /2 ), - (h /2 ), w, h);
// popMatrix();
// Side 1
pushMatrix();
translate( x - (w / 2) , y , 0);
rotateY(-PI / 2);
image(myImage, x, y - (h /2 ), d, h);
popMatrix();
// Side 2
pushMatrix();
translate( x + (w / 2) , y , 0);
rotateY(-PI / 2);
image(myImage, x, y - (h /2 ), d, h);
popMatrix();
// Side 3
pushMatrix();
translate( x , y - (h /2 ), 0);
rotateY(-PI / 2);
rotateX(-PI / 2);
image(myImage, x, y - (w /2 ), d, w);
popMatrix();
// Side 4
pushMatrix();
translate( x , y + (h /2 ), 0);
rotateY(-PI / 2);
rotateX(-PI / 2);
image(myImage, x, y - (w /2 ), d, w);
popMatrix();
}
}
1