Tweak lens flares

- Lens flare is a screen-space effect
- Billboard size equals flare size * constant
- Make billboard translucent
This commit is contained in:
Vsevolod Kremianskii 2021-05-04 10:54:24 +07:00
parent ea4b444af8
commit 373cf4e14c

View file

@ -45,18 +45,34 @@ void LightSceneNode::drawLensFlares(const LensFlare &flare) {
shared_ptr<CameraSceneNode> camera(_sceneGraph->activeCamera());
if (!camera) return;
setActiveTextureUnit(0);
setActiveTextureUnit(TextureUnits::diffuse);
flare.texture->bind();
glm::vec4 lightPos(_absoluteTransform[3]);
glm::vec4 lightPosNdc(camera->projection() * camera->view() * lightPos);
float w = _sceneGraph->options().width;
float h = _sceneGraph->options().height;
glm::vec3 lightPosScreen(glm::vec3(lightPosNdc) / lightPosNdc.w);
lightPosScreen *= 0.5f;
lightPosScreen += 0.5f;
lightPosScreen *= glm::vec3(w, h, 1.0f);
float aspect = flare.texture->width() / static_cast<float>(flare.texture->height());
float baseFlareSize = 50.0f;
glm::mat4 transform(1.0f);
transform = glm::translate(transform, glm::vec3(_absoluteTransform[3]));
transform = glm::scale(transform, glm::vec3(flare.texture->height()));
transform = glm::translate(transform, glm::vec3(lightPosScreen.x, lightPosScreen.y, 0.0f));
transform = glm::scale(transform, glm::vec3(aspect * flare.size * baseFlareSize, flare.size * baseFlareSize, 1.0f));
ShaderUniforms uniforms(_sceneGraph->uniformsPrototype());
ShaderUniforms uniforms;
uniforms.combined.general.projection = glm::ortho(0.0f, w, 0.0f, h);
uniforms.combined.general.model = move(transform);
uniforms.combined.general.color = glm::vec4(flare.colorShift, 1.0f);
uniforms.combined.general.alpha = 0.5f;
//uniforms.combined.general.color = glm::vec4(flare.colorShift, 1.0f);
Shaders::instance().activate(ShaderProgram::BillboardGUI, uniforms);
Shaders::instance().activate(ShaderProgram::SimpleGUI, uniforms);
withAdditiveBlending([]() {
Meshes::instance().getBillboard()->draw();