瀏覽代碼

Add the sceleton for the clipmap generation

Panagiotis Christopoulos Charitos 6 年之前
父節點
當前提交
6f6de88ff4

+ 59 - 0
shaders/GlobalIlluminationClipmapPopulation.glslp

@@ -0,0 +1,59 @@
+// Copyright (C) 2009-2019, Panagiotis Christopoulos Charitos and contributors.
+// All rights reserved.
+// Code licensed under the BSD License.
+// http://www.anki3d.org/LICENSE
+
+// Populates a clipmap with the irradiance values of probes.
+
+#pragma anki input const U32 CLIPMAP_COUNT
+#pragma anki input const UVec3 WORKGROUP_SIZE
+
+#pragma anki start comp
+
+#include <shaders/ClusteredShading.h>
+
+layout(local_size_x = WORKGROUP_SIZE.x, local_size_y = WORKGROUP_SIZE.y, local_size_z = WORKGROUP_SIZE.z) in;
+
+layout(set = 0, binding = 0) buffer ssbo_
+{
+	GlobalIlluminationProbe u_probes[];
+};
+
+layout(set = 0, binding = 1) uniform sampler u_linearAnyClampSampler;
+layout(set = 0, binding = 2) uniform texture3D u_irradianceTextures[6];
+
+struct Clipmap
+{
+	Vec3 m_aabbMin;
+	F32 m_padding0;
+	Vec3 m_aabbMax;
+	F32 m_padding1;
+	UVec3 m_cellCounts;
+	U32 m_padding2;
+};
+
+layout(set = 0, binding = 3, std140) uniform ubo_
+{
+	Clipmap u_clipmaps[CLIPMAP_COUNT];
+	Vec3 u_cameraPos;
+	F32 u_padding;
+};
+
+void main()
+{
+	// Populate all clipmaps
+	ANKI_UNROLL for(U32 clipmapIdx = 0u; clipmapIdx < CLIPMAP_COUNT; ++clipmapIdx)
+	{
+		Clipmap clipmap = u_clipmaps[clipmapIdx];
+
+		// Check bounds
+		if(any(greaterThanEqual(gl_GlobalInvocationID, clipmap.m_cellCounts)))
+		{
+			continue;
+		}
+
+		// TODO
+	}
+}
+
+#pragma anki end

+ 9 - 0
shaders/glsl_cpp_common/ClusteredShading.h

@@ -104,6 +104,15 @@ struct FogDensityVolume
 const U32 SIZEOF_FOG_DENSITY_VOLUME = 2 * SIZEOF_VEC4;
 const U32 SIZEOF_FOG_DENSITY_VOLUME = 2 * SIZEOF_VEC4;
 ANKI_SHADER_STATIC_ASSERT(sizeof(FogDensityVolume) == SIZEOF_FOG_DENSITY_VOLUME)
 ANKI_SHADER_STATIC_ASSERT(sizeof(FogDensityVolume) == SIZEOF_FOG_DENSITY_VOLUME)
 
 
+// Global illumination probe
+struct GlobalIlluminationProbe
+{
+	Vec3 m_aabbMin;
+	F32 m_cellSize;
+	Vec3 m_aabbMax;
+	U32 m_textureIndex;
+};
+
 // Common uniforms for light shading passes
 // Common uniforms for light shading passes
 struct LightingUniforms
 struct LightingUniforms
 {
 {

+ 13 - 0
src/anki/renderer/GlobalIllumination.h

@@ -19,6 +19,8 @@ namespace anki
 class GlobalIllumination : public RendererObject
 class GlobalIllumination : public RendererObject
 {
 {
 anki_internal:
 anki_internal:
+	static constexpr U CLIPMAP_CASCADE_COUNT = 2;
+
 	GlobalIllumination(Renderer* r)
 	GlobalIllumination(Renderer* r)
 		: RendererObject(r)
 		: RendererObject(r)
 		, m_lightShading(r)
 		, m_lightShading(r)
@@ -93,6 +95,16 @@ private:
 		ShaderProgramPtr m_grProg;
 		ShaderProgramPtr m_grProg;
 	} m_irradiance; ///< Irradiance.
 	} m_irradiance; ///< Irradiance.
 
 
+	class
+	{
+	public:
+		Array2d<RenderTargetDescription, CLIPMAP_CASCADE_COUNT, 6> m_rtDescrs;
+		ShaderProgramResourcePtr m_prog;
+		ShaderProgramPtr m_grProg;
+		Array<UVec3, CLIPMAP_CASCADE_COUNT> m_volumeSizes;
+		Array<F32, CLIPMAP_CASCADE_COUNT> m_cellSizes;
+	} m_clipmap; ///< Clipmap population.
+
 	DynamicArray<CacheEntry> m_cacheEntries;
 	DynamicArray<CacheEntry> m_cacheEntries;
 	HashMap<U64, U32> m_probeUuidToCacheEntryIdx;
 	HashMap<U64, U32> m_probeUuidToCacheEntryIdx;
 	U32 m_tileSize = 0;
 	U32 m_tileSize = 0;
@@ -102,6 +114,7 @@ private:
 	ANKI_USE_RESULT Error initShadowMapping(const ConfigSet& cfg);
 	ANKI_USE_RESULT Error initShadowMapping(const ConfigSet& cfg);
 	ANKI_USE_RESULT Error initLightShading(const ConfigSet& cfg);
 	ANKI_USE_RESULT Error initLightShading(const ConfigSet& cfg);
 	ANKI_USE_RESULT Error initIrradiance(const ConfigSet& cfg);
 	ANKI_USE_RESULT Error initIrradiance(const ConfigSet& cfg);
+	ANKI_USE_RESULT Error initClipmap(const ConfigSet& cfg);
 
 
 	void runGBufferInThread(RenderPassWorkContext& rgraphCtx, InternalContext& giCtx) const;
 	void runGBufferInThread(RenderPassWorkContext& rgraphCtx, InternalContext& giCtx) const;
 	void runShadowmappingInThread(RenderPassWorkContext& rgraphCtx, InternalContext& giCtx) const;
 	void runShadowmappingInThread(RenderPassWorkContext& rgraphCtx, InternalContext& giCtx) const;