Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Rendering] Lens flare phase1 #66

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
98f0e66
generate repeating blobs mirroring bright spots
fall2019 May 28, 2023
2db950a
use lower resolution for ghost generation
fall2019 Jun 3, 2023
7353185
change default value
fall2019 Jun 3, 2023
5f385b9
adjust halo
fall2019 Jun 3, 2023
e8c96dd
add component
fall2019 Jun 3, 2023
7ee8982
fix compile
fall2019 Jun 3, 2023
994b27a
improve writing
fall2019 Jun 5, 2023
d17ea1d
fix compile
fall2019 Jun 5, 2023
a6b2182
fix wrongly return
fall2019 Jun 5, 2023
c22d8f9
using weighted sum to calc lum
fall2019 Jun 5, 2023
ee9f78b
fix halo visibility
fall2019 Jun 17, 2023
0f8bf0c
using average white texture
fall2019 Jun 18, 2023
49b702e
remove gpu -> cpu sync
fall2019 Jun 19, 2023
8fd56c5
fix halo
fall2019 Jun 22, 2023
fe53b89
update default setting for ghost num
fall2019 Jun 22, 2023
45686b8
change gauss option
fall2019 Jun 22, 2023
9c7d5b5
Merge branch 'master' into lensFlare
MomoDeve Jun 23, 2023
b89bfb4
remove constants
fall2019 Jun 23, 2023
5be53b2
Merge branch 'lensFlare' of https://github.com/asc-community/MxEngine…
fall2019 Jun 23, 2023
b7451ab
update average white no matter tone mapping is enabled.
fall2019 Jun 23, 2023
35ae993
revert swap interval
fall2019 Jun 30, 2023
58facab
move average white
fall2019 Jun 30, 2023
d591b6d
decompose eye adaptation and average white
fall2019 Jun 30, 2023
11a5a32
merge origin/master
MomoDeve Jul 30, 2023
e995adc
pull master
fall2019 Mar 22, 2024
0f4500e
temp
fall2019 Mar 25, 2024
a7d2ef9
wide range of lum
fall2019 Mar 25, 2024
f44e2ed
Merge remote-tracking branch 'origin/master' into lensFlare
MomoDeve Mar 28, 2024
7daf66e
beautify + remove unused
MomoDeve Mar 28, 2024
bcc1013
intensity of flare
MomoDeve Mar 28, 2024
cca33ba
revert uMipLevel deletion
MomoDeve Mar 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ set(MXENGINE_SOURCES
"Core/Components/Camera/CameraController.cpp"
"Core/Components/Camera/CameraEffects.cpp"
"Core/Components/Camera/CameraGodRay.cpp"
"Core/Components/Camera/CameraLensFlare.cpp"
"Core/Components/Camera/FrustrumCamera.cpp"
"Core/Components/Camera/InputController.cpp"
"Core/Components/Camera/OrthographicCamera.cpp"
Expand Down
33 changes: 33 additions & 0 deletions src/Core/Components/Camera/CameraController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,21 @@ namespace MxEngine
return this->renderBuffers->SwapHDR2;
}

TextureHandle CameraController::GetSwapQuater1() const
{
return this->renderBuffers->SwapQuater1;
}

TextureHandle CameraController::GetSwapQuater2() const
{
return this->renderBuffers->SwapQuater2;
}

TextureHandle CameraController::GetSwapQuater3() const
{
return this->renderBuffers->SwapQuater3;
}

TextureHandle CameraController::GetSwapHDRTexture1() const
{
return this->renderBuffers->SwapHDR1;
Expand All @@ -461,6 +476,9 @@ namespace MxEngine
this->HDR = Factory<Texture>::Create();
this->SwapHDR1 = Factory<Texture>::Create();
this->SwapHDR2 = Factory<Texture>::Create();
this->SwapQuater1 = Factory<Texture>::Create();
this->SwapQuater2 = Factory<Texture>::Create();
this->SwapQuater3 = Factory<Texture>::Create();

this->Resize(width, height);

Expand Down Expand Up @@ -512,6 +530,18 @@ namespace MxEngine
this->SwapHDR2->Load(nullptr, width, height, 3, false, TextureFormat::RGBA16F);
this->SwapHDR2->SetInternalEngineTag(MXENGINE_MAKE_INTERNAL_TAG("camera swap hdr 2"));
this->SwapHDR2->SetWrapType(TextureWrap::CLAMP_TO_EDGE);

this->SwapQuater1->Load(nullptr, width / 4, height / 4, 3, false, TextureFormat::RGBA16F);
this->SwapQuater1->SetInternalEngineTag(MXENGINE_MAKE_INTERNAL_TAG("camera swap quater 1"));
this->SwapQuater1->SetWrapType(TextureWrap::CLAMP_TO_EDGE);

this->SwapQuater2->Load(nullptr, width / 4, height / 4, 3, false, TextureFormat::RGBA16F);
this->SwapQuater2->SetInternalEngineTag(MXENGINE_MAKE_INTERNAL_TAG("camera swap quater 2"));
this->SwapQuater2->SetWrapType(TextureWrap::CLAMP_TO_EDGE);

this->SwapQuater3->Load(nullptr, width / 4, height / 4, 3, false, TextureFormat::RGBA16F);
this->SwapQuater3->SetInternalEngineTag(MXENGINE_MAKE_INTERNAL_TAG("camera swap quater 3"));
this->SwapQuater3->SetWrapType(TextureWrap::CLAMP_TO_EDGE);
}

