Browse Source

Renderer: Add blue noise in the final image

Panagiotis Christopoulos Charitos 9 years ago
parent
commit
c3760fca06

+ 4 - 0
README.md

@@ -18,6 +18,10 @@ See LICENSE file for more info.
 Building AnKi
 Building AnKi
 =============
 =============
 
 
+To checkout the source including the submodules type:
+
+	git clone --recurse-submodules https://github.com/godlikepanos/anki-3d-engine.git anki
+
 AnKi's build system is using CMake. A great effort was made to ease the building process that's why the number of 
 AnKi's build system is using CMake. A great effort was made to ease the building process that's why the number of 
 external dependencies are almost none.
 external dependencies are almost none.
 
 

BIN
engine_data/BlueNoiseLdrRgb.ankitex


+ 16 - 9
shaders/Pps.frag.glsl

@@ -14,24 +14,22 @@
 #include "shaders/SMAA.hlsl"
 #include "shaders/SMAA.hlsl"
 #endif
 #endif
 
 
+#define BLUE_NOISE 1
+
 layout(ANKI_TEX_BINDING(0, 0)) uniform sampler2D u_isRt;
 layout(ANKI_TEX_BINDING(0, 0)) uniform sampler2D u_isRt;
 layout(ANKI_TEX_BINDING(0, 1)) uniform sampler2D u_ppsBloomLfRt;
 layout(ANKI_TEX_BINDING(0, 1)) uniform sampler2D u_ppsBloomLfRt;
 layout(ANKI_TEX_BINDING(0, 2)) uniform sampler3D u_lut;
 layout(ANKI_TEX_BINDING(0, 2)) uniform sampler3D u_lut;
+layout(ANKI_TEX_BINDING(0, 3)) uniform sampler2DArray u_blueNoise;
 #if SMAA_ENABLED
 #if SMAA_ENABLED
-layout(ANKI_TEX_BINDING(0, 3)) uniform sampler2D u_smaaBlendTex;
+layout(ANKI_TEX_BINDING(0, 4)) uniform sampler2D u_smaaBlendTex;
 #endif
 #endif
 #if DBG_ENABLED
 #if DBG_ENABLED
-layout(ANKI_TEX_BINDING(0, 4)) uniform sampler2D u_dbgRt;
+layout(ANKI_TEX_BINDING(0, 5)) uniform sampler2D u_dbgRt;
 #endif
 #endif
 
 
-struct Luminance
-{
-	vec4 averageLuminancePad3;
-};
-
 layout(std140, ANKI_SS_BINDING(0, 0)) readonly buffer s0_
 layout(std140, ANKI_SS_BINDING(0, 0)) readonly buffer s0_
 {
 {
-	Luminance u_luminance;
+	vec4 u_averageLuminancePad3;
 };
 };
 
 
 #if NVIDIA_LINK_ERROR_WORKAROUND
 #if NVIDIA_LINK_ERROR_WORKAROUND
@@ -137,7 +135,7 @@ void main()
 	out_color = textureLod(u_isRt, uv, 0.0).rgb;
 	out_color = textureLod(u_isRt, uv, 0.0).rgb;
 #endif
 #endif
 
 
-	out_color = tonemap(out_color, u_luminance.averageLuminancePad3.x, 0.0);
+	out_color = tonemap(out_color, u_averageLuminancePad3.x, 0.0);
 
 
 #if BLOOM_ENABLED
 #if BLOOM_ENABLED
 	vec3 bloom = textureLod(u_ppsBloomLfRt, uv, 0.0).rgb;
 	vec3 bloom = textureLod(u_ppsBloomLfRt, uv, 0.0).rgb;
@@ -155,4 +153,13 @@ void main()
 #if DBG_ENABLED
 #if DBG_ENABLED
 	out_color += textureLod(u_dbgRt, uv, 0.0).rgb;
 	out_color += textureLod(u_dbgRt, uv, 0.0).rgb;
 #endif
 #endif
