Browse Source

Minor change in mesh format

Panagiotis Christopoulos Charitos 10 years ago
parent
commit
e56f465761

+ 5 - 2
include/anki/gr/Enums.h

@@ -102,6 +102,8 @@ enum class VertexStepRate: U8
 
 enum class ComponentFormat: U8
 {
+	NONE,
+
 	R8,
 	R8G8,
 	R8G8B8,
@@ -137,6 +139,7 @@ enum class ComponentFormat: U8
 
 enum class TransformFormat: U8
 {
+	NONE,
 	UNORM,
 	SNORM,
 	UINT,
@@ -199,8 +202,8 @@ ANKI_ENUM_ALLOW_NUMERIC_OPERATIONS(ShaderVariableDataType, inline)
 class PixelFormat
 {
 public:
-	ComponentFormat m_components = ComponentFormat::R8G8B8A8;
-	TransformFormat m_transform = TransformFormat::UNORM;
+	ComponentFormat m_components = ComponentFormat::NONE;
+	TransformFormat m_transform = TransformFormat::NONE;
 	Bool8 m_srgb = false;
 
 	PixelFormat() = default;

+ 4 - 5
shaders/Common.glsl

@@ -3,7 +3,7 @@
 // Code licensed under the BSD License.
 // http://www.anki3d.org/LICENSE
 
-// This file contains common code for all shaders. It's optional but it's 
+// This file contains common code for all shaders. It's optional but it's
 // recomended to include it
 
 #ifndef ANKI_SHADERS_COMMON_GLSL
@@ -29,10 +29,9 @@ precision DEFAULT_FLOAT_PRECISION int;
 
 // Common locations
 #define POSITION_LOCATION 0
-#define NORMAL_LOCATION 1
-#define TANGENT_LOCATION 2
-#define TEXTURE_COORDINATE_LOCATION 3
-#define TEXTURE_COORDINATE_LOCATION_1 4
+#define TEXTURE_COORDINATE_LOCATION 1
+#define NORMAL_LOCATION 2
+#define TANGENT_LOCATION 3
 #define SCALE_LOCATION 6
 #define ALPHA_LOCATION 7
 

+ 5 - 5
shaders/Dbg.vert.glsl

@@ -6,10 +6,10 @@
 #pragma anki type vert
 #pragma anki include "shaders/Common.glsl"
 
-layout(location = 0) in vec4 inPosition;
-layout(location = 1) in vec4 inColor;
+layout(location = 0) in vec4 in_position;
+layout(location = 1) in vec4 in_color;
 
-layout(location = 0) out vec4 outColor;
+layout(location = 0) out vec4 out_color;
 
 out gl_PerVertex
 {
@@ -18,6 +18,6 @@ out gl_PerVertex
 
 void main()
 {
-	outColor = inColor;
-	gl_Position = inPosition;
+	out_color = in_color;
+	gl_Position = in_position;
 }

+ 7 - 0
src/gr/gl/PipelineImpl.cpp

@@ -294,6 +294,13 @@ void PipelineImpl::initVertexState()
 			cache.m_type = GL_HALF_FLOAT;
 			cache.m_normalized = false;
 		}
+		else if(binding.m_format == PixelFormat(
+			ComponentFormat::R16G16, TransformFormat::UNORM))
+		{
+			cache.m_compCount = 2;
+			cache.m_type = GL_UNSIGNED_SHORT;
+			cache.m_normalized = true;
+		}
 		else if(binding.m_format == PixelFormat(
 			ComponentFormat::R10G10B10A2, TransformFormat::SNORM))
 		{

+ 1 - 1
src/resource/MeshLoader.cpp

@@ -34,7 +34,7 @@ Error MeshLoader::load(const ResourceFilename& filename)
 	//
 	// Check header
 	//
-	if(memcmp(&m_header.m_magic[0], "ANKIMES2", 8) != 0)
+	if(memcmp(&m_header.m_magic[0], "ANKIMES3", 8) != 0)
 	{
 		ANKI_LOGE("Wrong magic word");
 		return ErrorCode::USER_DATA;

+ 15 - 8
src/resource/Model.cpp

@@ -161,23 +161,30 @@ void ModelPatch::computePipelineInitializer(
 		vert.m_bindingCount = 1;
 		vert.m_attributeCount = 4;
 		vert.m_bindings[0].m_stride =
-			sizeof(Vec3) + 2 * sizeof(U32) + sizeof(HVec2);
+			sizeof(Vec3) + sizeof(HVec2) + 2 * sizeof(U32);
 
 		vert.m_attributes[0].m_format = PixelFormat(
 			ComponentFormat::R32G32B32, TransformFormat::FLOAT);
 		vert.m_attributes[0].m_offset = 0;
 
 		vert.m_attributes[1].m_format = PixelFormat(
-			ComponentFormat::R10G10B10A2, TransformFormat::SNORM);
+			ComponentFormat::R16G16, TransformFormat::FLOAT);
 		vert.m_attributes[1].m_offset = sizeof(Vec3);
 
-		vert.m_attributes[2].m_format = PixelFormat(
-			ComponentFormat::R10G10B10A2, TransformFormat::SNORM);
-		vert.m_attributes[2].m_offset = sizeof(Vec3) + sizeof(U32);
+		if(key.m_pass == Pass::MS_FS)
+		{
+			vert.m_attributes[2].m_format = PixelFormat(
+				ComponentFormat::R10G10B10A2, TransformFormat::SNORM);
+			vert.m_attributes[2].m_offset = sizeof(Vec3) + sizeof(U32);
 
-		vert.m_attributes[3].m_format = PixelFormat(
-			ComponentFormat::R16G16, TransformFormat::FLOAT);
-		vert.m_attributes[3].m_offset = sizeof(Vec3) + 2 * sizeof(U32);
+			vert.m_attributes[3].m_format = PixelFormat(
+				ComponentFormat::R10G10B10A2, TransformFormat::SNORM);
+			vert.m_attributes[3].m_offset = sizeof(Vec3) + sizeof(U32) * 2;
+		}
+		else
+		{
+			vert.m_attributeCount = 2;
+		}
 	}
 
 	//

+ 7 - 6
tools/scene/ExporterMesh.cpp

@@ -4,6 +4,7 @@
 // http://www.anki3d.org/LICENSE
 
 #include "Exporter.h"
+#include <cmath>
 
 //==============================================================================
 enum class ComponentFormat: uint32_t
@@ -80,9 +81,9 @@ struct SubMesh
 struct Vertex
 {
 	float m_position[3];
+	uint16_t m_uv[2];
 	uint32_t m_normal;
 	uint32_t m_tangent;
-	uint16_t m_uv[2];
 };
 
 //==============================================================================
@@ -233,7 +234,7 @@ void Exporter::exportMesh(
 	}
 
 	// Write header
-	static const char* magic = "ANKIMES2";
+	static const char* magic = "ANKIMES3";
 	memcpy(&header.m_magic, magic, 8);
 
 	header.m_positionsFormat.m_components = ComponentFormat::R32G32B32;
@@ -333,6 +334,10 @@ void Exporter::exportMesh(
 		vert.m_position[1] = pos[1];
 		vert.m_position[2] = pos[2];
 
+		// Tex coords
+		vert.m_uv[0] = toF16(uv[0]);
+		vert.m_uv[1] = toF16(uv[1]);
+
 		// Normal
 		vert.m_normal = toR10G10B10A2Sint(n[0], n[1], n[2], 0.0);
 
@@ -340,10 +345,6 @@ void Exporter::exportMesh(
 		float w = ((n ^ t) * b < 0.0) ? 1.0 : -1.0;
 		vert.m_tangent = toR10G10B10A2Sint(t[0], t[1], t[2], w);
 
-		// Tex coords
-		vert.m_uv[0] = toF16(uv[0]);
-		vert.m_uv[1] = toF16(uv[1]);
-
 		// Write
 		file.write(reinterpret_cast<char*>(&vert), sizeof(vert));
 	}