Hi,
I am at the very end of my OpenGL powers, so I decided to ask for help. After playing around with planet rendering and fake atmospheric scattering and finally getting it to work, I tried to add a sun and observed some odd behaviour.
Please see here: https://www.youtube.com/watch?v=YxdZoh2iT6g&feature=youtu.be
My code is as follows, I’ve added comments to explain:
//----------------------------------------------------------
// code for atmospheric scattering
// I used a sphere bigger than the planet that has some lighting effects with shaders
// I record this in an fbo to blur it later on
// I do not set blending mode during the recording of the fbo, just when drawing it
atmScatter.begin();
ofPushMatrix();
ofTranslate(ofGetWidth()/2, ofGetHeight()/2);
ofDisableBlendMode();
ofClear(0);
shader3.begin(); // shader for lighting effect
shader3.setUniformBuffer("Light", atmosphereLight);
shader3.setUniformBuffer("Material", blue);
shader3.setUniformBuffer("NormalMatrix",
calcNormalMatrix(glowSphere.getGlobalTransformMatrix()*camera.getModelViewMatrix()));
shader3.setUniformTexture("tex", glow.getTextureReference(), 0);
glowSphere.draw();
shader3.end();
ofPopMatrix();
atmScatter.end();
//----------------------------------------------------------
// code for blurring the atmospheric scatter fbo
ofPushStyle();
ofEnableBlendMode(OF_BLENDMODE_ADD);
shaderBlur.begin();
fboBlurOnePass.draw(0, 0);
shaderBlur.end();
ofPopStyle();
ofDisableBlendMode();
//----------------------------------------------------------
// code for drawing the sun, loaded as a 2d image
ofPushMatrix();
ofPushStyle();
ofEnableBlendMode(OF_BLENDMODE_ADD);
ofTranslate(sun.getPosition()); // translate to sun position
ofRotate(ang, vec.x, vec.y, vec.z); // rotate to face camera
glow2.draw(-2400/2, -2400/2, 2400, 2400); // set size
ofDisableBlendMode();
ofPopStyle();
ofPopMatrix();
Visually, this draws correctly, only that the sun is somehow overlapped by the atmosphere scatter fbo.
If I draw the sun behind the atmosphere scatter fbo, this does not happen anymore, instead, if I zoom the camera such that it is positioned behind the sun’s orbit, the sun image will then overlap the atmosphere scatter fbo.
I have no clue as to why this happens, especially since the effects look as intended. I have individually looked at the amt scatter fbo - and it is just the sphere with a black background, as expected, and also at the sun image, which is the sun you see in the video with a black background. I have also tried to use the SCREEN blend mode, but to the same effect.
Thanks a bunch for any tips on this!
p.s.: the shaders have nothing to do with this, I commented them out and, sadly, the effect is still present.