Browse Source

Exporter updates

Panagiotis Christopoulos Charitos 11 years ago
parent
commit
894725d00e

+ 8 - 2
include/anki/core/Counters.h

@@ -64,11 +64,17 @@ public:
 	void stopTimerIncreaseCounter(Counter counter);
 
 private:
+	union Value
+	{
+		F64 m_float;
+		U64 m_int;
+	};
+
 	HeapAllocator<U8> m_alloc;
 	File m_perframeFile;
 	File m_perrunFile;
-	DArray<U64> m_perframeValues;
-	DArray<U64> m_perrunValues;
+	DArray<Value> m_perframeValues;
+	DArray<Value> m_perrunValues;
 	DArray<HighRezTimer::Scalar> m_counterTimes;
 };
 

+ 5 - 0
include/anki/util/DArray.h

@@ -142,6 +142,11 @@ public:
 		return m_size;
 	}
 
+	PtrSize getByteSize() const
+	{
+		return m_size * sizeof(Value);
+	}
+
 	Bool isEmpty() const
 	{
 		return m_size == 0;

+ 1 - 1
shaders/IsLp.frag.glsl

@@ -348,7 +348,7 @@ void main()
 #if 0
 	if(in_instanceId != 99999)
 	{
-		out_color = vec3(diffCol);
+		out_color = vec3(normal);
 	}
 #endif
 }

+ 1 - 1
shaders/PpsSsao.frag.glsl

@@ -28,7 +28,7 @@ layout(binding = 1) uniform sampler2D uMsRt;
 layout(binding = 2) uniform sampler2D uNoiseMap;
 
 #define RADIUS 0.5
-#define DARKNESS_MULTIPLIER 1.0 // Initial is 1.0 but the bigger it is the more
+#define DARKNESS_MULTIPLIER 1.5 // Initial is 1.0 but the bigger it is the more
                                 // darker the SSAO factor gets
 
 // Get normal

+ 25 - 22
src/core/Counters.cpp

@@ -26,9 +26,8 @@ enum CounterFlag
 	CF_U64 = 1 << 4
 };
 
-class CounterInfo
+struct CounterInfo
 {
-public:
 	const char* m_name;
 	U32 m_flags;
 };