void CameraRender::DeInit()
Expand All @@ -524,6 +554,9 @@ namespace MxEngine
Factory<Texture>::Destroy(this->HDR);
Factory<Texture>::Destroy(this->SwapHDR1);
Factory<Texture>::Destroy(this->SwapHDR2);
Factory<Texture>::Destroy(this->SwapQuater1);
Factory<Texture>::Destroy(this->SwapQuater2);
Factory<Texture>::Destroy(this->SwapQuater3);
}

MXENGINE_REFLECT_TYPE
Expand Down
6 changes: 6 additions & 0 deletions src/Core/Components/Camera/CameraController.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ namespace MxEngine
TextureHandle HDR;
TextureHandle SwapHDR1;
TextureHandle SwapHDR2;
TextureHandle SwapQuater1;
TextureHandle SwapQuater2;
TextureHandle SwapQuater3;

void Init(int width, int height);
void Resize(int width, int height);
Expand Down Expand Up @@ -135,5 +138,8 @@ namespace MxEngine
TextureHandle GetHDRTexture() const;
TextureHandle GetSwapHDRTexture1() const;
TextureHandle GetSwapHDRTexture2() const;
TextureHandle GetSwapQuater1() const;
TextureHandle GetSwapQuater2() const;
TextureHandle GetSwapQuater3() const;
};
}
4 changes: 2 additions & 2 deletions src/Core/Components/Camera/CameraEffects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,13 @@ namespace MxEngine
.property("fog density", &CameraEffects::GetFogDensity, &CameraEffects::SetFogDensity)
(
rttr::metadata(MetaInfo::FLAGS, MetaInfo::SERIALIZABLE | MetaInfo::EDITABLE),
rttr::metadata(EditorInfo::EDIT_RANGE, Range{ 0.0f, 10000.0f }),
rttr::metadata(EditorInfo::EDIT_RANGE, Range { 0.0f, 10000.0f }),
rttr::metadata(EditorInfo::EDIT_PRECISION, 0.01f)
)
.property("fog distance", &CameraEffects::GetFogDistance, &CameraEffects::SetFogDistance)
(
rttr::metadata(MetaInfo::FLAGS, MetaInfo::SERIALIZABLE | MetaInfo::EDITABLE),
rttr::metadata(EditorInfo::EDIT_RANGE, Range{ 0.0f, 1.0f }),
rttr::metadata(EditorInfo::EDIT_RANGE, Range { 0.0f, 1.0f }),
rttr::metadata(EditorInfo::EDIT_PRECISION, 0.01f)
)
.property("bloom weight", &CameraEffects::GetBloomWeight, &CameraEffects::SetBloomWeight)
Expand Down
1 change: 1 addition & 0 deletions src/Core/Components/Camera/CameraEffects.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ namespace MxEngine
float bokehRadius = 10.f;
float focusRange = 5.f;
float focusDistance = 0.f;

public:
CameraEffects() = default;

Expand Down
2 changes: 1 addition & 1 deletion src/Core/Components/Camera/CameraGodRay.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ namespace MxEngine
void SetGodRaySampleStep(float value);
void SetGodRayAsymmetry(float value);
};
}
}
95 changes: 95 additions & 0 deletions src/Core/Components/Camera/CameraLensFlare.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#include "CameraLensFlare.h"
#include "Utilities/Math/Math.h"
#include "Core/Runtime/Reflection.h"

