From 811484a3cea3eb187b7e7705a298aaebec5324a5 Mon Sep 17 00:00:00 2001 From: turanszkij Date: Sun, 10 Sep 2017 16:38:47 +0200 Subject: [PATCH] refactored vertex streams --- WickedEngine/CommonInclude.h | 2 + WickedEngine/ResourceMapping.h | 5 +- WickedEngine/skinningCS.hlsl | 29 +- WickedEngine/wiBULLET.cpp | 30 +- WickedEngine/wiEmittedParticle.cpp | 12 +- WickedEngine/wiHairParticle.cpp | 18 +- WickedEngine/wiLoader.cpp | 484 ++++++++++++++++------------- WickedEngine/wiLoader.h | 193 ++++++++---- WickedEngine/wiRenderer.cpp | 102 +++--- WickedEngine/wiRenderer.h | 2 +- WickedEngine/wiVersion.cpp | 2 +- 11 files changed, 502 insertions(+), 377 deletions(-) diff --git a/WickedEngine/CommonInclude.h b/WickedEngine/CommonInclude.h index a3a46e9b6..4960531f1 100644 --- a/WickedEngine/CommonInclude.h +++ b/WickedEngine/CommonInclude.h @@ -15,7 +15,9 @@ // Platform agnostic: #include +#include using namespace DirectX; +using namespace DirectX::PackedVector; #define ALIGN_16 void* operator new(size_t i){return _mm_malloc(i, 16);} void operator delete(void* p){_mm_free(p);} #define SAFE_INIT(a) (a) = nullptr; diff --git a/WickedEngine/ResourceMapping.h b/WickedEngine/ResourceMapping.h index 7ef93598f..510f6369e 100644 --- a/WickedEngine/ResourceMapping.h +++ b/WickedEngine/ResourceMapping.h @@ -67,9 +67,8 @@ // Skinning: #define SKINNINGSLOT_IN_VERTEX_POS 0 #define SKINNINGSLOT_IN_VERTEX_NOR 1 -#define SKINNINGSLOT_IN_VERTEX_WEI 2 -#define SKINNINGSLOT_IN_VERTEX_BON 3 -#define SKINNINGSLOT_IN_BONEBUFFER 4 +#define SKINNINGSLOT_IN_VERTEX_BON 2 +#define SKINNINGSLOT_IN_BONEBUFFER 3 #define SKINNINGSLOT_OUT_VERTEX_POS 0 #define SKINNINGSLOT_OUT_VERTEX_NOR 1 diff --git a/WickedEngine/skinningCS.hlsl b/WickedEngine/skinningCS.hlsl index e0188a6cb..8db8e3e69 100644 --- a/WickedEngine/skinningCS.hlsl +++ b/WickedEngine/skinningCS.hlsl @@ -9,7 +9,6 @@ STRUCTUREDBUFFER(boneBuffer, Bone, SKINNINGSLOT_IN_BONEBUFFER); RAWBUFFER(vertexBuffer_POS, SKINNINGSLOT_IN_VERTEX_POS); RAWBUFFER(vertexBuffer_NOR, SKINNINGSLOT_IN_VERTEX_NOR); -RAWBUFFER(vertexBuffer_WEI, SKINNINGSLOT_IN_VERTEX_WEI); RAWBUFFER(vertexBuffer_BON, SKINNINGSLOT_IN_VERTEX_BON); RWRAWBUFFER(streamoutBuffer_POS, SKINNINGSLOT_OUT_VERTEX_POS); @@ -49,24 +48,32 @@ inline void Skinning(inout float4 pos, inout float4 nor, in float4 inBon, in flo [numthreads(SKINNING_COMPUTE_THREADCOUNT, 1, 1)] void main( uint3 DTid : SV_DispatchThreadID ) { - const uint fetchAddress = DTid.x * 16; + const uint stride_POS = 16; + const uint stride_NOR = 16; + const uint stride_BON_IND = 16; + const uint stride_BON_WEI = 16; - uint4 pos_u = vertexBuffer_POS.Load4(fetchAddress); - uint4 nor_u = vertexBuffer_NOR.Load4(fetchAddress); - uint4 wei_u = vertexBuffer_WEI.Load4(fetchAddress); - uint4 bon_u = vertexBuffer_BON.Load4(fetchAddress); + const uint fetchAddress_POS = DTid.x * stride_POS; + const uint fetchAddress_NOR = DTid.x * stride_NOR; + const uint fetchAddress_BON_IND = DTid.x * (stride_BON_IND + stride_BON_WEI) + 0; + const uint fetchAddress_BON_WEI = DTid.x * (stride_BON_IND + stride_BON_WEI) + stride_BON_IND; + + uint4 pos_u = vertexBuffer_POS.Load4(fetchAddress_POS); + uint4 nor_u = vertexBuffer_NOR.Load4(fetchAddress_NOR); + uint4 ind_u = vertexBuffer_BON.Load4(fetchAddress_BON_IND); + uint4 wei_u = vertexBuffer_BON.Load4(fetchAddress_BON_WEI); float4 pos = asfloat(pos_u); float4 nor = asfloat(nor_u); + float4 ind = asfloat(ind_u); float4 wei = asfloat(wei_u); - float4 bon = asfloat(bon_u); - Skinning(pos, nor, bon, wei); + Skinning(pos, nor, ind, wei); pos_u = asuint(pos); nor_u = asuint(nor); - streamoutBuffer_PRE.Store4(fetchAddress, streamoutBuffer_POS.Load4(fetchAddress)); // copy prev frame current pos to current frame prev pos - streamoutBuffer_POS.Store4(fetchAddress, pos_u); - streamoutBuffer_NOR.Store4(fetchAddress, nor_u); + streamoutBuffer_PRE.Store4(fetchAddress_POS, streamoutBuffer_POS.Load4(fetchAddress_POS)); // copy prev frame current pos to current frame prev pos + streamoutBuffer_POS.Store4(fetchAddress_POS, pos_u); + streamoutBuffer_NOR.Store4(fetchAddress_NOR, nor_u); } \ No newline at end of file diff --git a/WickedEngine/wiBULLET.cpp b/WickedEngine/wiBULLET.cpp index 9348cf7cd..520baaabc 100644 --- a/WickedEngine/wiBULLET.cpp +++ b/WickedEngine/wiBULLET.cpp @@ -11,6 +11,8 @@ #include "BulletSoftBody/btDefaultSoftBodySolver.h" #include "BulletSoftBody/btSoftBodyRigidBodyCollisionConfiguration.h" +using namespace std; + int PHYSICS::softBodyIterationCount=5; bool PHYSICS::rigidBodyPhysicsEnabled = true, PHYSICS::softBodyPhysicsEnabled = true; bool wiBULLET::grab=false; @@ -585,15 +587,15 @@ void wiBULLET::connectVerticesToSoftBody(Mesh* const mesh, int objectI){ btSoftBody::tNodeArray& nodes(softBody->m_nodes); int gvg = mesh->goalVG; - for (unsigned int i = 0; ivertices[VPROP_POS].size(); ++i) + for (unsigned int i = 0; ivertices_POS.size(); ++i) { int indexP = mesh->physicalmapGP[i]; float weight = mesh->vertexGroups[gvg].vertices[indexP]; - mesh->vertices_Transformed[VPROP_PRE][i] = mesh->vertices_Transformed[VPROP_POS][i]; - mesh->vertices_Transformed[VPROP_POS][i] = XMFLOAT4(nodes[indexP].m_x.getX(), nodes[indexP].m_x.getY(), nodes[indexP].m_x.getZ(), mesh->vertices[VPROP_POS][i].w); - mesh->vertices_Transformed[VPROP_NOR][i].x = -nodes[indexP].m_n.getX(); - mesh->vertices_Transformed[VPROP_NOR][i].y = -nodes[indexP].m_n.getY(); - mesh->vertices_Transformed[VPROP_NOR][i].z = -nodes[indexP].m_n.getZ(); + mesh->vertices_Transformed_PRE[i].pos = mesh->vertices_Transformed_POS[i].pos; + mesh->vertices_Transformed_POS[i].pos = XMFLOAT4(nodes[indexP].m_x.getX(), nodes[indexP].m_x.getY(), nodes[indexP].m_x.getZ(), mesh->vertices_POS[i].pos.w); + mesh->vertices_Transformed_NOR[i].nor.x = -nodes[indexP].m_n.getX(); + mesh->vertices_Transformed_NOR[i].nor.y = -nodes[indexP].m_n.getY(); + mesh->vertices_Transformed_NOR[i].nor.z = -nodes[indexP].m_n.getZ(); } } } @@ -699,8 +701,14 @@ void wiBULLET::registerObject(Object* object){ object->physicsObjectID = ++registeredObjects; } if(!object->collisionShape.compare("CONVEX_HULL")){ + vector pos_stream(object->mesh->vertices_POS.size()); + for (size_t i = 0; i < object->mesh->vertices_POS.size(); ++i) + { + pos_stream[i] = object->mesh->vertices_POS[i].pos; + } + addConvexHull( - object->mesh->vertices[VPROP_POS], + pos_stream, S,R,T ,object->mass,object->friction,object->restitution ,object->damping,object->kinematic @@ -708,8 +716,14 @@ void wiBULLET::registerObject(Object* object){ object->physicsObjectID = ++registeredObjects; } if(!object->collisionShape.compare("MESH")){ + vector pos_stream(object->mesh->vertices_POS.size()); + for (size_t i = 0; i < object->mesh->vertices_POS.size(); ++i) + { + pos_stream[i] = object->mesh->vertices_POS[i].pos; + } + addTriangleMesh( - object->mesh->vertices[VPROP_POS],object->mesh->indices, + pos_stream,object->mesh->indices, S,R,T ,object->mass,object->friction,object->restitution ,object->damping,object->kinematic diff --git a/WickedEngine/wiEmittedParticle.cpp b/WickedEngine/wiEmittedParticle.cpp index 22797b517..67824ec7e 100644 --- a/WickedEngine/wiEmittedParticle.cpp +++ b/WickedEngine/wiEmittedParticle.cpp @@ -144,16 +144,16 @@ void wiEmittedParticle::addPoint(const XMMATRIX& t4, const XMMATRIX& t3) XMFLOAT3 pos; XMFLOAT3 vel; XMVECTOR& vbar=XMVectorBaryCentric( - XMLoadFloat4(&object->mesh->vertices[VPROP_POS][object->mesh->indices[gen[0]]]) - , XMLoadFloat4(&object->mesh->vertices[VPROP_POS][object->mesh->indices[gen[1]]]) - , XMLoadFloat4(&object->mesh->vertices[VPROP_POS][object->mesh->indices[gen[2]]]) + XMLoadFloat4(&object->mesh->vertices_POS[object->mesh->indices[gen[0]]].pos) + , XMLoadFloat4(&object->mesh->vertices_POS[object->mesh->indices[gen[1]]].pos) + , XMLoadFloat4(&object->mesh->vertices_POS[object->mesh->indices[gen[2]]].pos) , f , g ); XMVECTOR& nbar=XMVectorBaryCentric( - XMLoadFloat4(&object->mesh->vertices[VPROP_NOR][object->mesh->indices[gen[0]]]) - , XMLoadFloat4(&object->mesh->vertices[VPROP_NOR][object->mesh->indices[gen[1]]]) - , XMLoadFloat4(&object->mesh->vertices[VPROP_NOR][object->mesh->indices[gen[2]]]) + XMLoadFloat4(&object->mesh->vertices_NOR[object->mesh->indices[gen[0]]].nor) + , XMLoadFloat4(&object->mesh->vertices_NOR[object->mesh->indices[gen[1]]].nor) + , XMLoadFloat4(&object->mesh->vertices_NOR[object->mesh->indices[gen[2]]].nor) , f , g ); diff --git a/WickedEngine/wiHairParticle.cpp b/WickedEngine/wiHairParticle.cpp index ce5e21c17..66b52332d 100644 --- a/WickedEngine/wiHairParticle.cpp +++ b/WickedEngine/wiHairParticle.cpp @@ -312,13 +312,17 @@ void wiHairParticle::Generate() if (lenMod[m] < 0) lenMod[m] = 0; } - Vertex verts[3]; - verts[0].pos = mesh->vertices[VPROP_POS][vi[0]]; - verts[0].nor = mesh->vertices[VPROP_NOR][vi[0]]; - verts[1].pos = mesh->vertices[VPROP_POS][vi[1]]; - verts[1].nor = mesh->vertices[VPROP_NOR][vi[1]]; - verts[2].pos = mesh->vertices[VPROP_POS][vi[2]]; - verts[2].nor = mesh->vertices[VPROP_NOR][vi[2]]; + Mesh::Vertex_FULL verts[] = { + mesh->vertices_FULL[vi[0]], + mesh->vertices_FULL[vi[1]], + mesh->vertices_FULL[vi[2]], + }; + //verts[0].pos = mesh->vertices_POS[vi[0]].pos; + //verts[0].nor = mesh->vertices_NOR[vi[0]].nor; + //verts[1].pos = mesh->vertices_POS[vi[1]].pos; + //verts[1].nor = mesh->vertices_NOR[vi[1]].nor; + //verts[2].pos = mesh->vertices_POS[vi[2]].pos; + //verts[2].nor = mesh->vertices_NOR[vi[2]].nor; if( (denMod[0]>FLT_EPSILON || denMod[1]>FLT_EPSILON || denMod[2]>FLT_EPSILON) && diff --git a/WickedEngine/wiLoader.cpp b/WickedEngine/wiLoader.cpp index 2b53ac1f7..9094102b1 100644 --- a/WickedEngine/wiLoader.cpp +++ b/WickedEngine/wiLoader.cpp @@ -532,29 +532,26 @@ void LoadWiMeshes(const std::string& directory, const std::string& name, const s } break; case 'v': - for (int vprop = 0; vprop < VPROP_COUNT; ++vprop) - { - currentMesh->vertices[vprop].push_back(XMFLOAT4(0,0,0,0)); - } - file >> currentMesh->vertices[VPROP_POS].back().x; - file >> currentMesh->vertices[VPROP_POS].back().y; - file >> currentMesh->vertices[VPROP_POS].back().z; + currentMesh->vertices_FULL.push_back(Mesh::Vertex_FULL()); + file >> currentMesh->vertices_FULL.back().pos.x; + file >> currentMesh->vertices_FULL.back().pos.y; + file >> currentMesh->vertices_FULL.back().pos.z; break; case 'n': if (currentMesh->isBillboarded){ - currentMesh->vertices[VPROP_NOR].back().x = currentMesh->billboardAxis.x; - currentMesh->vertices[VPROP_NOR].back().y = currentMesh->billboardAxis.y; - currentMesh->vertices[VPROP_NOR].back().z = currentMesh->billboardAxis.z; + currentMesh->vertices_FULL.back().nor.x = currentMesh->billboardAxis.x; + currentMesh->vertices_FULL.back().nor.y = currentMesh->billboardAxis.y; + currentMesh->vertices_FULL.back().nor.z = currentMesh->billboardAxis.z; } else{ - file >> currentMesh->vertices[VPROP_NOR].back().x; - file >> currentMesh->vertices[VPROP_NOR].back().y; - file >> currentMesh->vertices[VPROP_NOR].back().z; + file >> currentMesh->vertices_FULL.back().nor.x; + file >> currentMesh->vertices_FULL.back().nor.y; + file >> currentMesh->vertices_FULL.back().nor.z; } break; case 'u': - file >> currentMesh->vertices[VPROP_TEX].back().x; - file >> currentMesh->vertices[VPROP_TEX].back().y; + file >> currentMesh->vertices_FULL.back().tex.x; + file >> currentMesh->vertices_FULL.back().tex.y; //texCoordFill++; break; case 'w': @@ -591,30 +588,30 @@ void LoadWiMeshes(const std::string& directory, const std::string& name, const s } } if (gotBone) { //ONLY PROCEED IF CORRESPONDING BONE WAS FOUND - if (!currentMesh->vertices[VPROP_WEI].back().x) { - currentMesh->vertices[VPROP_WEI].back().x = weight; - currentMesh->vertices[VPROP_BON].back().x = (float)BONEINDEX; + if (!currentMesh->vertices_FULL.back().wei.x) { + currentMesh->vertices_FULL.back().wei.x = weight; + currentMesh->vertices_FULL.back().ind.x = (float)BONEINDEX; } - else if(!currentMesh->vertices[VPROP_WEI].back().y) { - currentMesh->vertices[VPROP_WEI].back().y=weight; - currentMesh->vertices[VPROP_BON].back().y=(float)BONEINDEX; + else if(!currentMesh->vertices_FULL.back().wei.y) { + currentMesh->vertices_FULL.back().wei.y=weight; + currentMesh->vertices_FULL.back().ind.y=(float)BONEINDEX; } - else if(!currentMesh->vertices[VPROP_WEI].back().z) { - currentMesh->vertices[VPROP_WEI].back().z=weight; - currentMesh->vertices[VPROP_BON].back().z=(float)BONEINDEX; + else if(!currentMesh->vertices_FULL.back().wei.z) { + currentMesh->vertices_FULL.back().wei.z=weight; + currentMesh->vertices_FULL.back().ind.z=(float)BONEINDEX; } - else if(!currentMesh->vertices[VPROP_WEI].back().w) { - currentMesh->vertices[VPROP_WEI].back().w = weight; - currentMesh->vertices[VPROP_BON].back().w = (float)BONEINDEX; + else if(!currentMesh->vertices_FULL.back().wei.w) { + currentMesh->vertices_FULL.back().wei.w = weight; + currentMesh->vertices_FULL.back().ind.w = (float)BONEINDEX; } } //(+RIBBONTRAIL SETUP)(+VERTEXGROUP SETUP) if(nameB.find("trailbase")!=string::npos) - currentMesh->trailInfo.base = (int)(currentMesh->vertices[VPROP_POS].size()-1); + currentMesh->trailInfo.base = (int)(currentMesh->vertices_FULL.size()-1); else if(nameB.find("trailtip")!=string::npos) - currentMesh->trailInfo.tip = (int)(currentMesh->vertices[VPROP_POS].size()-1); + currentMesh->trailInfo.tip = (int)(currentMesh->vertices_FULL.size()-1); bool windAffection=false; if(nameB.find("wind")!=string::npos) @@ -623,15 +620,15 @@ void LoadWiMeshes(const std::string& directory, const std::string& name, const s for (unsigned int v = 0; vvertexGroups.size(); ++v) if(!nameB.compare(currentMesh->vertexGroups[v].name)){ gotvg=true; - currentMesh->vertexGroups[v].addVertex(VertexRef((int)(currentMesh->vertices[VPROP_POS].size() - 1), weight)); + currentMesh->vertexGroups[v].addVertex(VertexRef((int)(currentMesh->vertices_FULL.size() - 1), weight)); if(windAffection) - currentMesh->vertices[VPROP_POS].back().w=weight; + currentMesh->vertices_FULL.back().pos.w=weight; } if(!gotvg){ currentMesh->vertexGroups.push_back(VertexGroup(nameB)); - currentMesh->vertexGroups.back().addVertex(VertexRef((int)(currentMesh->vertices[VPROP_POS].size() - 1), weight)); + currentMesh->vertexGroups.back().addVertex(VertexRef((int)(currentMesh->vertices_FULL.size() - 1), weight)); if(windAffection) - currentMesh->vertices[VPROP_POS].back().w=weight; + currentMesh->vertices_FULL.back().pos.w=weight; } } break; @@ -681,7 +678,7 @@ void LoadWiMeshes(const std::string& directory, const std::string& name, const s } break; case 'a': - file>>currentMesh->vertices[VPROP_TEX].back().z; + file>>currentMesh->vertices_FULL.back().tex.z; break; case 'B': for(int corner=0;corner<8;++corner){ @@ -1658,7 +1655,10 @@ void VertexGroup::Serialize(wiArchive& archive) #pragma region MESH -GPUBuffer Mesh::impostorVBs[VPROP_COUNT]; +//GPUBuffer Mesh::impostorVBs[VPROP_COUNT]; +GPUBuffer Mesh::impostorVB_POS; +GPUBuffer Mesh::impostorVB_NOR; +GPUBuffer Mesh::impostorVB_TEX; void Mesh::LoadFromFile(const std::string& newName, const std::string& fname , const MaterialCollection& materialColl, const list& armatures, const std::string& identifier) { @@ -1751,35 +1751,32 @@ void Mesh::LoadFromFile(const std::string& newName, const std::string& fname memcpy(&vertexCount, buffer + offset, sizeof(int)); offset += sizeof(int); - for (int vprop = 0; vprop < VPROP_COUNT; ++vprop) - { - vertices[vprop].resize(vertexCount); - } + vertices_FULL.resize(vertexCount); for (int i = 0; iindices[i]; } - ForsythVertexIndexType* result = forsythReorderIndices(_indices_out, _indices_in, (int)(this->indices.size() / 3), (int)(this->vertices->size())); + ForsythVertexIndexType* result = forsythReorderIndices(_indices_out, _indices_in, (int)(this->indices.size() / 3), (int)(this->vertices_FULL.size())); for (size_t i = 0; i < indices.size(); ++i) { @@ -1988,7 +1985,7 @@ void Mesh::CreateBuffers(Object* object) { if (!buffersComplete) { - if (vertices[VPROP_POS].empty()) + if (vertices_POS.empty()) { renderable = false; } @@ -2017,37 +2014,68 @@ void Mesh::CreateBuffers(Object* object) goalNormals.resize(vertexGroups[goalVG].vertices.size()); } - for (int vprop = 0; vprop < VPROP_COUNT; ++vprop) { ZeroMemory(&bd, sizeof(bd)); bd.Usage = (softBody ? USAGE_DYNAMIC : USAGE_IMMUTABLE); bd.CPUAccessFlags = (softBody ? CPU_ACCESS_WRITE : 0); - bd.ByteWidth = (UINT)(sizeof(XMFLOAT4) * vertices[vprop].size()); bd.BindFlags = BIND_VERTEX_BUFFER | BIND_SHADER_RESOURCE; bd.MiscFlags = RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS; ZeroMemory(&InitData, sizeof(InitData)); - InitData.pSysMem = vertices[vprop].data(); - wiRenderer::GetDevice()->CreateBuffer(&bd, &InitData, &vertexBuffers[vprop]); - if (object->isArmatureDeformed() && !softBody && vprop != VPROP_TEX && vprop != VPROP_WEI) { + InitData.pSysMem = vertices_POS.data(); + bd.ByteWidth = (UINT)(sizeof(Vertex_POS) * vertices_POS.size()); + wiRenderer::GetDevice()->CreateBuffer(&bd, &InitData, &vertexBuffer_POS); + + InitData.pSysMem = vertices_NOR.data(); + bd.ByteWidth = (UINT)(sizeof(Vertex_NOR) * vertices_NOR.size()); + wiRenderer::GetDevice()->CreateBuffer(&bd, &InitData, &vertexBuffer_NOR); + + InitData.pSysMem = vertices_TEX.data(); + bd.ByteWidth = (UINT)(sizeof(Vertex_TEX) * vertices_TEX.size()); + wiRenderer::GetDevice()->CreateBuffer(&bd, &InitData, &vertexBuffer_TEX); + + InitData.pSysMem = vertices_BON.data(); + bd.ByteWidth = (UINT)(sizeof(Vertex_BON) * vertices_BON.size()); + wiRenderer::GetDevice()->CreateBuffer(&bd, &InitData, &vertexBuffer_BON); + + if (object->isArmatureDeformed()) { ZeroMemory(&bd, sizeof(bd)); bd.Usage = USAGE_DEFAULT; - bd.ByteWidth = (UINT)(sizeof(XMFLOAT4) * vertices[vprop].size()); bd.BindFlags = BIND_VERTEX_BUFFER | BIND_UNORDERED_ACCESS; bd.CPUAccessFlags = 0; bd.MiscFlags = RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS; - wiRenderer::GetDevice()->CreateBuffer(&bd, nullptr, &streamoutBuffers[vprop]); + + bd.ByteWidth = (UINT)(sizeof(Vertex_POS) * vertices_POS.size()); + wiRenderer::GetDevice()->CreateBuffer(&bd, nullptr, &streamoutBuffer_POS); + + bd.ByteWidth = (UINT)(sizeof(Vertex_NOR) * vertices_NOR.size()); + wiRenderer::GetDevice()->CreateBuffer(&bd, nullptr, &streamoutBuffer_NOR); + + bd.ByteWidth = (UINT)(sizeof(Vertex_POS) * vertices_POS.size()); + wiRenderer::GetDevice()->CreateBuffer(&bd, nullptr, &streamoutBuffer_PRE); + } + + if (softBody) + { + ZeroMemory(&bd, sizeof(bd)); + bd.Usage = USAGE_DYNAMIC; + bd.BindFlags = BIND_VERTEX_BUFFER; + bd.CPUAccessFlags = CPU_ACCESS_WRITE; + bd.MiscFlags = 0; + + bd.ByteWidth = (UINT)(sizeof(Vertex_POS) * vertices_POS.size()); + wiRenderer::GetDevice()->CreateBuffer(&bd, nullptr, &streamoutBuffer_PRE); } } //PHYSICALMAPPING if (!physicsverts.empty() && physicalmapGP.empty()) { - for (unsigned int i = 0; i < vertices[VPROP_POS].size(); ++i) { + for (unsigned int i = 0; i < vertices_POS.size(); ++i) { for (unsigned int j = 0; j < physicsverts.size(); ++j) { - if (fabs(vertices[VPROP_POS][i].x - physicsverts[j].x) < FLT_EPSILON - && fabs(vertices[VPROP_POS][i].y - physicsverts[j].y) < FLT_EPSILON - && fabs(vertices[VPROP_POS][i].z - physicsverts[j].z) < FLT_EPSILON + if (fabs(vertices_POS[i].pos.x - physicsverts[j].x) < FLT_EPSILON + && fabs(vertices_POS[i].pos.y - physicsverts[j].y) < FLT_EPSILON + && fabs(vertices_POS[i].pos.z - physicsverts[j].z) < FLT_EPSILON ) { physicalmapGP.push_back(j); @@ -2098,176 +2126,180 @@ void Mesh::CreateBuffers(Object* object) } void Mesh::CreateImpostorVB() { - if (!impostorVBs[VPROP_POS].IsValid()) + if (!impostorVB_POS.IsValid()) { - XMFLOAT4 impostorVertices[VPROP_COUNT][6 * 6]; + XMFLOAT4 impostorVertices_POS[6 * 6]; + XMFLOAT4 impostorVertices_NOR[6 * 6]; + XMFLOAT4 impostorVertices_TEX[6 * 6]; float stepX = 1.f / 6.f; // front - impostorVertices[VPROP_POS][0] = XMFLOAT4(-1, 1, 0, 0); - impostorVertices[VPROP_NOR][0] = XMFLOAT4(0, 0, -1, 1); - impostorVertices[VPROP_TEX][0] = XMFLOAT4(0, 0, 0, 0); + impostorVertices_POS[0] = XMFLOAT4(-1, 1, 0, 0); + impostorVertices_NOR[0] = XMFLOAT4(0, 0, -1, 1); + impostorVertices_TEX[0] = XMFLOAT4(0, 0, 0, 0); - impostorVertices[VPROP_POS][1] = XMFLOAT4(-1, -1, 0, 0); - impostorVertices[VPROP_NOR][1] = XMFLOAT4(0, 0, -1, 1); - impostorVertices[VPROP_TEX][1] = XMFLOAT4(0, 1, 0, 0); + impostorVertices_POS[1] = XMFLOAT4(-1, -1, 0, 0); + impostorVertices_NOR[1] = XMFLOAT4(0, 0, -1, 1); + impostorVertices_TEX[1] = XMFLOAT4(0, 1, 0, 0); - impostorVertices[VPROP_POS][2] = XMFLOAT4(1, 1, 0, 0); - impostorVertices[VPROP_NOR][2] = XMFLOAT4(0, 0, -1, 1); - impostorVertices[VPROP_TEX][2] = XMFLOAT4(stepX, 0, 0, 0); + impostorVertices_POS[2] = XMFLOAT4(1, 1, 0, 0); + impostorVertices_NOR[2] = XMFLOAT4(0, 0, -1, 1); + impostorVertices_TEX[2] = XMFLOAT4(stepX, 0, 0, 0); - impostorVertices[VPROP_POS][3] = XMFLOAT4(-1, -1, 0, 0); - impostorVertices[VPROP_NOR][3] = XMFLOAT4(0, 0, -1, 1); - impostorVertices[VPROP_TEX][3] = XMFLOAT4(0, 1, 0, 0); + impostorVertices_POS[3] = XMFLOAT4(-1, -1, 0, 0); + impostorVertices_NOR[3] = XMFLOAT4(0, 0, -1, 1); + impostorVertices_TEX[3] = XMFLOAT4(0, 1, 0, 0); - impostorVertices[VPROP_POS][4] = XMFLOAT4(1, -1, 0, 0); - impostorVertices[VPROP_NOR][4] = XMFLOAT4(0, 0, -1, 1); - impostorVertices[VPROP_TEX][4] = XMFLOAT4(stepX, 1, 0, 0); + impostorVertices_POS[4] = XMFLOAT4(1, -1, 0, 0); + impostorVertices_NOR[4] = XMFLOAT4(0, 0, -1, 1); + impostorVertices_TEX[4] = XMFLOAT4(stepX, 1, 0, 0); - impostorVertices[VPROP_POS][5] = XMFLOAT4(1, 1, 0, 0); - impostorVertices[VPROP_NOR][5] = XMFLOAT4(0, 0, -1, 1); - impostorVertices[VPROP_TEX][5] = XMFLOAT4(stepX, 0, 0, 0); + impostorVertices_POS[5] = XMFLOAT4(1, 1, 0, 0); + impostorVertices_NOR[5] = XMFLOAT4(0, 0, -1, 1); + impostorVertices_TEX[5] = XMFLOAT4(stepX, 0, 0, 0); // right - impostorVertices[VPROP_POS][6] = XMFLOAT4(0, 1, -1, 0); - impostorVertices[VPROP_NOR][6] = XMFLOAT4(1, 0, 0, 1); - impostorVertices[VPROP_TEX][6] = XMFLOAT4(stepX, 0, 0, 0); + impostorVertices_POS[6] = XMFLOAT4(0, 1, -1, 0); + impostorVertices_NOR[6] = XMFLOAT4(1, 0, 0, 1); + impostorVertices_TEX[6] = XMFLOAT4(stepX, 0, 0, 0); - impostorVertices[VPROP_POS][7] = XMFLOAT4(0, -1, -1, 0); - impostorVertices[VPROP_NOR][7] = XMFLOAT4(1, 0, 0, 1); - impostorVertices[VPROP_TEX][7] = XMFLOAT4(stepX, 1, 0, 0); + impostorVertices_POS[7] = XMFLOAT4(0, -1, -1, 0); + impostorVertices_NOR[7] = XMFLOAT4(1, 0, 0, 1); + impostorVertices_TEX[7] = XMFLOAT4(stepX, 1, 0, 0); - impostorVertices[VPROP_POS][8] = XMFLOAT4(0, 1, 1, 0); - impostorVertices[VPROP_NOR][8] = XMFLOAT4(1, 0, 0, 1); - impostorVertices[VPROP_TEX][8] = XMFLOAT4(stepX*2, 0, 0, 0); + impostorVertices_POS[8] = XMFLOAT4(0, 1, 1, 0); + impostorVertices_NOR[8] = XMFLOAT4(1, 0, 0, 1); + impostorVertices_TEX[8] = XMFLOAT4(stepX*2, 0, 0, 0); - impostorVertices[VPROP_POS][9] = XMFLOAT4(0, -1, -1, 0); - impostorVertices[VPROP_NOR][9] = XMFLOAT4(1, 0, 0, 1); - impostorVertices[VPROP_TEX][9] = XMFLOAT4(stepX, 1, 0, 0); + impostorVertices_POS[9] = XMFLOAT4(0, -1, -1, 0); + impostorVertices_NOR[9] = XMFLOAT4(1, 0, 0, 1); + impostorVertices_TEX[9] = XMFLOAT4(stepX, 1, 0, 0); - impostorVertices[VPROP_POS][10] = XMFLOAT4(0, -1, 1, 0); - impostorVertices[VPROP_NOR][10] = XMFLOAT4(1, 0, 0, 1); - impostorVertices[VPROP_TEX][10] = XMFLOAT4(stepX*2, 1, 0, 0); + impostorVertices_POS[10] = XMFLOAT4(0, -1, 1, 0); + impostorVertices_NOR[10] = XMFLOAT4(1, 0, 0, 1); + impostorVertices_TEX[10] = XMFLOAT4(stepX*2, 1, 0, 0); - impostorVertices[VPROP_POS][11] = XMFLOAT4(0, 1, 1, 0); - impostorVertices[VPROP_NOR][11] = XMFLOAT4(1, 0, 0, 1); - impostorVertices[VPROP_TEX][11] = XMFLOAT4(stepX*2, 0, 0, 0); + impostorVertices_POS[11] = XMFLOAT4(0, 1, 1, 0); + impostorVertices_NOR[11] = XMFLOAT4(1, 0, 0, 1); + impostorVertices_TEX[11] = XMFLOAT4(stepX*2, 0, 0, 0); // back - impostorVertices[VPROP_POS][12] = XMFLOAT4(-1, 1, 0, 0); - impostorVertices[VPROP_NOR][12] = XMFLOAT4(0, 0, -1, 1); - impostorVertices[VPROP_TEX][12] = XMFLOAT4(stepX*3, 0, 0, 0); + impostorVertices_POS[12] = XMFLOAT4(-1, 1, 0, 0); + impostorVertices_NOR[12] = XMFLOAT4(0, 0, -1, 1); + impostorVertices_TEX[12] = XMFLOAT4(stepX*3, 0, 0, 0); - impostorVertices[VPROP_POS][13] = XMFLOAT4(1, 1, 0, 0); - impostorVertices[VPROP_NOR][13] = XMFLOAT4(0, 0, -1, 1); - impostorVertices[VPROP_TEX][13] = XMFLOAT4(stepX * 2, 0, 0, 0); + impostorVertices_POS[13] = XMFLOAT4(1, 1, 0, 0); + impostorVertices_NOR[13] = XMFLOAT4(0, 0, -1, 1); + impostorVertices_TEX[13] = XMFLOAT4(stepX * 2, 0, 0, 0); - impostorVertices[VPROP_POS][14] = XMFLOAT4(-1, -1, 0, 0); - impostorVertices[VPROP_NOR][14] = XMFLOAT4(0, 0, -1, 1); - impostorVertices[VPROP_TEX][14] = XMFLOAT4(stepX*3, 1, 0, 0); + impostorVertices_POS[14] = XMFLOAT4(-1, -1, 0, 0); + impostorVertices_NOR[14] = XMFLOAT4(0, 0, -1, 1); + impostorVertices_TEX[14] = XMFLOAT4(stepX*3, 1, 0, 0); - impostorVertices[VPROP_POS][15] = XMFLOAT4(-1, -1, 0, 0); - impostorVertices[VPROP_NOR][15] = XMFLOAT4(0, 0, -1, 1); - impostorVertices[VPROP_TEX][15] = XMFLOAT4(stepX*3, 1, 0, 0); + impostorVertices_POS[15] = XMFLOAT4(-1, -1, 0, 0); + impostorVertices_NOR[15] = XMFLOAT4(0, 0, -1, 1); + impostorVertices_TEX[15] = XMFLOAT4(stepX*3, 1, 0, 0); - impostorVertices[VPROP_POS][16] = XMFLOAT4(1, 1, 0, 0); - impostorVertices[VPROP_NOR][16] = XMFLOAT4(0, 0, -1, 1); - impostorVertices[VPROP_TEX][16] = XMFLOAT4(stepX*2, 0, 0, 0); + impostorVertices_POS[16] = XMFLOAT4(1, 1, 0, 0); + impostorVertices_NOR[16] = XMFLOAT4(0, 0, -1, 1); + impostorVertices_TEX[16] = XMFLOAT4(stepX*2, 0, 0, 0); - impostorVertices[VPROP_POS][17] = XMFLOAT4(1, -1, 0, 0); - impostorVertices[VPROP_NOR][17] = XMFLOAT4(0, 0, -1, 1); - impostorVertices[VPROP_TEX][17] = XMFLOAT4(stepX*2, 1, 0, 0); + impostorVertices_POS[17] = XMFLOAT4(1, -1, 0, 0); + impostorVertices_NOR[17] = XMFLOAT4(0, 0, -1, 1); + impostorVertices_TEX[17] = XMFLOAT4(stepX*2, 1, 0, 0); // left - impostorVertices[VPROP_POS][18] = XMFLOAT4(0, 1, -1, 0); - impostorVertices[VPROP_NOR][18] = XMFLOAT4(1, 0, 0, 1); - impostorVertices[VPROP_TEX][18] = XMFLOAT4(stepX*4, 0, 0, 0); + impostorVertices_POS[18] = XMFLOAT4(0, 1, -1, 0); + impostorVertices_NOR[18] = XMFLOAT4(1, 0, 0, 1); + impostorVertices_TEX[18] = XMFLOAT4(stepX*4, 0, 0, 0); - impostorVertices[VPROP_POS][19] = XMFLOAT4(0, 1, 1, 0); - impostorVertices[VPROP_NOR][19] = XMFLOAT4(1, 0, 0, 1); - impostorVertices[VPROP_TEX][19] = XMFLOAT4(stepX * 3, 0, 0, 0); + impostorVertices_POS[19] = XMFLOAT4(0, 1, 1, 0); + impostorVertices_NOR[19] = XMFLOAT4(1, 0, 0, 1); + impostorVertices_TEX[19] = XMFLOAT4(stepX * 3, 0, 0, 0); - impostorVertices[VPROP_POS][20] = XMFLOAT4(0, -1, -1, 0); - impostorVertices[VPROP_NOR][20] = XMFLOAT4(1, 0, 0, 1); - impostorVertices[VPROP_TEX][20] = XMFLOAT4(stepX*4, 1, 0, 0); + impostorVertices_POS[20] = XMFLOAT4(0, -1, -1, 0); + impostorVertices_NOR[20] = XMFLOAT4(1, 0, 0, 1); + impostorVertices_TEX[20] = XMFLOAT4(stepX*4, 1, 0, 0); - impostorVertices[VPROP_POS][21] = XMFLOAT4(0, -1, -1, 0); - impostorVertices[VPROP_NOR][21] = XMFLOAT4(1, 0, 0, 1); - impostorVertices[VPROP_TEX][21] = XMFLOAT4(stepX*4, 1, 0, 0); + impostorVertices_POS[21] = XMFLOAT4(0, -1, -1, 0); + impostorVertices_NOR[21] = XMFLOAT4(1, 0, 0, 1); + impostorVertices_TEX[21] = XMFLOAT4(stepX*4, 1, 0, 0); - impostorVertices[VPROP_POS][22] = XMFLOAT4(0, 1, 1, 0); - impostorVertices[VPROP_NOR][22] = XMFLOAT4(1, 0, 0, 1); - impostorVertices[VPROP_TEX][22] = XMFLOAT4(stepX*3, 0, 0, 0); + impostorVertices_POS[22] = XMFLOAT4(0, 1, 1, 0); + impostorVertices_NOR[22] = XMFLOAT4(1, 0, 0, 1); + impostorVertices_TEX[22] = XMFLOAT4(stepX*3, 0, 0, 0); - impostorVertices[VPROP_POS][23] = XMFLOAT4(0, -1, 1, 0); - impostorVertices[VPROP_NOR][23] = XMFLOAT4(1, 0, 0, 1); - impostorVertices[VPROP_TEX][23] = XMFLOAT4(stepX*3, 1, 0, 0); + impostorVertices_POS[23] = XMFLOAT4(0, -1, 1, 0); + impostorVertices_NOR[23] = XMFLOAT4(1, 0, 0, 1); + impostorVertices_TEX[23] = XMFLOAT4(stepX*3, 1, 0, 0); // bottom - impostorVertices[VPROP_POS][24] = XMFLOAT4(-1, 0, 1, 0); - impostorVertices[VPROP_NOR][24] = XMFLOAT4(0, 1, 0, 1); - impostorVertices[VPROP_TEX][24] = XMFLOAT4(stepX*4, 0, 0, 0); + impostorVertices_POS[24] = XMFLOAT4(-1, 0, 1, 0); + impostorVertices_NOR[24] = XMFLOAT4(0, 1, 0, 1); + impostorVertices_TEX[24] = XMFLOAT4(stepX*4, 0, 0, 0); - impostorVertices[VPROP_POS][25] = XMFLOAT4(1, 0, 1, 0); - impostorVertices[VPROP_NOR][25] = XMFLOAT4(0, 1, 0, 1); - impostorVertices[VPROP_TEX][25] = XMFLOAT4(stepX * 5, 0, 0, 0); + impostorVertices_POS[25] = XMFLOAT4(1, 0, 1, 0); + impostorVertices_NOR[25] = XMFLOAT4(0, 1, 0, 1); + impostorVertices_TEX[25] = XMFLOAT4(stepX * 5, 0, 0, 0); - impostorVertices[VPROP_POS][26] = XMFLOAT4(-1, 0, -1, 0); - impostorVertices[VPROP_NOR][26] = XMFLOAT4(0, 1, 0, 1); - impostorVertices[VPROP_TEX][26] = XMFLOAT4(stepX*4, 1, 0, 0); + impostorVertices_POS[26] = XMFLOAT4(-1, 0, -1, 0); + impostorVertices_NOR[26] = XMFLOAT4(0, 1, 0, 1); + impostorVertices_TEX[26] = XMFLOAT4(stepX*4, 1, 0, 0); - impostorVertices[VPROP_POS][27] = XMFLOAT4(-1, 0, -1, 0); - impostorVertices[VPROP_NOR][27] = XMFLOAT4(0, 1, 0, 1); - impostorVertices[VPROP_TEX][27] = XMFLOAT4(stepX*4, 1, 0, 0); + impostorVertices_POS[27] = XMFLOAT4(-1, 0, -1, 0); + impostorVertices_NOR[27] = XMFLOAT4(0, 1, 0, 1); + impostorVertices_TEX[27] = XMFLOAT4(stepX*4, 1, 0, 0); - impostorVertices[VPROP_POS][28] = XMFLOAT4(1, 0, 1, 0); - impostorVertices[VPROP_NOR][28] = XMFLOAT4(0, 1, 0, 1); - impostorVertices[VPROP_TEX][28] = XMFLOAT4(stepX*5, 0, 0, 0); + impostorVertices_POS[28] = XMFLOAT4(1, 0, 1, 0); + impostorVertices_NOR[28] = XMFLOAT4(0, 1, 0, 1); + impostorVertices_TEX[28] = XMFLOAT4(stepX*5, 0, 0, 0); - impostorVertices[VPROP_POS][29] = XMFLOAT4(1, 0, -1, 0); - impostorVertices[VPROP_NOR][29] = XMFLOAT4(0, 1, 0, 1); - impostorVertices[VPROP_TEX][29] = XMFLOAT4(stepX*5, 1, 0, 0); + impostorVertices_POS[29] = XMFLOAT4(1, 0, -1, 0); + impostorVertices_NOR[29] = XMFLOAT4(0, 1, 0, 1); + impostorVertices_TEX[29] = XMFLOAT4(stepX*5, 1, 0, 0); // top - impostorVertices[VPROP_POS][30] = XMFLOAT4(-1, 0, 1, 0); - impostorVertices[VPROP_NOR][30] = XMFLOAT4(0, 1, 0, 1); - impostorVertices[VPROP_TEX][30] = XMFLOAT4(stepX*5, 0, 0, 0); + impostorVertices_POS[30] = XMFLOAT4(-1, 0, 1, 0); + impostorVertices_NOR[30] = XMFLOAT4(0, 1, 0, 1); + impostorVertices_TEX[30] = XMFLOAT4(stepX*5, 0, 0, 0); - impostorVertices[VPROP_POS][31] = XMFLOAT4(-1, 0, -1, 0); - impostorVertices[VPROP_NOR][31] = XMFLOAT4(0, 1, 0, 1); - impostorVertices[VPROP_TEX][31] = XMFLOAT4(stepX * 5, 1, 0, 0); + impostorVertices_POS[31] = XMFLOAT4(-1, 0, -1, 0); + impostorVertices_NOR[31] = XMFLOAT4(0, 1, 0, 1); + impostorVertices_TEX[31] = XMFLOAT4(stepX * 5, 1, 0, 0); - impostorVertices[VPROP_POS][32] = XMFLOAT4(1, 0, 1, 0); - impostorVertices[VPROP_NOR][32] = XMFLOAT4(0, 1, 0, 1); - impostorVertices[VPROP_TEX][32] = XMFLOAT4(stepX*6, 0, 0, 0); + impostorVertices_POS[32] = XMFLOAT4(1, 0, 1, 0); + impostorVertices_NOR[32] = XMFLOAT4(0, 1, 0, 1); + impostorVertices_TEX[32] = XMFLOAT4(stepX*6, 0, 0, 0); - impostorVertices[VPROP_POS][33] = XMFLOAT4(-1, 0, -1, 0); - impostorVertices[VPROP_NOR][33] = XMFLOAT4(0, 1, 0, 1); - impostorVertices[VPROP_TEX][33] = XMFLOAT4(stepX*5, 1, 0, 0); + impostorVertices_POS[33] = XMFLOAT4(-1, 0, -1, 0); + impostorVertices_NOR[33] = XMFLOAT4(0, 1, 0, 1); + impostorVertices_TEX[33] = XMFLOAT4(stepX*5, 1, 0, 0); - impostorVertices[VPROP_POS][34] = XMFLOAT4(1, 0, -1, 0); - impostorVertices[VPROP_NOR][34] = XMFLOAT4(0, 1, 0, 1); - impostorVertices[VPROP_TEX][34] = XMFLOAT4(stepX*6, 1, 0, 0); + impostorVertices_POS[34] = XMFLOAT4(1, 0, -1, 0); + impostorVertices_NOR[34] = XMFLOAT4(0, 1, 0, 1); + impostorVertices_TEX[34] = XMFLOAT4(stepX*6, 1, 0, 0); - impostorVertices[VPROP_POS][35] = XMFLOAT4(1, 0, 1, 0); - impostorVertices[VPROP_NOR][35] = XMFLOAT4(0, 1, 0, 1); - impostorVertices[VPROP_TEX][35] = XMFLOAT4(stepX*6, 0, 0, 0); + impostorVertices_POS[35] = XMFLOAT4(1, 0, 1, 0); + impostorVertices_NOR[35] = XMFLOAT4(0, 1, 0, 1); + impostorVertices_TEX[35] = XMFLOAT4(stepX*6, 0, 0, 0); GPUBufferDesc bd; ZeroMemory(&bd, sizeof(bd)); bd.Usage = USAGE_IMMUTABLE; - bd.ByteWidth = sizeof(impostorVertices[VPROP_POS]); bd.BindFlags = BIND_VERTEX_BUFFER; bd.CPUAccessFlags = 0; SubresourceData InitData; ZeroMemory(&InitData, sizeof(InitData)); - InitData.pSysMem = impostorVertices[VPROP_POS]; - wiRenderer::GetDevice()->CreateBuffer(&bd, &InitData, &impostorVBs[VPROP_POS]); - InitData.pSysMem = impostorVertices[VPROP_NOR]; - wiRenderer::GetDevice()->CreateBuffer(&bd, &InitData, &impostorVBs[VPROP_NOR]); - InitData.pSysMem = impostorVertices[VPROP_TEX]; - wiRenderer::GetDevice()->CreateBuffer(&bd, &InitData, &impostorVBs[VPROP_TEX]); + InitData.pSysMem = impostorVertices_POS; + bd.ByteWidth = sizeof(impostorVertices_POS); + wiRenderer::GetDevice()->CreateBuffer(&bd, &InitData, &impostorVB_POS); + InitData.pSysMem = impostorVertices_NOR; + bd.ByteWidth = sizeof(impostorVertices_NOR); + wiRenderer::GetDevice()->CreateBuffer(&bd, &InitData, &impostorVB_NOR); + InitData.pSysMem = impostorVertices_TEX; + bd.ByteWidth = sizeof(impostorVertices_TEX); + wiRenderer::GetDevice()->CreateBuffer(&bd, &InitData, &impostorVB_TEX); } } void Mesh::CreateVertexArrays() @@ -2277,14 +2309,15 @@ void Mesh::CreateVertexArrays() return; } - // Save original vertices. This will be input for CPU skinning / soft bodies - vertices_Transformed[VPROP_POS] = vertices[VPROP_POS]; - vertices_Transformed[VPROP_NOR] = vertices[VPROP_NOR]; - vertices_Transformed[VPROP_PRE] = vertices[VPROP_POS]; // pre <- pos!! - - // Normalize bone weights: - for (auto& wei : vertices[VPROP_WEI]) + // De-interleave vertex arrays: + vertices_POS.resize(vertices_FULL.size()); + vertices_NOR.resize(vertices_FULL.size()); + vertices_TEX.resize(vertices_FULL.size()); + vertices_BON.resize(vertices_FULL.size()); + for (size_t i = 0; i < vertices_FULL.size(); ++i) { + // Normalize bone weights: + XMFLOAT4& wei = vertices_FULL[i].wei; float len = wei.x + wei.y + wei.z + wei.w; if (len > 0) { @@ -2293,13 +2326,25 @@ void Mesh::CreateVertexArrays() wei.z /= len; wei.w /= len; } + + // Split and convert props: + vertices_POS[i].pos = vertices_FULL[i].pos; + vertices_NOR[i].nor = vertices_FULL[i].nor; + vertices_TEX[i].tex = vertices_FULL[i].tex; + vertices_BON[i].ind = vertices_FULL[i].ind; + vertices_BON[i].wei = vertices_FULL[i].wei; } + // Save original vertices. This will be input for CPU skinning / soft bodies + vertices_Transformed_POS = vertices_POS; + vertices_Transformed_NOR = vertices_NOR; + vertices_Transformed_PRE = vertices_POS; // pre <- pos!! + // Map subset indices: for (size_t i = 0; i < indices.size(); ++i) { unsigned int index = indices[i]; - const XMFLOAT4& tex = vertices[VPROP_TEX][index]; + const XMFLOAT4& tex = vertices_FULL[index].tex; unsigned int materialIndex = (unsigned int)floor(tex.z); assert((materialIndex < (unsigned int)subsets.size()) && "Bad subset index!"); @@ -2359,21 +2404,18 @@ void Mesh::Serialize(wiArchive& archive) { size_t vertexCount; archive >> vertexCount; - for (int vprop = 0; vprop < VPROP_COUNT; ++vprop) - { - vertices[vprop].resize(vertexCount); - } + vertices_FULL.resize(vertexCount); for (size_t i = 0; i < vertexCount; ++i) { - archive >> vertices[VPROP_POS][i]; - archive >> vertices[VPROP_NOR][i]; - archive >> vertices[VPROP_TEX][i]; - archive >> vertices[VPROP_BON][i]; - archive >> vertices[VPROP_WEI][i]; + archive >> vertices_FULL[i].pos; + archive >> vertices_FULL[i].nor; + archive >> vertices_FULL[i].tex; + archive >> vertices_FULL[i].ind; + archive >> vertices_FULL[i].wei; if (archive.GetVersion() < 8) { - vertices[VPROP_POS][i].w = vertices[VPROP_TEX][i].w; + vertices_FULL[i].pos.w = vertices_FULL[i].tex.w; } } } @@ -2485,14 +2527,14 @@ void Mesh::Serialize(wiArchive& archive) // vertices { - archive << vertices[VPROP_POS].size(); - for (size_t i = 0; i < vertices[VPROP_POS].size(); ++i) + archive << vertices_FULL.size(); + for (size_t i = 0; i < vertices_FULL.size(); ++i) { - archive << vertices[VPROP_POS][i]; - archive << vertices[VPROP_NOR][i]; - archive << vertices[VPROP_TEX][i]; - archive << vertices[VPROP_BON][i]; - archive << vertices[VPROP_WEI][i]; + archive << vertices_FULL[i].pos; + archive << vertices_FULL[i].nor; + archive << vertices_FULL[i].tex; + archive << vertices_FULL[i].ind; + archive << vertices_FULL[i].wei; } } // indices diff --git a/WickedEngine/wiLoader.h b/WickedEngine/wiLoader.h index 9db1cc842..f1cce2314 100644 --- a/WickedEngine/wiLoader.h +++ b/WickedEngine/wiLoader.h @@ -34,68 +34,68 @@ typedef std::map MaterialCollection; class wiArchive; -enum VERTEXPROPERTY -{ - VPROP_POS, // pos, wind - VPROP_NOR, // normal, vertexao - VPROP_TEX, // texcoord, materialindex, unused - VPROP_BON, // boneindices - VPROP_WEI, // boneweights - VPROP_COUNT, -}; -#define VPROP_PRE VPROP_BON // posprev -struct SkinnedVertex -{ - XMFLOAT4 pos; //pos, wind - XMFLOAT4 nor; //normal, vertex ao - XMFLOAT4 tex; //tex, matIndex, unused - XMFLOAT4 bon; //bone indices - XMFLOAT4 wei; //bone weights - - - SkinnedVertex(){ - pos=XMFLOAT4(0,0,0,0); - nor=XMFLOAT4(0,0,0,1); - tex=XMFLOAT4(0,0,0,0); - bon=XMFLOAT4(0,0,0,0); - wei=XMFLOAT4(0,0,0,0); - }; - SkinnedVertex(const XMFLOAT3& newPos){ - pos=XMFLOAT4(newPos.x,newPos.y,newPos.z,1); - nor=XMFLOAT4(0,0,0,1); - tex=XMFLOAT4(0,0,0,0); - bon=XMFLOAT4(0,0,0,0); - wei=XMFLOAT4(0,0,0,0); - } - //void Serialize(wiArchive& archive); -}; -struct Vertex -{ - XMFLOAT4 pos; //pos, wind - XMFLOAT4 nor; //normal, vertex ao - XMFLOAT4 tex; //tex, matIndex, unused - XMFLOAT4 pre; //previous frame position - - Vertex(){ - pos=XMFLOAT4(0,0,0,0); - nor=XMFLOAT4(0,0,0,1); - tex=XMFLOAT4(0,0,0,0); - pre=XMFLOAT4(0,0,0,0); - }; - Vertex(const XMFLOAT3& newPos){ - pos=XMFLOAT4(newPos.x,newPos.y,newPos.z,1); - nor=XMFLOAT4(0,0,0,1); - tex=XMFLOAT4(0,0,0,0); - pre=XMFLOAT4(0,0,0,0); - } - Vertex(const SkinnedVertex& copyFromSkinnedVert) - { - pos = copyFromSkinnedVert.pos; - nor = copyFromSkinnedVert.nor; - tex = copyFromSkinnedVert.tex; - pre = XMFLOAT4(0, 0, 0, 0); - } -}; +//enum VERTEXPROPERTY +//{ +// VPROP_POS, // pos, wind +// VPROP_NOR, // normal, vertexao +// VPROP_TEX, // texcoord, materialindex, unused +// VPROP_BON, // boneindices +// VPROP_WEI, // boneweights +// VPROP_COUNT, +//}; +//#define VPROP_PRE VPROP_BON // posprev +//struct SkinnedVertex +//{ +// XMFLOAT4 pos; //pos, wind +// XMFLOAT4 nor; //normal, vertex ao +// XMFLOAT4 tex; //tex, matIndex, unused +// XMFLOAT4 bon; //bone indices +// XMFLOAT4 wei; //bone weights +// +// +// SkinnedVertex(){ +// pos=XMFLOAT4(0,0,0,0); +// nor=XMFLOAT4(0,0,0,1); +// tex=XMFLOAT4(0,0,0,0); +// bon=XMFLOAT4(0,0,0,0); +// wei=XMFLOAT4(0,0,0,0); +// }; +// SkinnedVertex(const XMFLOAT3& newPos){ +// pos=XMFLOAT4(newPos.x,newPos.y,newPos.z,1); +// nor=XMFLOAT4(0,0,0,1); +// tex=XMFLOAT4(0,0,0,0); +// bon=XMFLOAT4(0,0,0,0); +// wei=XMFLOAT4(0,0,0,0); +// } +// //void Serialize(wiArchive& archive); +//}; +//struct Vertex +//{ +// XMFLOAT4 pos; //pos, wind +// XMFLOAT4 nor; //normal, vertex ao +// XMFLOAT4 tex; //tex, matIndex, unused +// XMFLOAT4 pre; //previous frame position +// +// Vertex(){ +// pos=XMFLOAT4(0,0,0,0); +// nor=XMFLOAT4(0,0,0,1); +// tex=XMFLOAT4(0,0,0,0); +// pre=XMFLOAT4(0,0,0,0); +// }; +// Vertex(const XMFLOAT3& newPos){ +// pos=XMFLOAT4(newPos.x,newPos.y,newPos.z,1); +// nor=XMFLOAT4(0,0,0,1); +// tex=XMFLOAT4(0,0,0,0); +// pre=XMFLOAT4(0,0,0,0); +// } +// Vertex(const SkinnedVertex& copyFromSkinnedVert) +// { +// pos = copyFromSkinnedVert.pos; +// nor = copyFromSkinnedVert.nor; +// tex = copyFromSkinnedVert.tex; +// pre = XMFLOAT4(0, 0, 0, 0); +// } +//}; GFX_STRUCT Instance { XMFLOAT4A mat0; @@ -324,10 +324,59 @@ struct MeshSubset struct Mesh { public: + struct Vertex_FULL + { + XMFLOAT4 pos; //pos, wind + XMFLOAT4 nor; //normal, vertex ao + XMFLOAT4 tex; //tex, matIndex, unused + XMFLOAT4 ind; //bone indices + XMFLOAT4 wei; //bone weights + + Vertex_FULL(){ + pos=XMFLOAT4(0,0,0,0); + nor=XMFLOAT4(0,0,0,1); + tex=XMFLOAT4(0,0,0,0); + ind=XMFLOAT4(0,0,0,0); + wei=XMFLOAT4(0,0,0,0); + }; + Vertex_FULL(const XMFLOAT3& newPos){ + pos=XMFLOAT4(newPos.x,newPos.y,newPos.z,1); + nor=XMFLOAT4(0,0,0,1); + tex=XMFLOAT4(0,0,0,0); + ind=XMFLOAT4(0,0,0,0); + wei=XMFLOAT4(0,0,0,0); + } + }; + struct Vertex_POS + { + XMFLOAT4 pos; + }; + struct Vertex_NOR + { + XMFLOAT4 nor; + }; + struct Vertex_TEX + { + XMFLOAT4 tex; + }; + struct Vertex_BON + { + XMFLOAT4 ind; + XMFLOAT4 wei; + }; + std::string name; std::string parent; - std::vector vertices_Transformed[VPROP_COUNT]; // for CPU skinning / soft body simulation - std::vector vertices[VPROP_COUNT]; + //std::vector vertices_Transformed[VPROP_COUNT]; // for CPU skinning / soft body simulation + //std::vector vertices[VPROP_COUNT]; + std::vector vertices_FULL; + std::vector vertices_POS; // position(xyz), wind(w) + std::vector vertices_NOR; // normal + std::vector vertices_TEX; // texcoords + std::vector vertices_BON; // bone indices, bone weights + std::vector vertices_Transformed_POS; // for soft body simulation + std::vector vertices_Transformed_NOR; // for soft body simulation + std::vector vertices_Transformed_PRE; // for soft body simulation std::vector indices; std::vector physicsverts; std::vector physicsindices; @@ -335,8 +384,15 @@ public: std::vector subsets; std::vector materialNames; - wiGraphicsTypes::GPUBuffer vertexBuffers[VPROP_COUNT]; - wiGraphicsTypes::GPUBuffer streamoutBuffers[VPROP_COUNT]; // omit texcoord, omit weights, change boneindices to posprev + //wiGraphicsTypes::GPUBuffer vertexBuffers[VPROP_COUNT]; + //wiGraphicsTypes::GPUBuffer streamoutBuffers[VPROP_COUNT]; // omit texcoord, omit weights, change boneindices to posprev + wiGraphicsTypes::GPUBuffer vertexBuffer_POS; + wiGraphicsTypes::GPUBuffer vertexBuffer_NOR; + wiGraphicsTypes::GPUBuffer vertexBuffer_TEX; + wiGraphicsTypes::GPUBuffer vertexBuffer_BON; + wiGraphicsTypes::GPUBuffer streamoutBuffer_POS; + wiGraphicsTypes::GPUBuffer streamoutBuffer_NOR; + wiGraphicsTypes::GPUBuffer streamoutBuffer_PRE; wiGraphicsTypes::GPUBuffer instanceBuffer; wiGraphicsTypes::GPUBuffer instanceBufferPrev; @@ -363,7 +419,10 @@ public: wiRenderTarget impostorTarget; float impostorDistance; - static wiGraphicsTypes::GPUBuffer impostorVBs[VPROP_COUNT]; // omit weights, omit posprev + //static wiGraphicsTypes::GPUBuffer impostorVBs[VPROP_COUNT]; // omit weights, omit posprev + static wiGraphicsTypes::GPUBuffer impostorVB_POS; + static wiGraphicsTypes::GPUBuffer impostorVB_NOR; + static wiGraphicsTypes::GPUBuffer impostorVB_TEX; float tessellationFactor; diff --git a/WickedEngine/wiRenderer.cpp b/WickedEngine/wiRenderer.cpp index a3aba0329..dc462c35b 100644 --- a/WickedEngine/wiRenderer.cpp +++ b/WickedEngine/wiRenderer.cpp @@ -1480,24 +1480,24 @@ Light* wiRenderer::getLightByName(const std::string& name) return nullptr; } -Vertex wiRenderer::TransformVertex(const Mesh* mesh, int vertexI, const XMMATRIX& mat) +Mesh::Vertex_FULL wiRenderer::TransformVertex(const Mesh* mesh, int vertexI, const XMMATRIX& mat) { XMMATRIX sump; - XMVECTOR pos = XMLoadFloat4(&mesh->vertices[VPROP_POS][vertexI]); - XMVECTOR nor = XMLoadFloat4(&mesh->vertices[VPROP_NOR][vertexI]); + XMVECTOR pos = XMLoadFloat4(&mesh->vertices_POS[vertexI].pos); + XMVECTOR nor = XMLoadFloat4(&mesh->vertices_NOR[vertexI].nor); if (mesh->hasArmature() && !mesh->armature->boneCollection.empty()) { float inWei[4] = { - mesh->vertices[VPROP_WEI][vertexI].x - , mesh->vertices[VPROP_WEI][vertexI].y - , mesh->vertices[VPROP_WEI][vertexI].z - , mesh->vertices[VPROP_WEI][vertexI].w }; + mesh->vertices_BON[vertexI].wei.x, + mesh->vertices_BON[vertexI].wei.y, + mesh->vertices_BON[vertexI].wei.z, + mesh->vertices_BON[vertexI].wei.w }; float inBon[4] = { - mesh->vertices[VPROP_BON][vertexI].x - , mesh->vertices[VPROP_BON][vertexI].y - , mesh->vertices[VPROP_BON][vertexI].z - , mesh->vertices[VPROP_BON][vertexI].w }; + mesh->vertices_BON[vertexI].ind.x, + mesh->vertices_BON[vertexI].ind.y, + mesh->vertices_BON[vertexI].ind.z, + mesh->vertices_BON[vertexI].ind.w }; if (inWei[0] || inWei[1] || inWei[2] || inWei[3]) { sump = XMMATRIX(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); @@ -1522,10 +1522,9 @@ Vertex wiRenderer::TransformVertex(const Mesh* mesh, int vertexI, const XMMATRIX XMStoreFloat3(&transformedN, XMVector3Normalize(XMVector3TransformNormal(nor, sump))); - Vertex retV(transformedP); + Mesh::Vertex_FULL retV(transformedP); retV.nor = XMFLOAT4(transformedN.x, transformedN.y, transformedN.z, retV.nor.w); - retV.tex = mesh->vertices[VPROP_TEX][vertexI]; - retV.pre = XMFLOAT4(0, 0, 0, 1); + retV.tex = mesh->vertices_TEX[vertexI].tex; return retV; } @@ -1787,8 +1786,8 @@ void wiRenderer::UpdateRenderData(GRAPHICSTHREAD threadID) { Mesh* mesh = iter->second; - if (mesh->hasArmature() && !mesh->softBody && mesh->renderable && !mesh->vertices[VPROP_POS].empty() - && mesh->streamoutBuffers[VPROP_POS].IsValid() && mesh->vertexBuffers[VPROP_POS].IsValid()) + if (mesh->hasArmature() && !mesh->softBody && mesh->renderable && !mesh->vertices_POS.empty() + && mesh->streamoutBuffer_POS.IsValid() && mesh->vertexBuffer_POS.IsValid()) { Armature* armature = mesh->armature; @@ -1818,30 +1817,29 @@ void wiRenderer::UpdateRenderData(GRAPHICSTHREAD threadID) // Do the skinning const GPUResource* vbs[] = { - static_cast(&mesh->vertexBuffers[VPROP_POS]), - static_cast(&mesh->vertexBuffers[VPROP_NOR]), - static_cast(&mesh->vertexBuffers[VPROP_WEI]), - static_cast(&mesh->vertexBuffers[VPROP_BON]), + static_cast(&mesh->vertexBuffer_POS), + static_cast(&mesh->vertexBuffer_NOR), + static_cast(&mesh->vertexBuffer_BON), }; const GPUUnorderedResource* sos[] = { - static_cast(&mesh->streamoutBuffers[VPROP_POS]), - static_cast(&mesh->streamoutBuffers[VPROP_NOR]), - static_cast(&mesh->streamoutBuffers[VPROP_PRE]), + static_cast(&mesh->streamoutBuffer_POS), + static_cast(&mesh->streamoutBuffer_NOR), + static_cast(&mesh->streamoutBuffer_PRE), }; GetDevice()->BindResourcesCS(vbs, SKINNINGSLOT_IN_VERTEX_POS, ARRAYSIZE(vbs), threadID); GetDevice()->BindUnorderedAccessResourcesCS(sos, 0, ARRAYSIZE(sos), threadID); - GetDevice()->Dispatch((UINT)ceilf((float)mesh->vertices[VPROP_POS].size() / SKINNING_COMPUTE_THREADCOUNT), 1, 1, threadID); + GetDevice()->Dispatch((UINT)ceilf((float)mesh->vertices_POS.size() / SKINNING_COMPUTE_THREADCOUNT), 1, 1, threadID); } // Upload CPU skinned vertex buffer (Soft body VB) if (mesh->softBody) { - GetDevice()->UpdateBuffer(&mesh->vertexBuffers[VPROP_POS], mesh->vertices_Transformed[VPROP_POS].data(), threadID, (int)(sizeof(XMFLOAT4)*mesh->vertices_Transformed[VPROP_POS].size())); - GetDevice()->UpdateBuffer(&mesh->vertexBuffers[VPROP_NOR], mesh->vertices_Transformed[VPROP_NOR].data(), threadID, (int)(sizeof(XMFLOAT4)*mesh->vertices_Transformed[VPROP_NOR].size())); - GetDevice()->UpdateBuffer(&mesh->vertexBuffers[VPROP_PRE], mesh->vertices_Transformed[VPROP_PRE].data(), threadID, (int)(sizeof(XMFLOAT4)*mesh->vertices_Transformed[VPROP_PRE].size())); + GetDevice()->UpdateBuffer(&mesh->vertexBuffer_POS, mesh->vertices_Transformed_POS.data(), threadID, (int)(sizeof(XMFLOAT4)*mesh->vertices_Transformed_POS.size())); + GetDevice()->UpdateBuffer(&mesh->vertexBuffer_NOR, mesh->vertices_Transformed_NOR.data(), threadID, (int)(sizeof(XMFLOAT4)*mesh->vertices_Transformed_NOR.size())); + GetDevice()->UpdateBuffer(&mesh->streamoutBuffer_PRE, mesh->vertices_Transformed_PRE.data(), threadID, (int)(sizeof(XMFLOAT4)*mesh->vertices_Transformed_PRE.size())); } } } @@ -2653,7 +2651,7 @@ void wiRenderer::DrawDebugEmitters(Camera* camera, GRAPHICSTHREAD threadID) for (auto& y : x->object->mesh->subsets) { const GPUBuffer* vbs[] = { - &x->object->mesh->vertexBuffers[VPROP_POS], + &x->object->mesh->vertexBuffer_POS, }; const UINT strides[] = { sizeof(XMFLOAT4), @@ -3968,8 +3966,8 @@ void wiRenderer::RenderMeshes(const XMFLOAT3& eye, const CulledCollection& culle if (realVL == VLTYPE_OBJECT_POS_TEX) { GPUBuffer* vbs[] = { - &Mesh::impostorVBs[VPROP_POS], - &Mesh::impostorVBs[VPROP_TEX], + &Mesh::impostorVB_POS, + &Mesh::impostorVB_TEX, &mesh->instanceBuffer }; UINT strides[] = { @@ -3982,10 +3980,10 @@ void wiRenderer::RenderMeshes(const XMFLOAT3& eye, const CulledCollection& culle else { GPUBuffer* vbs[] = { - &Mesh::impostorVBs[VPROP_POS], - &Mesh::impostorVBs[VPROP_NOR], - &Mesh::impostorVBs[VPROP_TEX], - &Mesh::impostorVBs[VPROP_POS], + &Mesh::impostorVB_POS, + &Mesh::impostorVB_NOR, + &Mesh::impostorVB_TEX, + &Mesh::impostorVB_POS, &mesh->instanceBuffer, &mesh->instanceBufferPrev, }; @@ -4209,7 +4207,7 @@ void wiRenderer::RenderMeshes(const XMFLOAT3& eye, const CulledCollection& culle case BOUNDVERTEXBUFFERTYPE::POSITION: { GPUBuffer* vbs[] = { - (mesh->streamoutBuffers[VPROP_POS].IsValid() ? &mesh->streamoutBuffers[VPROP_POS] : &mesh->vertexBuffers[VPROP_POS]), + (mesh->streamoutBuffer_POS.IsValid() ? &mesh->streamoutBuffer_POS : &mesh->vertexBuffer_POS), &mesh->instanceBuffer }; UINT strides[] = { @@ -4222,8 +4220,8 @@ void wiRenderer::RenderMeshes(const XMFLOAT3& eye, const CulledCollection& culle case BOUNDVERTEXBUFFERTYPE::POSITION_TEXCOORD: { GPUBuffer* vbs[] = { - (mesh->streamoutBuffers[VPROP_POS].IsValid() ? &mesh->streamoutBuffers[VPROP_POS] : &mesh->vertexBuffers[VPROP_POS]), - &mesh->vertexBuffers[VPROP_TEX], + (mesh->streamoutBuffer_POS.IsValid() ? &mesh->streamoutBuffer_POS : &mesh->vertexBuffer_POS), + &mesh->vertexBuffer_TEX, &mesh->instanceBuffer }; UINT strides[] = { @@ -4237,10 +4235,10 @@ void wiRenderer::RenderMeshes(const XMFLOAT3& eye, const CulledCollection& culle case BOUNDVERTEXBUFFERTYPE::EVERYTHING: { GPUBuffer* vbs[] = { - (mesh->streamoutBuffers[VPROP_POS].IsValid() ? &mesh->streamoutBuffers[VPROP_POS] : &mesh->vertexBuffers[VPROP_POS]), - (mesh->streamoutBuffers[VPROP_NOR].IsValid() ? &mesh->streamoutBuffers[VPROP_NOR] : &mesh->vertexBuffers[VPROP_NOR]), - &mesh->vertexBuffers[VPROP_TEX], - (mesh->streamoutBuffers[VPROP_PRE].IsValid() ? &mesh->streamoutBuffers[VPROP_PRE] : &mesh->vertexBuffers[mesh->softBody ? VPROP_PRE : VPROP_POS]), // this is getting out of hand! + (mesh->streamoutBuffer_POS.IsValid() ? &mesh->streamoutBuffer_POS : &mesh->vertexBuffer_POS), + (mesh->streamoutBuffer_NOR.IsValid() ? &mesh->streamoutBuffer_NOR : &mesh->vertexBuffer_NOR), + &mesh->vertexBuffer_TEX, + (mesh->streamoutBuffer_PRE.IsValid() ? &mesh->streamoutBuffer_PRE : &mesh->vertexBuffer_POS), &mesh->instanceBuffer, &mesh->instanceBufferPrev, }; @@ -5703,11 +5701,11 @@ void wiRenderer::RayIntersectMeshes(const RAY& ray, const CulledList& culledObje } Mesh* mesh = object->mesh; - if (mesh->vertices[VPROP_POS].size() >= _arraySize) + if (mesh->vertices_POS.size() >= _arraySize) { // grow preallocated vector helper array _mm_free(_vertices); - _arraySize = (mesh->vertices[VPROP_POS].size() + 1) * 2; + _arraySize = (mesh->vertices_POS.size() + 1) * 2; _vertices = (XMVECTOR*)_mm_malloc(sizeof(XMVECTOR)*_arraySize, 16); } @@ -5717,8 +5715,8 @@ void wiRenderer::RayIntersectMeshes(const RAY& ray, const CulledList& culledObje XMVECTOR& rayOrigin_local = XMVector3Transform(rayOrigin, objectMat_Inverse); XMVECTOR& rayDirection_local = XMVector3Normalize(XMVector3TransformNormal(rayDirection, objectMat_Inverse)); - Vertex _tmpvert; - for (size_t i = 0; i < mesh->vertices[VPROP_POS].size(); ++i) + Mesh::Vertex_FULL _tmpvert; + for (size_t i = 0; i < mesh->vertices_POS.size(); ++i) { if (object->isArmatureDeformed() && !object->mesh->armature->boneCollection.empty()) { @@ -5727,7 +5725,7 @@ void wiRenderer::RayIntersectMeshes(const RAY& ray, const CulledList& culledObje } else { - _vertices[i] = XMLoadFloat4(&mesh->vertices[VPROP_POS][i]); + _vertices[i] = XMLoadFloat4(&mesh->vertices_POS[i].pos); } } @@ -5748,7 +5746,7 @@ void wiRenderer::RayIntersectMeshes(const RAY& ray, const CulledList& culledObje XMStoreFloat3(&picked.position, pos); XMStoreFloat3(&picked.normal, nor); picked.distance = wiMath::Distance(pos, rayOrigin); - picked.subsetIndex = (int)mesh->vertices[VPROP_TEX][i0].z; + picked.subsetIndex = (int)mesh->vertices_TEX[i0].tex.z; points.push_back(picked); } } @@ -5919,7 +5917,7 @@ void wiRenderer::SynchronizeWithPhysicsEngine(float dt) for (std::map::iterator it = mesh->vertexGroups[gvg].vertices.begin(); it != mesh->vertexGroups[gvg].vertices.end(); ++it) { int vi = (*it).first; - Vertex tvert = TransformVertex(mesh, vi, worldMat); + Mesh::Vertex_FULL tvert = TransformVertex(mesh, vi, worldMat); mesh->goalPositions[j] = XMFLOAT3(tvert.pos.x, tvert.pos.y, tvert.pos.z); mesh->goalNormals[j] = XMFLOAT3(tvert.nor.x, tvert.nor.y, tvert.nor.z); ++j; @@ -6001,10 +5999,10 @@ void wiRenderer::CreateImpostor(Mesh* mesh) mesh->UpdateRenderableInstances(1, threadID); GPUBuffer* vbs[] = { - (mesh->streamoutBuffers[VPROP_POS].IsValid() ? &mesh->streamoutBuffers[VPROP_POS] : &mesh->vertexBuffers[VPROP_POS]), - (mesh->streamoutBuffers[VPROP_NOR].IsValid() ? &mesh->streamoutBuffers[VPROP_NOR] : &mesh->vertexBuffers[VPROP_NOR]), - &mesh->vertexBuffers[VPROP_TEX], - (mesh->streamoutBuffers[VPROP_PRE].IsValid() ? &mesh->streamoutBuffers[VPROP_PRE] : &mesh->vertexBuffers[VPROP_POS]), + (mesh->streamoutBuffer_POS.IsValid() ? &mesh->streamoutBuffer_POS : &mesh->vertexBuffer_POS), + (mesh->streamoutBuffer_NOR.IsValid() ? &mesh->streamoutBuffer_NOR : &mesh->vertexBuffer_NOR), + &mesh->vertexBuffer_TEX, + (mesh->streamoutBuffer_PRE.IsValid() ? &mesh->streamoutBuffer_PRE : &mesh->vertexBuffer_POS), &mesh->instanceBuffer }; UINT strides[] = { diff --git a/WickedEngine/wiRenderer.h b/WickedEngine/wiRenderer.h index cf9c98dfa..8fb89af04 100644 --- a/WickedEngine/wiRenderer.h +++ b/WickedEngine/wiRenderer.h @@ -401,7 +401,7 @@ public: static void ReloadShaders(const std::string& path = ""); static void BindPersistentState(GRAPHICSTHREAD threadID); - static Vertex TransformVertex(const Mesh* mesh, int vertexI, const XMMATRIX& mat = XMMatrixIdentity()); + static Mesh::Vertex_FULL TransformVertex(const Mesh* mesh, int vertexI, const XMMATRIX& mat = XMMatrixIdentity()); struct FrameCulling { diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index 12de3964a..e6741baa9 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -9,7 +9,7 @@ namespace wiVersion // minor features, major updates const int minor = 13; // minor bug fixes, alterations, refactors, updates - const int revision = 5; + const int revision = 6; long GetVersion()