@@ -40,7 +39,7 @@ static const Array<CounterInfo, (U)Counter::COUNT> cinfo = {{
 	{"RENDERER_IS_TIME", CF_PER_FRAME | CF_PER_RUN | CF_F64},
 	{"RENDERER_PPS_TIME", CF_PER_FRAME | CF_PER_RUN | CF_F64},
 	{"RENDERER_SHADOW_PASSES", CF_PER_FRAME | CF_PER_RUN | CF_U64},
-	{"RENDERER_LIGHTS_COUNT", CF_PER_RUN | CF_U64},
+	{"RENDERER_LIGHTS_COUNT", CF_PER_FRAME | CF_PER_RUN | CF_U64},
 	{"SCENE_UPDATE_TIME", CF_PER_RUN | CF_F64},
 	{"SWAP_BUFFERS_TIME", CF_PER_RUN | CF_F64},
 	{"GL_CLIENT_WAIT_TIME", CF_PER_FRAME | CF_PER_RUN | CF_F64},
@@ -62,15 +61,19 @@ Error CountersManager::create(
 	U count = static_cast<U>(Counter::COUNT);
 	m_alloc = alloc;
 	
-	err = m_perframeValues.create(m_alloc, count, 0);
+	err = m_perframeValues.create(m_alloc, count);
 	if(err) return err;
 
-	err = m_perrunValues.create(m_alloc, count, 0);
+	err = m_perrunValues.create(m_alloc, count);
 	if(err) return err;
 
-	err = m_counterTimes.create(m_alloc, count, 0.0);
+	err = m_counterTimes.create(m_alloc, count);
 	if(err) return err;
 
+	memset(&m_perframeValues[0], 0, m_perframeValues.getByteSize());
+	memset(&m_perrunValues[0], 0, m_perrunValues.getByteSize());
+	memset(&m_counterTimes[0], 0, m_counterTimes.getByteSize());
+
 	// Open and write the headers to the files
 	String tmp;
 	String::ScopeDestroyer tmpd(&tmp, alloc);
@@ -139,12 +142,12 @@ void CountersManager::increaseCounter(Counter counter, U64 val)
 
 	if(cinfo[(U)counter].m_flags & CF_PER_FRAME)
 	{
-		m_perframeValues[(U)counter] += val;
+		m_perframeValues[(U)counter].m_int += val;
 	}
 
 	if(cinfo[(U)counter].m_flags & CF_PER_RUN)
 	{
-		m_perrunValues[(U)counter] += val;
+		m_perrunValues[(U)counter].m_int += val;
 	}
 }
 
@@ -152,17 +155,15 @@ void CountersManager::increaseCounter(Counter counter, U64 val)
 void CountersManager::increaseCounter(Counter counter, F64 val)
 {
 	ANKI_ASSERT(cinfo[(U)counter].m_flags & CF_F64);
-	F64 f;
-	memcpy(&f, &val, sizeof(F64));
 
 	if(cinfo[(U)counter].m_flags & CF_PER_FRAME)
 	{
-		*(F64*)(&m_perframeValues[(U)counter]) += f;
+		m_perframeValues[(U)counter].m_float += val;
 	}
 
 	if(cinfo[(U)counter].m_flags & CF_PER_RUN)
 	{
-		*(F64*)(&m_perrunValues[(U)counter]) += f;
+		m_perrunValues[(U)counter].m_float += val;
 	}
 }
 
@@ -171,7 +172,7 @@ void CountersManager::startTimer(Counter counter)
 {
 	// The counter should be F64
 	ANKI_ASSERT(cinfo[(U)counter].m_flags & CF_F64);
-	// The timer should have beeb reseted
+	// The timer should have been reseted
 	ANKI_ASSERT(m_counterTimes[(U)counter] == 0.0);
 
 	m_counterTimes[(U)counter] = HighRezTimer::getCurrentTime();
@@ -185,10 +186,11 @@ void CountersManager::stopTimerIncreaseCounter(Counter counter)
 	// The timer should have started
 	ANKI_ASSERT(m_counterTimes[(U)counter] > 0.0);
 
-	F32 prevTime = m_counterTimes[(U)counter];
+	auto prevTime = m_counterTimes[(U)counter];
 	m_counterTimes[(U)counter] = 0.0;
 
-	increaseCounter(counter, HighRezTimer::getCurrentTime() - prevTime);
+	increaseCounter(
+		counter, (HighRezTimer::getCurrentTime() - prevTime) * 1000.0);
 }
 
 //==============================================================================
@@ -206,19 +208,20 @@ void CountersManager::resolveFrame()
 		{
 			if(inf.m_flags & CF_U64)
 			{
-				err = m_perframeFile.writeText(", %llu", m_perframeValues[i]);
+				err = m_perframeFile.writeText(
+					", %llu", m_perframeValues[i].m_int);
 			}
 			else if(inf.m_flags & CF_F64)
 			{
 				err = m_perframeFile.writeText(
-					", %f", *((F64*)&m_perframeValues[i]));
+					", %f", m_perframeValues[i].m_float);
 			}
 			else
 			{
 				ANKI_ASSERT(0);
 			}
 
-			m_perframeValues[i] = 0;
+			m_perframeValues[i].m_int = 0;
 		}
 
 		i++;
@@ -247,19 +250,19 @@ void CountersManager::flush()
 			if(inf.m_flags & CF_U64)
 			{
 				err = m_perrunFile.writeText(
-					"%" MAX_NAME "llu", m_perrunValues[i]);
+					"%" MAX_NAME "llu", m_perrunValues[i].m_int);
 			}
 			else if(inf.m_flags & CF_F64)
 			{
 				if(inf.m_flags & CF_FPS)
 				{
 					err = m_perrunFile.writeText("%" MAX_NAME "f", 
-						(F64)getGlobTimestamp() / *((F64*)&m_perrunValues[i]));
+						(F64)getGlobTimestamp() / m_perrunValues[i].m_float);
 				}
 				else
 				{
 					err = m_perrunFile.writeText("%" MAX_NAME "f", 
-						*((F64*)&m_perrunValues[i]));
+						&m_perrunValues[i].m_float);
 				}
 			}
 			else