namespace MxEngine
{
float CameraLensFlare::GetLensFlareScale()const
{
return this->lensFlareScale;
}

float CameraLensFlare::GetLensFlareBias()const
{
return this->lensFlareBias;
}

int CameraLensFlare::GetLensFlareNumOfGhosts()const
{
return this->lensFlareNumOfGhosts;
}

float CameraLensFlare::GetLensFlareGhostDispersal()const
{
return this->lensFlareGhostDispersal;
}

float CameraLensFlare::GetLensFlareHaloWidth()const
{
return this->lensFalreHaloWidth;
}

void CameraLensFlare::SetLensFlareScale(float scale)
{
this->lensFlareScale = scale;
}

void CameraLensFlare::SetLensFlareBias(float bias)
{
this->lensFlareBias = bias;
}

void CameraLensFlare::SetLensFlareNumOfGhosts(int num)
{
this->lensFlareNumOfGhosts = Max(num,0);
}

void CameraLensFlare::SetLensFlareGhostDispersal(float dispersal)
{
this->lensFlareGhostDispersal = dispersal;
}

void CameraLensFlare::SetLensFlareHaloWidth(float width)
{
this->lensFalreHaloWidth = width;
}

MXENGINE_REFLECT_TYPE
{
rttr::registration::class_<CameraLensFlare>("CameraLensFlare")
(
rttr::metadata(MetaInfo::FLAGS, MetaInfo::CLONE_COPY | MetaInfo::CLONE_INSTANCE)
)
.constructor<>()
.property("lens flare scale", &CameraLensFlare::GetLensFlareScale, &CameraLensFlare::SetLensFlareScale)
(
rttr::metadata(MetaInfo::FLAGS, MetaInfo::SERIALIZABLE | MetaInfo::EDITABLE),
rttr::metadata(EditorInfo::EDIT_RANGE, Range { 0.0f, 100.f }),
rttr::metadata(EditorInfo::EDIT_PRECISION, 0.01f)
)
.property("lens flare bias", &CameraLensFlare::GetLensFlareBias, &CameraLensFlare::SetLensFlareBias)
(
rttr::metadata(MetaInfo::FLAGS, MetaInfo::SERIALIZABLE | MetaInfo::EDITABLE),
rttr::metadata(EditorInfo::EDIT_RANGE, Range { -200.0f, 0.f }),
rttr::metadata(EditorInfo::EDIT_PRECISION, 0.01f)
)
.property("lens flare num of ghosts", &CameraLensFlare::GetLensFlareNumOfGhosts, &CameraLensFlare::SetLensFlareNumOfGhosts)
(
rttr::metadata(MetaInfo::FLAGS, MetaInfo::SERIALIZABLE | MetaInfo::EDITABLE),
rttr::metadata(EditorInfo::EDIT_RANGE, Range { 0.0f, 100.f }),
rttr::metadata(EditorInfo::EDIT_PRECISION, 0.01f)
)
.property("lens flare ghost dispersal", &CameraLensFlare::GetLensFlareGhostDispersal, &CameraLensFlare::SetLensFlareGhostDispersal)
(
rttr::metadata(MetaInfo::FLAGS, MetaInfo::SERIALIZABLE | MetaInfo::EDITABLE),
rttr::metadata(EditorInfo::EDIT_RANGE, Range { 0.001f, 1.f }),
rttr::metadata(EditorInfo::EDIT_PRECISION, 0.01f)
)
.property("lens falre halo width", &CameraLensFlare::GetLensFlareHaloWidth, &CameraLensFlare::SetLensFlareHaloWidth)
fall2019 marked this conversation as resolved.
Show resolved Hide resolved
(
rttr::metadata(MetaInfo::FLAGS, MetaInfo::SERIALIZABLE | MetaInfo::EDITABLE),
rttr::metadata(EditorInfo::EDIT_RANGE, Range { 0.0f, 100.f }),
rttr::metadata(EditorInfo::EDIT_PRECISION, 0.01f)
);
}
}
32 changes: 32 additions & 0 deletions src/Core/Components/Camera/CameraLensFlare.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#pragma once

#include "Utilities/ECS/Component.h"


