Browse Source

More shader work

Panagiotis Christopoulos Charitos 4 năm trước cách đây
mục cha
commit
fcd6a978bd

+ 29 - 34
AnKi/Renderer/VolumetricFog.cpp

@@ -50,53 +50,48 @@ Error VolumetricFog::init(const ConfigSet& config)
 	return Error::NONE;
 }
 
-void VolumetricFog::run(const RenderingContext& ctx, RenderPassWorkContext& rgraphCtx)
+void VolumetricFog::populateRenderGraph(RenderingContext& ctx)
 {
-	CommandBufferPtr& cmdb = rgraphCtx.m_commandBuffer;
+	RenderGraphDescription& rgraph = ctx.m_renderGraphDescr;
 
-	cmdb->bindShaderProgram(m_grProg);
+	m_runCtx.m_rt = rgraph.newRenderTarget(m_rtDescr);
 
-	cmdb->bindSampler(0, 0, m_r->getSamplers().m_trilinearClamp);
-	rgraphCtx.bindColorTexture(0, 1, m_r->getVolumetricLightingAccumulation().getRt());
+	ComputeRenderPassDescription& pass = rgraph.newComputeRenderPass("Vol fog");
 
-	rgraphCtx.bindImage(0, 2, m_runCtx.m_rt, TextureSubresourceInfo());
+	pass.newDependency({m_runCtx.m_rt, TextureUsageBit::IMAGE_COMPUTE_WRITE});
+	pass.newDependency({m_r->getVolumetricLightingAccumulation().getRt(), TextureUsageBit::SAMPLED_COMPUTE});
 
-	struct PushConsts
-	{
-		F32 m_fogScatteringCoeff;
-		F32 m_fogAbsorptionCoeff;
-		F32 m_density;
-		F32 m_near;
-		Vec3 m_fogDiffuse;
-		F32 m_far;
-	} regs;
+	pass.setWork([this, &ctx](RenderPassWorkContext& rgraphCtx) -> void {
+		CommandBufferPtr& cmdb = rgraphCtx.m_commandBuffer;
 
-	regs.m_fogScatteringCoeff = m_fogScatteringCoeff;
-	regs.m_fogAbsorptionCoeff = m_fogAbsorptionCoeff;
-	regs.m_density = m_fogDensity;
-	regs.m_fogDiffuse = m_fogDiffuseColor;
-	regs.m_near = ctx.m_renderQueue->m_cameraNear;
-	regs.m_far = ctx.m_renderQueue->m_cameraFar;
+		cmdb->bindShaderProgram(m_grProg);
 
-	cmdb->setPushConstants(&regs, sizeof(regs));
+		cmdb->bindSampler(0, 0, m_r->getSamplers().m_trilinearClamp);
+		rgraphCtx.bindColorTexture(0, 1, m_r->getVolumetricLightingAccumulation().getRt());
 
-	dispatchPPCompute(cmdb, m_workgroupSize[0], m_workgroupSize[1], m_volumeSize[0], m_volumeSize[1]);
-}
+		rgraphCtx.bindImage(0, 2, m_runCtx.m_rt, TextureSubresourceInfo());
 
-void VolumetricFog::populateRenderGraph(RenderingContext& ctx)
-{
-	RenderGraphDescription& rgraph = ctx.m_renderGraphDescr;
+		struct PushConsts
+		{
+			F32 m_fogScatteringCoeff;
+			F32 m_fogAbsorptionCoeff;
+			F32 m_density;
+			F32 m_near;
+			Vec3 m_fogDiffuse;
+			F32 m_far;
+		} regs;
 
-	m_runCtx.m_rt = rgraph.newRenderTarget(m_rtDescr);
+		regs.m_fogScatteringCoeff = m_fogScatteringCoeff;
+		regs.m_fogAbsorptionCoeff = m_fogAbsorptionCoeff;
+		regs.m_density = m_fogDensity;
+		regs.m_fogDiffuse = m_fogDiffuseColor;
+		regs.m_near = ctx.m_renderQueue->m_cameraNear;
+		regs.m_far = ctx.m_renderQueue->m_cameraFar;
 
-	ComputeRenderPassDescription& pass = rgraph.newComputeRenderPass("Vol fog");
+		cmdb->setPushConstants(&regs, sizeof(regs));
 
-	pass.setWork([this, &ctx](RenderPassWorkContext& rgraphCtx) -> void {
-		run(ctx, rgraphCtx);
+		dispatchPPCompute(cmdb, m_workgroupSize[0], m_workgroupSize[1], m_volumeSize[0], m_volumeSize[1]);
 	});
-
-	pass.newDependency({m_runCtx.m_rt, TextureUsageBit::IMAGE_COMPUTE_WRITE});
-	pass.newDependency({m_r->getVolumetricLightingAccumulation().getRt(), TextureUsageBit::SAMPLED_COMPUTE});
 }
 
 } // end namespace anki

+ 0 - 2
AnKi/Renderer/VolumetricFog.h

@@ -87,8 +87,6 @@ private:
 	public:
 		RenderTargetHandle m_rt;
 	} m_runCtx; ///< Runtime context.