@@ -267,7 +270,7 @@ void CountersManager::flush()
 				ANKI_ASSERT(0);
 			}
 
-			m_perrunValues[i] = 0;
+			m_perrunValues[i].m_int = 0;
 			++j;
 		}
 

+ 3 - 3
src/gl/GlTexture.cpp

@@ -164,9 +164,9 @@ Error GlTexture::create(const Initializer& init,
 	// Load data
 	if(init.m_data[0][0].m_ptr != nullptr)
 	{
-		Bool compressed;
-		GLenum format;
-		GLenum type;
+		Bool compressed = false;
+		GLenum format = GL_NONE;
+		GLenum type = GL_NONE;
 		getTextureInformation(m_internalFormat, compressed, format, type);
 
 		U w = m_width;

+ 1 - 1
src/renderer/Sm.cpp

@@ -93,7 +93,7 @@ void Sm::prepareDraw(GlCommandBufferHandle& cmdBuff)
 	cmdBuff.setColorWriteMask(false, false, false, false);
 
 	// for artifacts
-	cmdBuff.setPolygonOffset(2.0, 2.0); // keep both as low as possible!!!!
+	cmdBuff.setPolygonOffset(7.0, 5.0); // keep both as low as possible!!!!
 	cmdBuff.enablePolygonOffset(true);
 
 	m_r->getSceneDrawer().prepareDraw(

+ 5 - 3
testapp/Main.cpp

@@ -101,7 +101,7 @@ Error init()
 	}
 #endif
 
-#if 1
+#if 0
 	err = scene.newSceneNode<SpotLight>("spot0", spot);
 	if(err) return err;
 
@@ -532,7 +532,7 @@ Error initSubsystems(int argc, char* argv[])
 	config.set("pps.hdr.renderingQuality", 0.5);
 	config.set("pps.hdr.blurringDist", 1.0);
 	config.set("pps.hdr.blurringIterationsCount", 2);
-	config.set("pps.hdr.exposure", 10.0);
+	config.set("pps.hdr.exposure", 15.0);
 	config.set("pps.hdr.samples", 17);
 	config.set("pps.sslr.enabled", true);
 	config.set("pps.sslr.renderingQuality", 0.5);
@@ -544,7 +544,7 @@ Error initSubsystems(int argc, char* argv[])
 	config.set("pps.bl.blurringIterationsCount", 2);
 	config.set("pps.bl.sideBlurFactor", 1.0);
 	config.set("pps.lf.enabled", true);
-	config.set("pps.sharpen", true);
+	config.set("pps.sharpen", false);
 	config.set("renderingQuality", 1.0);
 	config.set("width", 1280);
 	config.set("height", 720);
@@ -554,6 +554,8 @@ Error initSubsystems(int argc, char* argv[])
 	config.set("tilesXCount", 16);
 	config.set("tilesYCount", 16);
 
+	//config.set("maxTextureSize", 256);
+
 	config.set("fullscreenDesktopResolution", true);
 	config.set("debugContext", false);
 

+ 1 - 1
thirdparty

@@ -1 +1 @@
-Subproject commit 0871551666b161222b505b856028fa10bfbd7699
+Subproject commit f1d4d1f40103028baa4556126ac16e773a6443d6

+ 9 - 1
tools/scene/Exporter.cpp

@@ -833,7 +833,15 @@ void Exporter::exportLight(const aiLight& light)
 		ERROR("Couldn't find node for light %s", light.mName.C_Str());
 	}
 
-	writeNodeTransform("node", node->mTransformation);
+	aiMatrix4x4 rot;
+	aiMatrix4x4::RotationX(-3.1415 / 2.0, rot);
+	writeNodeTransform("node", node->mTransformation * rot);
+
+	// Extra
+	if(light.mShadow)
+	{
+		file << "lcomp:setShadowEnabled(1)\n";
+	}
 }
 
 //==============================================================================

+ 90 - 37
tools/texture/ankitexture.py

@@ -9,6 +9,23 @@ import copy
 import tempfile
 import shutil
 
