Skip to content

Commit

Permalink
Add Luminance.xml shader
Browse files Browse the repository at this point in the history
  • Loading branch information
ducphamhong committed Aug 21, 2020
1 parent eb151ae commit 5de3fa0
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 1 deletion.
14 changes: 14 additions & 0 deletions Assets/BuiltIn/Shader/Basic/GLSL/LuminanceFS.glsl
Original file line number Diff line number Diff line change
@@ -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);
}
16 changes: 16 additions & 0 deletions Assets/BuiltIn/Shader/Basic/HLSL/LuminanceFS.hlsl
Original file line number Diff line number Diff line change
@@ -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);
}
17 changes: 17 additions & 0 deletions Assets/BuiltIn/Shader/Basic/Luminance.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<shaderConfig name="Luminance" baseShader="SOLID">
<uniforms>
<vs>
<uniform name="uMvpMatrix" type="WORLD_VIEW_PROJECTION" value="0" float="16" matrix="true"/>
</vs>
<fs>
<uniform name="uTexDiffuse" type="DEFAULT_VALUE" value="0" float="1" directX="false"/>
</fs>
</uniforms>
<customUI>
<ui control="UIGroup" name="Texture">
<ui control="UITexture" name="uTexDiffuse" autoReplace="_diff.tga"/>
</ui>
</customUI>
<shader type="GLSL" vs="GLSL/TextureColorVS.glsl" fs="GLSL/LuminanceFS.glsl"/>
<shader type="HLSL" vs="HLSL/TextureColorVS.hlsl" fs="HLSL/LuminanceFS.hlsl"/>
</shaderConfig>
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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");
}
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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);
};
}

0 comments on commit 5de3fa0

Please sign in to comment.