Visual bug when having a light follow the camera position

Hi,

I’m having a weird issue when setting up the ofLight position at the same one of my Camera,
I have tried ofEnableLighting and ofSmoothLighting.

Light Stuff

I’ve narrowed down the code to a test project to get easy repros and see if it was caused by something in my initial project.

my main

ofGLFWWindowSettings settings;
settings.resizable = false;
settings.setSize(1440, 900);
settings.setGLVersion(3, 3);
ofCreateWindow(settings);
return ofRunApp(new ofApp);

my .h

class ofApp : public ofBaseApp{

	public:
		void setup();
		void update();
		void draw();


		ofEasyCam camera;
		ofLight light_spot;

		ofMaterial material;

		ofBoxPrimitive box;
		
};

my .cpp

void ofApp::setup() {



	ofSetSmoothLighting(true);

	material.setShininess(120);
	material.setSpecularColor(ofColor(255,255,255,255));
	material.setDiffuseColor(ofColor(255, 255, 255, 255));

	box.set(25);

}

void ofApp::update() {
	light_spot.setPosition(camera.getPosition());


}

void ofApp::draw() {

	ofEnableDepthTest();
	light_spot.enable();
	camera.begin();

	material.begin();
	box.setPosition(0, 0, 0);
	box.draw();
	material.end();

	light_spot.disable();
	camera.end();
	light_spot.disable();
	ofDisableDepthTest();
}

seems ok here. maybe something related to the GPU and specific platform?

That could be possible, thanks for checking.

Hey @Frank1 , this is kinda interesting! It reminds me of an interference pattern. I wonder if this might be one of those “floating point things”. Did you try making the camera and the light slightly apart from one another, so that their positions are distinct when represented by a float. Maybe multiply the position of one or the other by something close to 1 (0.99, or 1.01, etc). I can’t remember if the light works best behind the camera or in front of it.

1 Like

I did move it by a very amount of unit and it fixed the issue, forgot to post it here after my bad.

Thanks again !

Hey that’s great to hear and glad that was the issue! Like dimitre posted, sometimes these things arise from how floating point numbers are treated by gpu drivers, shaders, etc. And sometimes floats behave differently than doubles too.