+#
+# Config
+#
+
+class Config:
+	in_files = []
+	out_file = ""
+	fast = False
+	type = 0 
+	normal = False
+	convert_path = ""
+	no_alpha = False
+	no_uncompressed = False
+	to_linear_rgb = False
+
+	tmp_dir = ""
+
 #
 # AnKi texture
 #
@@ -198,6 +215,16 @@ def parse_commandline():
 			action = "store_true", default = True, 
 			help = "don't store uncompressed data")
 
+	parser.add_option("--to-linear-rgb", dest = "to_linear_rgb", 
+			action = "store_true", default = False, 
+			help = "assume the input textures are sRGB. If this option is " \
+			"true then convert them to linear RGB")
+
+	# Add the default value on each option when printing help
+	for option in parser.option_list:
+		if option.default != ("NO", "DEFAULT"):
+			option.help += (" " if option.help else "") + "[default: %default]"
+
 	(options, args) = parser.parse_args()
 
 	if not options.inp or not options.out or not options.convert_path:
@@ -214,9 +241,18 @@ def parse_commandline():
 	else:
 		parser.error("Unrecognized type: " + options.type)
 
-	return (options.inp.split(":"), options.out, options.fast, \
-			typ, options.normal, options.convert_path, options.no_alpha, \
-			options.no_uncompressed)
+	config = Config()
+	config.in_files = options.inp.split(":")
+	config.out_file = options.out
+	config.fast = options.fast
+	config.type = typ
+	config.normal = options.normal
+	config.convert_path = options.convert_path
+	config.no_alpha = options.no_alpha
+	config.no_uncompressed = options.no_uncompressed
+	config.to_linear_rgb = options.to_linear_rgb
+
+	return config
 
 def identify_image(in_file):
 	""" Return the size of the input image and the internal format """
@@ -260,7 +296,8 @@ def identify_image(in_file):
 
 	return (color_format, int(reg.group(1)), int(reg.group(2)))
 
-def create_mipmaps(in_file, tmp_dir, width_, height_, color_format):
+def create_mipmaps(in_file, tmp_dir, width_, height_, color_format, \
+		to_linear_rgb):
 	""" Create a number of images for all mipmaps """
 
 	printi("Generate mipmaps")
@@ -279,8 +316,25 @@ def create_mipmaps(in_file, tmp_dir, width_, height_, color_format):
 
 		mips_fnames.append(out_file_str)
 
-		args = ["convert", in_file, "-resize", size_str, "-alpha"]
+		args = ["convert", in_file]
+		
+		# to linear
+		if to_linear_rgb:
+			if color_format != CF_RGB8:
+				raise Exception("to linear RGB only supported for RGB textures")
+			
+			args.append("-set") 
+			args.append("colorspace")
+			args.append("sRGB")
+			args.append("-colorspace")
+			args.append("RGB")
+
+		# resize
+		args.append("-resize") 
+		args.append(size_str) 
 
+		# alpha
+		args.append("-alpha") 
 		if color_format == CF_RGB8:
 			args.append("deactivate")
 		else:
@@ -513,43 +567,43 @@ def write_etc(out_file, fname, width, height, color_format):
 
 	out_file.write(data)
 
-def convert(in_files, out, fast, typ, normal, tmp_dir, convert_path, no_alpha, \
-		no_uncompressed):
+def convert(config):
 	""" This is the function that does all the work """
 
 	# Invoke app named "identify" to get internal format and width and height
-	(color_format, width, height) = identify_image(in_files[0])
+	(color_format, width, height) = identify_image(config.in_files[0])
 
 	if not is_power2(width) or not is_power2(height):
 		raise Exception("Image width and height should power of 2")
 
-	if color_format == CF_RGBA8 and normal:
+	if color_format == CF_RGBA8 and config.normal:
 		raise Exception("RGBA image and normal does not make much sense")
 
-	for i in range(1, len(in_files)):
+	for i in range(1, len(config.in_files)):
 		(color_format_2, width_2, height_2) = identify_image(in_files[i])
 
 		if width != width_2 or height != height_2 \
 				or color_format != color_format_2:
 			raise Exception("Images are not same size and color space")
 
-	if no_alpha:
+	if config.no_alpha:
 		color_format = CF_RGB8
 
 	# Create images