namespace MxEngine
{
class CameraLensFlare
{
MAKE_COMPONENT(CameraLensFlare);
private:
float lensFlareScale = 1.0f;
float lensFlareBias = -42.0f;
int lensFlareNumOfGhosts = 12;
float lensFlareGhostDispersal = 0.13f;
float lensFalreHaloWidth = 0.5f;

public:
CameraLensFlare() = default;
float GetLensFlareScale()const;
float GetLensFlareBias()const;
int GetLensFlareNumOfGhosts()const;
float GetLensFlareGhostDispersal()const;
float GetLensFlareHaloWidth()const;

void SetLensFlareScale(float);
void SetLensFlareBias(float);
void SetLensFlareNumOfGhosts(int);
void SetLensFlareGhostDispersal(float);
void SetLensFlareHaloWidth(float);
};
}
2 changes: 2 additions & 0 deletions src/Core/Components/Components.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ namespace MxEngine
TEMPLATE_INSTANCIATE_COMPONENT(CameraSSGI );
TEMPLATE_INSTANCIATE_COMPONENT(CameraSSAO );
TEMPLATE_INSTANCIATE_COMPONENT(CameraGodRay );
TEMPLATE_INSTANCIATE_COMPONENT(CameraLensFlare );
TEMPLATE_INSTANCIATE_COMPONENT(CameraToneMapping );
TEMPLATE_INSTANCIATE_COMPONENT(VRCameraController );
TEMPLATE_INSTANCIATE_COMPONENT(AudioSource );
Expand Down Expand Up @@ -124,6 +125,7 @@ namespace MxEngine
RegisterComponent<CameraSSGI >();
RegisterComponent<CameraSSAO >();
RegisterComponent<CameraGodRay >();
RegisterComponent<CameraLensFlare >();
RegisterComponent<CameraToneMapping >();
RegisterComponent<VRCameraController >();
RegisterComponent<AudioSource >();
Expand Down
1 change: 1 addition & 0 deletions src/Core/Components/Components.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "Camera/CameraSSGI.h"
#include "Camera/CameraSSAO.h"
#include "Camera/CameraGodRay.h"
#include "Camera/CameraLensFlare.h"
#include "Camera/InputController.h"
#include "Camera/VRCameraController.h"
#include "Audio/AudioListener.h"
Expand Down
23 changes: 21 additions & 2 deletions src/Core/Rendering/RenderAdaptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "Core/Components/Camera/CameraSSGI.h"
#include "Core/Components/Camera/CameraSSAO.h"
#include "Core/Components/Camera/CameraGodRay.h"
#include "Core/Components/Camera/CameraLensFlare.h"
#include "Core/Components/Camera/CameraToneMapping.h"
#include "Core/Components/Lighting/DirectionalLight.h"
#include "Core/Components/Lighting/PointLight.h"
Expand Down Expand Up @@ -329,6 +330,21 @@ namespace MxEngine
shaderFolder / "dof_combine.glsl"
);

environment.Shaders["LensFlare"_id] = AssetManager::LoadShader(
shaderFolder / "rect_vertex.glsl",
shaderFolder / "lens_flare.glsl"
);

environment.Shaders["LensFlareGhosts"_id] = AssetManager::LoadShader(
shaderFolder / "rect_vertex.glsl",
shaderFolder / "lens_flare_ghosts.glsl"
);

environment.Shaders["LensFlareHalo"_id] = AssetManager::LoadShader(
shaderFolder / "rect_vertex.glsl",
shaderFolder / "lens_flare_halo.glsl"
);

// compute shaders
environment.ComputeShaders["Particle"_id] = AssetManager::LoadComputeShader(
shaderFolder / "particle_compute.glsl"
Expand Down Expand Up @@ -391,15 +407,18 @@ namespace MxEngine
auto ssgiComponent = object.GetComponent<CameraSSGI>();
auto ssaoComponent = object.GetComponent<CameraSSAO>();
auto godRayComponent = object.GetComponent<CameraGodRay>();
auto lensFlareComponent= object.GetComponent<CameraLensFlare>();
Skybox* skybox = skyboxComponent.IsValid() ? skyboxComponent.GetUnchecked() : nullptr;
CameraEffects* effects = effectsComponent.IsValid() ? effectsComponent.GetUnchecked() : nullptr;
CameraToneMapping* toneMapping = toneMappingComponent.IsValid() ? toneMappingComponent.GetUnchecked() : nullptr;
CameraSSR* ssr = ssrComponent.IsValid() ? ssrComponent.GetUnchecked() : nullptr;
CameraSSGI* ssgi = ssgiComponent.IsValid() ? ssgiComponent.GetUnchecked() : nullptr;
CameraSSAO* ssao = ssaoComponent.IsValid() ? ssaoComponent.GetUnchecked() : nullptr;
CameraGodRay* godRay = godRayComponent.IsValid() ? godRayComponent.GetUnchecked() : nullptr;
CameraLensFlare* lensFlare = lensFlareComponent.IsValid() ? lensFlareComponent.GetUnchecked() : nullptr;

this->Renderer.SubmitCamera(camera, transform, skybox, effects, toneMapping, ssr, ssgi, ssao, godRay);
CameraInfo camInfo{ camera, transform, skybox, effects, toneMapping, ssr, ssgi, ssao, godRay, lensFlare };
this->Renderer.SubmitCamera(std::move(camInfo));
TrackMainCameraIndex(camera);
}
}
Expand Down Expand Up @@ -437,7 +456,7 @@ namespace MxEngine
}

size_t renderGroupIndex = this->Renderer.SubmitRenderGroup(*mesh, instanceOffset, instanceCount);
for (const auto& submesh : mesh->GetSubMeshes())
for (const auto& submesh : mesh->GetSubMeshes())
{
auto materialId = submesh.GetMaterialId();
if (materialId >= meshRenderer->Materials.size()) continue;
Expand Down
Loading