+
+#if BLUE_NOISE
+	ivec2 fragCoord = ivec2(gl_FragCoord.xy);
+	vec3 blueNoise = texelFetch(u_blueNoise, ivec3(fragCoord.x % 64, fragCoord.y % 64, 0), 0).rgb;
+	blueNoise = blueNoise * 2.0 - 1.0;
+	blueNoise = sign(blueNoise) * (1.0 - sqrt(1.0 - abs(blueNoise)));
+
+	out_color += blueNoise / 255.0;
+#endif
 }
 }

+ 1 - 1
src/anki/gr/gl/StateTracker.h

@@ -372,7 +372,7 @@ public:
 
 
 	Bool maybeEnableBlend(U attidx)
 	Bool maybeEnableBlend(U attidx)
 	{
 	{
-		const ColorAttachment& att = m_colorAtt[attidx];
+		ColorAttachment& att = m_colorAtt[attidx];
 		Bool wantBlend = !blendingDisabled(att.m_blendSrcFactorRgb,
 		Bool wantBlend = !blendingDisabled(att.m_blendSrcFactorRgb,
 			att.m_blendDstFactorRgb,
 			att.m_blendDstFactorRgb,
 			att.m_blendSrcFactorA,
 			att.m_blendSrcFactorA,

+ 5 - 2
src/anki/renderer/Pps.cpp

@@ -55,6 +55,8 @@ Error Pps::initInternal(const ConfigSet& config)
 		m_fb = getGrManager().newInstance<Framebuffer>(fbInit);
 		m_fb = getGrManager().newInstance<Framebuffer>(fbInit);
 	}
 	}
 
 
+	ANKI_CHECK(getResourceManager().loadResource("engine_data/BlueNoiseLdrRgb.ankitex", m_blueNoise));
+
 	return ErrorCode::NONE;
 	return ErrorCode::NONE;
 }
 }
 
 
@@ -145,10 +147,11 @@ Error Pps::run(RenderingContext& ctx)
 	cmdb->bindTexture(0, 0, m_r->getIs().getRt());
 	cmdb->bindTexture(0, 0, m_r->getIs().getRt());
 	cmdb->bindTexture(0, 1, m_r->getBloom().m_upscale.m_rt);
 	cmdb->bindTexture(0, 1, m_r->getBloom().m_upscale.m_rt);
 	cmdb->bindTexture(0, 2, m_lut->getGrTexture());
 	cmdb->bindTexture(0, 2, m_lut->getGrTexture());
-	cmdb->bindTexture(0, 3, m_r->getSmaa().m_weights.m_rt);
+	cmdb->bindTexture(0, 3, m_blueNoise->getGrTexture());
+	cmdb->bindTexture(0, 4, m_r->getSmaa().m_weights.m_rt);
 	if(dbgEnabled)
 	if(dbgEnabled)
 	{
 	{
-		cmdb->bindTexture(0, 4, m_r->getDbg().getRt());
+		cmdb->bindTexture(0, 5, m_r->getDbg().getRt());
 	}
 	}
 
 
 	cmdb->bindStorageBuffer(0, 0, m_r->getTm().m_luminanceBuff, 0, MAX_PTR_SIZE);
 	cmdb->bindStorageBuffer(0, 0, m_r->getTm().m_luminanceBuff, 0, MAX_PTR_SIZE);

+ 1 - 0
src/anki/renderer/Pps.h

@@ -50,6 +50,7 @@ private:
 	TexturePtr m_rt;
 	TexturePtr m_rt;
 
 
 	TextureResourcePtr m_lut; ///< Color grading lookup texture.
 	TextureResourcePtr m_lut; ///< Color grading lookup texture.
+	TextureResourcePtr m_blueNoise;
 
 
 	Bool8 m_sharpenEnabled = false;
 	Bool8 m_sharpenEnabled = false;