-	for in_file in in_files:
-		mips_fnames = create_mipmaps(in_file, tmp_dir, width, height, \
-				color_format)
+	for in_file in config.in_files:
+		mips_fnames = create_mipmaps(in_file, config.tmp_dir, width, height, \
+				color_format, config.to_linear_rgb)
 
 		# Create etc images
-		create_etc_images(mips_fnames, tmp_dir, fast, color_format, \
-				convert_path)
+		create_etc_images(mips_fnames, config.tmp_dir, config.fast, \
+				color_format, config.convert_path)
 
 		# Create dds images
-		create_dds_images(mips_fnames, tmp_dir, fast, color_format, normal)
+		create_dds_images(mips_fnames, config.tmp_dir, config.fast, \
+				color_format, config.normal)
 
 	# Open file
-	fname = out
+	fname = config.out_file
 	printi("Writing %s" % fname)
 	tex_file = open(fname, "wb")
 
@@ -557,18 +611,18 @@ def convert(in_files, out, fast, typ, normal, tmp_dir, convert_path, no_alpha, \
 	ak_format = "8sIIIIIIII"
 
 	data_compression = DC_S3TC | DC_ETC2
-	if not no_uncompressed:
+	if not config.no_uncompressed:
 		data_compression = data_compression | DC_RAW
 
 	buff = struct.pack(ak_format, 
 			b"ANKITEX1",
 			width,
 			height,
-			len(in_files),
-			typ,
+			len(config.in_files),
+			config.type,
 			color_format,
 			data_compression,
-			normal,
+			config.normal,
 			len(mips_fnames))
 
 	tex_file.write(buff)
@@ -592,13 +646,13 @@ def convert(in_files, out, fast, typ, normal, tmp_dir, convert_path, no_alpha, \
 		while tmp_width >= 4 and tmp_height >= 4:
 
 			# For each image
-			for in_file in in_files:
+			for in_file in config.in_files:
 				size_str = "%dx%d" % (tmp_width, tmp_height)
-				in_base_fname = os.path.join(tmp_dir, get_base_fname(in_file)) \
-						+ "." + size_str
+				in_base_fname = os.path.join(config.tmp_dir, \
+						get_base_fname(in_file)) + "." + size_str
 
 				# Write RAW
-				if compression == 0 and not no_uncompressed:
+				if compression == 0 and not config.no_uncompressed:
 					write_raw(tex_file, in_base_fname + ".tga", \
 							tmp_width, tmp_height, color_format)
 				# Write S3TC
@@ -617,31 +671,30 @@ def main():
 	""" The main """
 
 	# Parse cmd line args
-	(in_files, out, fast, typ, normal, convert_path, \
-			no_alpha, no_uncompressed) = parse_commandline();
+	config = parse_commandline();
 
-	if typ == TT_CUBE and len(in_files) != 6:
+	if config.type == TT_CUBE and len(config.in_files) != 6:
 		raise Exception("Not enough images for cube generation")
 
-	if (typ == TT_3D or typ == TT_2D_ARRAY) and len(in_files) < 2:
+	if (config.type == TT_3D or config.type == TT_2D_ARRAY) \
+			and len(config.in_files) < 2:
 		#raise Exception("Not enough images for 2DArray/3D texture")
 		printw("Not enough images for 2DArray/3D texture")
 
-	if typ == TT_2D and len(in_files) != 1:
+	if config.type == TT_2D and len(config.in_files) != 1:
 		raise Exception("Only one image for 2D textures needed")
 
-	if not os.path.isfile(convert_path):
-		raise Exception("Tool convert not found: " + convert_path)
+	if not os.path.isfile(config.convert_path):
+		raise Exception("Tool convert not found: " + config.convert_path)
 
 	# Setup the temp dir
-	tmp_dir = tempfile.mkdtemp("_ankitex")
+	config.tmp_dir = tempfile.mkdtemp("_ankitex")
 
 	# Do the work
 	try:
-		convert(in_files, out, fast, typ, normal, tmp_dir, \
-				convert_path, no_alpha, no_uncompressed)
+		convert(config)
 	finally:
-		shutil.rmtree(tmp_dir)
+		shutil.rmtree(config.tmp_dir)
 		
 	# Done
 	printi("Done!")