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 all 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
428 changes: 222 additions & 206 deletions samples/Sponza/sponza.json

Large diffs are not rendered by default.

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);
};
}
}
79 changes: 79 additions & 0 deletions src/Core/Components/Camera/CameraLensFlare.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#include "CameraLensFlare.h"
#include "Utilities/Math/Math.h"
#include "Core/Runtime/Reflection.h"

namespace MxEngine
{
float CameraLensFlare::GetIntensity() const
{
return this->intensity;
}

int CameraLensFlare::GetGhostNumber() const
{
return this->ghostNumber;
}

float CameraLensFlare::GetGhostDispersal()const
{
return this->ghostDispersal;
}

float CameraLensFlare::GetHaloWidth()const
{
return this->haloWidth;
}

void CameraLensFlare::SetIntensity(float scale)
{
this->intensity = Max(scale, 0.0);
}

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

void CameraLensFlare::SetGhostDispersal(float dispersal)
{
this->ghostDispersal = dispersal;
}

void CameraLensFlare::SetHaloWidth(float width)
{
this->haloWidth = width;
}

MXENGINE_REFLECT_TYPE
{
rttr::registration::class_<CameraLensFlare>("CameraLensFlare")
(
rttr::metadata(MetaInfo::FLAGS, MetaInfo::CLONE_COPY | MetaInfo::CLONE_INSTANCE)
)
.constructor<>()
.property("intensity", &CameraLensFlare::GetIntensity, &CameraLensFlare::SetIntensity)
(
rttr::metadata(MetaInfo::FLAGS, MetaInfo::SERIALIZABLE | MetaInfo::EDITABLE),
rttr::metadata(EditorInfo::EDIT_RANGE, Range { 0.0f, 1.0f }),
rttr::metadata(EditorInfo::EDIT_PRECISION, 0.01f)
)
.property("ghost number", &CameraLensFlare::GetGhostNumber, &CameraLensFlare::SetGhostNumber)
(
rttr::metadata(MetaInfo::FLAGS, MetaInfo::SERIALIZABLE | MetaInfo::EDITABLE),
rttr::metadata(EditorInfo::EDIT_RANGE, Range { 0.0f, 100.0f }),
rttr::metadata(EditorInfo::EDIT_PRECISION, 0.01f)
)
.property("ghost dispersal", &CameraLensFlare::GetGhostDispersal, &CameraLensFlare::SetGhostDispersal)
(
rttr::metadata(MetaInfo::FLAGS, MetaInfo::SERIALIZABLE | MetaInfo::EDITABLE),
rttr::metadata(EditorInfo::EDIT_RANGE, Range { 0.001f, 1.0f }),
rttr::metadata(EditorInfo::EDIT_PRECISION, 0.01f)
)
.property("halo width", &CameraLensFlare::GetHaloWidth, &CameraLensFlare::SetHaloWidth)
(
rttr::metadata(MetaInfo::FLAGS, MetaInfo::SERIALIZABLE | MetaInfo::EDITABLE),
rttr::metadata(EditorInfo::EDIT_RANGE, Range { 0.0f, 100.0f }),
rttr::metadata(EditorInfo::EDIT_PRECISION, 0.01f)
);
}
}
30 changes: 30 additions & 0 deletions src/Core/Components/Camera/CameraLensFlare.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#pragma once

#include "Utilities/ECS/Component.h"


namespace MxEngine
{
class CameraLensFlare
{
MAKE_COMPONENT(CameraLensFlare);
private:
float intensity = 0.1;
int ghostNumber = 12;
float ghostDispersal = 0.13f;
float haloWidth = 0.5f;

public:
CameraLensFlare() = default;

float GetIntensity() const;
int GetGhostNumber() const;
float GetGhostDispersal() const;
float GetHaloWidth() const;

void SetIntensity(float);
void SetGhostNumber(int);
void SetGhostDispersal(float);
void SetHaloWidth(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
25 changes: 22 additions & 3 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 @@ -335,6 +336,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 @@ -387,7 +403,7 @@ namespace MxEngine
for (const auto& camera : cameraView)
{
auto& object = MxObject::GetByComponent(camera);
auto& transform = object.LocalTransform;
auto transform = &object.LocalTransform;

auto skyboxComponent = object.GetComponent<Skybox>();
auto effectsComponent = object.GetComponent<CameraEffects>();
Expand All @@ -396,15 +412,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 @@ -442,7 +461,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