diff --git a/Assets/BuiltIn/Shader/Basic/GLSL/LuminanceFS.glsl b/Assets/BuiltIn/Shader/Basic/GLSL/LuminanceFS.glsl new file mode 100644 index 000000000..34517bd74 --- /dev/null +++ b/Assets/BuiltIn/Shader/Basic/GLSL/LuminanceFS.glsl @@ -0,0 +1,14 @@ +precision mediump float; + +uniform sampler2D uTexDiffuse; + +in vec2 varTexCoord0; +in vec4 varColor; +out vec4 FragColor; + +void main(void) +{ + vec4 color = texture(uTexDiffuse, varTexCoord0.xy) * varColor; + float lum = max(dot(color.rgb, vec3(0.299, 0.587, 0.114)), 0.0001); + FragColor = vec4(lum, 0.0, 0.0, 0.0); +} \ No newline at end of file diff --git a/Assets/BuiltIn/Shader/Basic/HLSL/LuminanceFS.hlsl b/Assets/BuiltIn/Shader/Basic/HLSL/LuminanceFS.hlsl new file mode 100644 index 000000000..28b06b5bd --- /dev/null +++ b/Assets/BuiltIn/Shader/Basic/HLSL/LuminanceFS.hlsl @@ -0,0 +1,16 @@ +Texture2D uTexDiffuse : register(t0); +SamplerState uTexDiffuseSampler : register(s0); + +struct PS_INPUT +{ + float4 pos : SV_POSITION; + float4 color : COLOR0; + float2 tex0 : TEXCOORD0; +}; + +float4 main(PS_INPUT input) : SV_TARGET +{ + float4 color = input.color * uTexDiffuse.Sample(uTexDiffuseSampler, input.tex0); + float lum = max(dot(color.rgb, float3(0.299, 0.587, 0.114)), 0.0001); + return float4(lum, 0.0, 0.0, 0.0); +} \ No newline at end of file diff --git a/Assets/BuiltIn/Shader/Basic/Luminance.xml b/Assets/BuiltIn/Shader/Basic/Luminance.xml new file mode 100644 index 000000000..cd9032893 --- /dev/null +++ b/Assets/BuiltIn/Shader/Basic/Luminance.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Projects/Skylicht/Engine/Source/Material/Shader/CShaderManager.cpp b/Projects/Skylicht/Engine/Source/Material/Shader/CShaderManager.cpp index e2ea4e7a8..256548591 100644 --- a/Projects/Skylicht/Engine/Source/Material/Shader/CShaderManager.cpp +++ b/Projects/Skylicht/Engine/Source/Material/Shader/CShaderManager.cpp @@ -87,6 +87,7 @@ namespace Skylicht loadShader("BuiltIn/Shader/ShadowMap/ShadowCubeDepthWrite.xml"); loadShader("BuiltIn/Shader/Basic/TextureTone.xml"); + loadShader("BuiltIn/Shader/Basic/Luminance.xml"); loadShader("BuiltIn/Shader/Lightmap/Lightmap.xml"); loadShader("BuiltIn/Shader/Lightmap/LightmapUV.xml"); diff --git a/Projects/Skylicht/Engine/Source/RenderPipeline/CPostProcessorRP.cpp b/Projects/Skylicht/Engine/Source/RenderPipeline/CPostProcessorRP.cpp index de3396f12..1fda50117 100644 --- a/Projects/Skylicht/Engine/Source/RenderPipeline/CPostProcessorRP.cpp +++ b/Projects/Skylicht/Engine/Source/RenderPipeline/CPostProcessorRP.cpp @@ -35,6 +35,9 @@ namespace Skylicht CPostProcessorRP::~CPostProcessorRP() { + IVideoDriver *driver = getVideoDriver(); + driver->removeTexture(m_luminance[0]); + driver->removeTexture(m_luminance[1]); } void CPostProcessorRP::initRender(int w, int h) @@ -45,6 +48,10 @@ namespace Skylicht // init size of framebuffer m_size = core::dimension2du((u32)w, (u32)h); + core::dimension2du lumSize(1024, 1024); + m_luminance[0] = driver->addRenderTargetTexture(lumSize, "lum_0", ECF_R16F); + m_luminance[1] = driver->addRenderTargetTexture(lumSize, "lum_1", ECF_R16F); + // init final pass shader m_finalPass.MaterialType = shaderMgr->getShaderIDByName("TextureColor"); } @@ -57,10 +64,17 @@ namespace Skylicht onNext(target, camera, entityManager, viewport); } + void CPostProcessorRP::luminanceMapGeneration(ITexture *color) + { + + } + void CPostProcessorRP::postProcessing(ITexture *finalTarget, ITexture *color, ITexture *normal, ITexture *position, const core::recti& viewport) { IVideoDriver *driver = getVideoDriver(); + luminanceMapGeneration(color); + driver->setRenderTarget(finalTarget, false, false); float renderW = (float)m_size.Width; diff --git a/Projects/Skylicht/Engine/Source/RenderPipeline/CPostProcessorRP.h b/Projects/Skylicht/Engine/Source/RenderPipeline/CPostProcessorRP.h index 8c6634beb..177ae4b9e 100644 --- a/Projects/Skylicht/Engine/Source/RenderPipeline/CPostProcessorRP.h +++ b/Projects/Skylicht/Engine/Source/RenderPipeline/CPostProcessorRP.h @@ -28,11 +28,13 @@ This file is part of the "Skylicht Engine". namespace Skylicht { - class CPostProcessorRP: public CBaseRP + class CPostProcessorRP : public CBaseRP { protected: core::dimension2du m_size; + ITexture *m_luminance[2]; + SMaterial m_finalPass; public: @@ -45,5 +47,7 @@ namespace Skylicht virtual void render(ITexture *target, CCamera *camera, CEntityManager *entityManager, const core::recti& vp); virtual void postProcessing(ITexture *finalTarget, ITexture *color, ITexture *normal, ITexture *position, const core::recti& viewport); + + void luminanceMapGeneration(ITexture *color); }; } \ No newline at end of file