-
-	void run(const RenderingContext& ctx, RenderPassWorkContext& rgraphCtx);
 };
 /// @}
 

+ 7 - 2
AnKi/Shaders/Common.glsl

@@ -12,9 +12,13 @@
 
 // Constants
 const F32 EPSILON = 0.000001;
-const ANKI_RP F32 EPSILON_RP = 0.0001; // Divisions by this should be OK according to http://weitz.de/ieee/
-const F32 FLT_MAX = 3.402823e+38;
+const F16 EPSILON_F16 = 0.0001hf; // Divisions by this should be OK according to http://weitz.de/ieee/
+const ANKI_RP F32 EPSILON_RP = F32(EPSILON_F16);
+
 const U32 MAX_U32 = 0xFFFFFFFFu;
+const F32 MAX_F32 = 3.402823e+38;
+const F16 MAX_F16 = 65504.0hf;
+const F16 MIN_F16 = 0.00006104hf;
 
 const F32 PI = 3.14159265358979323846;
 const U32 MAX_UBO_SIZE = 16384u;
@@ -24,6 +28,7 @@ const U32 MAX_SHARED_MEMORY = 32u * 1024u;
 #define UV_TO_NDC(x_) ((x_)*2.0 - 1.0)
 #define NDC_TO_UV(x_) ((x_)*0.5 + 0.5)
 #define saturate(x_) clamp((x_), 0.0, 1.0)
+#define saturateRp(x) min(x, F32(MAX_F16))
 #define mad(a_, b_, c_) fma((a_), (b_), (c_))
 
 // Passes

+ 1 - 1
AnKi/Shaders/IndirectDiffuseDenoise.ankiprog

@@ -3,7 +3,7 @@
 // Code licensed under the BSD License.
 // http://www.anki3d.org/LICENSE
 
-#pragma anki mutator BLUR_ORIENTATION 0 1 // 0: in X asix, 1: in Y axis
+#pragma anki mutator BLUR_ORIENTATION 0 1 // 0: in X axis, 1: in Y axis
 
 #pragma anki start comp
 

+ 2 - 2
AnKi/Shaders/PackFunctions.glsl

@@ -41,7 +41,7 @@ Vec3 signedOctEncode(Vec3 n)
 	outn.x = n.x * 0.5 + outn.y;
 	outn.y = n.x * -0.5 + outn.y;
 
-	outn.z = saturate(n.z * FLT_MAX);
+	outn.z = saturate(n.z * MAX_F32);
 	return outn;
 }
 
@@ -192,7 +192,7 @@ void readGBuffer(texture2D rt0, texture2D rt1, texture2D rt2, sampler sampl, Vec
 	g.m_normal = signedOctDecode(comp.yzw);
 	g.m_emission = comp.x * maxEmission;
 
-	g.m_velocity = Vec2(FLT_MAX); // Put something random
+	g.m_velocity = Vec2(MAX_F32); // Put something random
 
 	// Fix roughness
 	g.m_roughness = g.m_roughness * (1.0 - MIN_ROUGHNESS) + MIN_ROUGHNESS;

+ 1 - 1
AnKi/Shaders/Ssr.ankiprog

@@ -133,7 +133,7 @@ void main()
 
 		// Read the light buffer
 		outColor.rgb = textureLod(u_lightBufferRt, u_trilinearClampSampler, hitPoint.xy, lod).rgb;
-		outColor.rgb = clamp(outColor.rgb, 0.0, FLT_MAX); // Fix the value just in case
+		outColor.rgb = clamp(outColor.rgb, 0.0, MAX_F32); // Fix the value just in case
 		outColor.rgb *= hitAttenuation;
 		outColor.a = 1.0 - hitAttenuation;
 	}

+ 1 - 1
AnKi/Shaders/TonemappingAverageLuminance.ankiprog

@@ -90,7 +90,7 @@ void main()
 #endif
 
 		// This is a workaround because sometimes the avg lum becomes nan
-		finalAvgLum = clamp(finalAvgLum, EPSILON, FLT_MAX);
+		finalAvgLum = clamp(finalAvgLum, EPSILON, MAX_F32);
 
 		u_averageLuminance = finalAvgLum;
 		u_exposureThreshold0 = computeExposure(u_averageLuminance, 0.0);