Browse Source

Fixes in the image viewer and image importer. Added ASTC to EngineAssets

Panagiotis Christopoulos Charitos 4 years ago
parent
commit
ea093bdc31

+ 2 - 0
AnKi/Gr/Enums.h

@@ -155,6 +155,7 @@ public:
 	U8 m_blockSize; ///< The size of the block of a compressed format. Zero otherwise.
 	U8 m_shaderType; ///< It's 0 if the shader sees it as float, 1 if uint and 2 if signed int.
 	DepthStencilAspectBit m_depthStencil; ///< Depth/stencil mask.
+	const char* m_name;
 };
 
 /// Get info for a specific Format.
@@ -174,6 +175,7 @@ inline FormatInfo getFormatInfo(Format fmt)
 		out.m_blockSize = blockSize; \
 		out.m_shaderType = shaderType; \
 		out.m_depthStencil = DepthStencilAspectBit::depthStencil; \
+		out.m_name = #type; \
 		break;
 #include <AnKi/Gr/FormatDefs.h>
 #undef ANKI_FORMAT_DEF

+ 7 - 0
AnKi/Importer/ImageImporter.cpp

@@ -257,6 +257,7 @@ static ANKI_USE_RESULT Error loadFirstMipmap(const ImageImporterConfig& config,
 	for(U32 i = 0; i < config.m_inputFilenames.getSize(); ++i)
 	{
 		I32 width, height, c;
+		stbi_set_flip_vertically_on_load_thread(true);
 		void* data = stbi_load(config.m_inputFilenames[i].cstr(), &width, &height, &c, ctx.m_channelCount);
 		ANKI_ASSERT(U32(c) == ctx.m_channelCount);
 		if(!data)
@@ -551,6 +552,8 @@ static ANKI_USE_RESULT Error storeAnkiImage(const ImageImporterConfig& config, c
 	// Write RAW
 	if(!!(config.m_compressions & ImageBinaryDataCompression::RAW))
 	{
+		ANKI_IMPORTER_LOGV("Storing RAW");
+
 		// for(I32 mip = I32(ctx.m_mipmaps.getSize()) - 1; mip >= 0; --mip)
 		for(U32 mip = 0; mip < ctx.m_mipmaps.getSize(); ++mip)
 		{
@@ -569,6 +572,8 @@ static ANKI_USE_RESULT Error storeAnkiImage(const ImageImporterConfig& config, c
 	// Write S3TC
 	if(!!(config.m_compressions & ImageBinaryDataCompression::S3TC))
 	{
+		ANKI_IMPORTER_LOGV("Storing S3TC");
+
 		// for(I32 mip = I32(ctx.m_mipmaps.getSize()) - 1; mip >= 0; --mip)
 		for(U32 mip = 0; mip < ctx.m_mipmaps.getSize(); ++mip)
 		{
@@ -587,6 +592,8 @@ static ANKI_USE_RESULT Error storeAnkiImage(const ImageImporterConfig& config, c
 	// Write ASTC
 	if(!!(config.m_compressions & ImageBinaryDataCompression::ASTC))
 	{
+		ANKI_IMPORTER_LOGV("Storing ASTC");
+
 		// for(I32 mip = I32(ctx.m_mipmaps.getSize()) - 1; mip >= 0; --mip)
 		for(U32 mip = 0; mip < ctx.m_mipmaps.getSize(); ++mip)
 		{

+ 1 - 1
AnKi/Renderer/ProbeReflections.cpp

@@ -53,7 +53,7 @@ Error ProbeReflections::initInternal(const ConfigSet& config)
 	ANKI_CHECK(initShadowMapping(config));
 
 	// Load split sum integration LUT
-	ANKI_CHECK(getResourceManager().loadResource("EngineAssets/SplitSumIntegration.ankitex", m_integrationLut));
+	ANKI_CHECK(getResourceManager().loadResource("EngineAssets/SplitSumIntegration.png", m_integrationLut));
 
 	SamplerInitInfo sinit;
 	sinit.m_minMagFilter = SamplingFilter::LINEAR;

+ 1 - 0
AnKi/Resource/ImageLoader.cpp

@@ -593,6 +593,7 @@ Error ImageLoader::loadStb(FileInterface& fs, U32& width, U32& height, DynamicAr
 
 	// Use STB to read the image
 	int stbw, stbh, comp;
+	stbi_set_flip_vertically_on_load_thread(true);
 	U8* stbdata = reinterpret_cast<U8*>(stbi_load_from_memory(&fileData[0], I32(fileSize), &stbw, &stbh, &comp, 4));
 	if(!stbdata)
 	{

+ 3 - 3
AnKi/Shaders/ClusteredShadingCommon.glsl

@@ -40,13 +40,13 @@ layout(set = CLUSTERED_SHADING_SET, binding = CLUSTERED_SHADING_LIGHTS_BINDING +
 #if defined(CLUSTERED_SHADING_REFLECTIONS_BINDING)
 layout(set = CLUSTERED_SHADING_SET, binding = CLUSTERED_SHADING_REFLECTIONS_BINDING, scalar) uniform b_reflectionProbes
 {
-	ReflectionProbe u_reflectionProbes2[MAX_VISIBLE_REFLECTION_PROBES];
+	ReflectionProbe u_reflectionProbes[MAX_VISIBLE_REFLECTION_PROBES];
 };
 
 layout(set = CLUSTERED_SHADING_SET,
-	   binding = CLUSTERED_SHADING_REFLECTIONS_BINDING + 1) uniform textureCubeArray u_reflectionsTex2;
+	   binding = CLUSTERED_SHADING_REFLECTIONS_BINDING + 1) uniform textureCubeArray u_reflectionsTex;
 layout(set = CLUSTERED_SHADING_SET,
-	   binding = CLUSTERED_SHADING_REFLECTIONS_BINDING + 2) uniform texture2D u_integrationLut2;
+	   binding = CLUSTERED_SHADING_REFLECTIONS_BINDING + 2) uniform texture2D u_integrationLut;
 #endif
 
 //

+ 5 - 5
AnKi/Shaders/LightShading.ankiprog

@@ -186,12 +186,12 @@ void main()
 		{
 			// Only one probe, do a fast path without blend weight
 
-			const ReflectionProbe probe = u_reflectionProbes2[findLSB(cluster.m_reflectionProbesMask)];
+			const ReflectionProbe probe = u_reflectionProbes[findLSB(cluster.m_reflectionProbesMask)];
 
 			// Sample
 			const Vec3 cubeUv = intersectProbe(worldPos, reflDir, probe.m_aabbMin, probe.m_aabbMax, probe.m_position);
 			const Vec4 cubeArrUv = Vec4(cubeUv, probe.m_cubemapIndex);
-			specIndirect = textureLod(u_reflectionsTex2, u_trilinearClampSampler, cubeArrUv, reflLod).rgb;
+			specIndirect = textureLod(u_reflectionsTex, u_trilinearClampSampler, cubeArrUv, reflLod).rgb;
 		}
 		else
 		{
@@ -204,7 +204,7 @@ void main()
 			{
 				const U32 idx = U32(findLSB(cluster.m_reflectionProbesMask));
 				cluster.m_reflectionProbesMask &= ~(1u << idx);
-				const ReflectionProbe probe = u_reflectionProbes2[idx];
+				const ReflectionProbe probe = u_reflectionProbes[idx];
 
 				// Compute blend weight
 				const F32 blendWeight = computeProbeBlendWeight(worldPos, probe.m_aabbMin, probe.m_aabbMax, 0.2);
@@ -214,7 +214,7 @@ void main()
 				const Vec3 cubeUv =
 					intersectProbe(worldPos, reflDir, probe.m_aabbMin, probe.m_aabbMax, probe.m_position);
 				const Vec4 cubeArrUv = Vec4(cubeUv, probe.m_cubemapIndex);
-				const Vec3 c = textureLod(u_reflectionsTex2, u_trilinearClampSampler, cubeArrUv, reflLod).rgb;
+				const Vec3 c = textureLod(u_reflectionsTex, u_trilinearClampSampler, cubeArrUv, reflLod).rgb;
 				specIndirect += c * blendWeight;
 			}
 
@@ -231,7 +231,7 @@ void main()
 		// Compute env BRDF
 		const F32 NoV = max(EPSILON, dot(gbuffer.m_normal, viewDir));
 		const Vec3 env =
-			envBRDF(gbuffer.m_specular, gbuffer.m_roughness, u_integrationLut2, u_trilinearClampSampler, NoV);
+			envBRDF(gbuffer.m_specular, gbuffer.m_roughness, u_integrationLut, u_trilinearClampSampler, NoV);
 
 		out_color += finalSpecIndirect * env;
 	}

+ 13 - 2
AnKi/Shaders/UiVisualizeImage.ankiprog

@@ -3,10 +3,13 @@
 // Code licensed under the BSD License.
 // http://www.anki3d.org/LICENSE
 
+#pragma anki mutator TEXTURE_TYPE 0 1
+
 layout(push_constant) uniform b_pc
 {
 	Vec4 u_transform; // x: x scale, y: y scale, z: x transl, w: y transl
 	Vec4 u_colorScale;
+	Vec4 u_depth; // Used in 3D textures.
 };
 
 #pragma anki start vert
@@ -43,11 +46,19 @@ layout(location = 1) in Vec4 in_col;
 layout(location = 0) out Vec4 out_col;
 
 layout(set = 0, binding = 0) uniform sampler u_trilinearRepeatSampler;
-layout(set = 0, binding = 1) uniform texture2D u_tex;
+#if TEXTURE_TYPE == 0
+layout(set = 0, binding = 1) uniform texture2D u_tex2d;
+#else
+layout(set = 0, binding = 1) uniform texture3D u_tex3d;
+#endif
 
 void main()
 {
-	const Vec4 rgba = texture(u_tex, u_trilinearRepeatSampler, in_uv);
+#if TEXTURE_TYPE == 0
+	const Vec4 rgba = texture(u_tex2d, u_trilinearRepeatSampler, in_uv);
+#else
+	const Vec4 rgba = texture(u_tex3d, u_trilinearRepeatSampler, Vec3(in_uv, u_depth.x));
+#endif
 	out_col.rgb = in_col.rgb * rgba.rgb * u_colorScale.rgb;
 
 	if(u_colorScale.a == 1.0)

BIN
EngineAssets/BlueNoiseLdr16x16x16.ankitex


BIN
EngineAssets/GiProbe.ankitex


BIN
EngineAssets/GreenDecal.ankitex


BIN
EngineAssets/LensDirt.ankitex


BIN
EngineAssets/LightBulb.ankitex


BIN
EngineAssets/Mirror.ankitex


BIN
EngineAssets/ParticleEmitter.ankitex


BIN
EngineAssets/SplitSumIntegration.ankitex


BIN
EngineAssets/SplitSumIntegration.png


BIN
EngineAssets/SpotLight.ankitex


+ 51 - 7
Tools/Image/ImageViewerMain.cpp

@@ -26,9 +26,6 @@ public:
 
 		ANKI_CHECK_AND_IGNORE(getSceneGraph().getResourceManager().loadResource(
 			"AnKi/Shaders/UiVisualizeImage.ankiprog", m_imageProgram));
-		const ShaderProgramResourceVariant* variant;
-		m_imageProgram->getOrCreateVariant(variant);
-		m_imageGrProgram = variant->getProgram();
 	}
 
 	Error frameUpdate(Second prevUpdateTime, Second crntTime)
@@ -48,6 +45,7 @@ private:
 	TextureViewPtr m_textureView;
 	U32 m_crntMip = 0;
 	F32 m_zoom = 1.0f;
+	F32 m_depth = 0.0f;
 	Bool m_pointSampling = true;
 	Array<Bool, 4> m_colorChannel = {true, true, true, true};
 
@@ -55,6 +53,17 @@ private:
 	{
 		const Texture& grTex = *m_imageResource->getTexture().get();
 		const U32 colorComponentCount = getFormatInfo(grTex.getFormat()).m_componentCount;
+		ANKI_ASSERT(grTex.getTextureType() == TextureType::_2D || grTex.getTextureType() == TextureType::_3D);
+
+		if(!m_imageGrProgram.isCreated())
+		{
+			ShaderProgramResourceVariantInitInfo variantInit(m_imageProgram);
+			variantInit.addMutation("TEXTURE_TYPE", (grTex.getTextureType() == TextureType::_2D) ? 0 : 1);
+
+			const ShaderProgramResourceVariant* variant;
+			m_imageProgram->getOrCreateVariant(variantInit, variant);
+			m_imageGrProgram = variant->getProgram();
+		}
 
 		ImGui::Begin("Console", nullptr,
 					 ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove);
@@ -139,6 +148,38 @@ private:
 				viewInitInf.m_mipmapCount = 1;
 				m_textureView = getSceneGraph().getGrManager().newTextureView(viewInitInf);
 			}
+
+			ImGui::SameLine();
+		}
+
+		// Depth
+		if(grTex.getTextureType() == TextureType::_3D)
+		{
+			StringListAuto labels(getFrameAllocator());
+			for(U32 d = 0; d < grTex.getDepth(); ++d)
+			{
+				labels.pushBackSprintf("Depth %u", d);
+			}
+
+			if(ImGui::BeginCombo("##Depth", (labels.getBegin() + U32(m_depth))->cstr(), ImGuiComboFlags_HeightLarge))
+			{
+				for(U32 d = 0; d < grTex.getDepth(); ++d)
+				{
+					const Bool isSelected = (m_depth == F32(d));
+					if(ImGui::Selectable((labels.getBegin() + d)->cstr(), isSelected))
+					{
+						m_depth = F32(d);
+					}
+
+					if(isSelected)
+					{
+						ImGui::SetItemDefaultFocus();
+					}
+				}
+				ImGui::EndCombo();
+			}
+
+			ImGui::SameLine();
 		}
 
 		ImGui::EndChild();
@@ -154,16 +195,19 @@ private:
 			{
 			public:
 				Vec4 m_colorScale;
+				Vec4 m_depth;
 			} pc;
 			pc.m_colorScale.x() = F32(m_colorChannel[0]);
 			pc.m_colorScale.y() = F32(m_colorChannel[1]);
 			pc.m_colorScale.z() = F32(m_colorChannel[2]);
 			pc.m_colorScale.w() = F32(m_colorChannel[3]);
 
+			pc.m_depth = Vec4((m_depth + 0.5f) / F32(grTex.getDepth()));
+
 			canvas->setShaderProgram(m_imageGrProgram, &pc, sizeof(pc));
 
-			ImGui::Image(UiImageId(m_textureView, m_pointSampling), imageSize, Vec2(0.0f), Vec2(1.0f), Vec4(1.0f),
-						 Vec4(0.0f, 0.0f, 0.0f, 1.0f));
+			ImGui::Image(UiImageId(m_textureView, m_pointSampling), imageSize, Vec2(0.0f, 1.0f), Vec2(1.0f, 0.0f),
+						 Vec4(1.0f), Vec4(0.0f, 0.0f, 0.0f, 1.0f));
 
 			canvas->clearShaderProgram();
 
@@ -236,8 +280,8 @@ public:
 
 		// Change window name
 		StringAuto title(alloc);
-		title.sprintf("%s %llu x %llu Mips %u", argv[1], image->getWidth(), image->getHeight(),
-					  image->getTexture()->getMipmapCount());
+		title.sprintf("%s %llu x %llu Mips %u Format %s", argv[1], image->getWidth(), image->getHeight(),
+					  image->getTexture()->getMipmapCount(), getFormatInfo(image->getTexture()->getFormat()).m_name);
 		getWindow().setWindowTitle(title);
 
 		// Create the node