added more precision to bone vertex buffer, removed 16-bit positions

This commit is contained in:
turanszkij
2017-09-12 19:37:35 +02:00
parent 5231552e34
commit 0176cdb3af
5 changed files with 34 additions and 86 deletions
-3
View File
@@ -1,9 +1,6 @@
#ifndef _WICKEDENGINE_SHADERINTEROP_H_
#define _WICKEDENGINE_SHADERINTEROP_H_
//#define VERTEXBUFFER_HALFPOSITION
// Tiled rendering params:
#define BLOCK_SIZE 16
#define MAX_LIGHTS 1024
+12 -41
View File
@@ -48,33 +48,18 @@ 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)
{
#ifdef VERTEXBUFFER_HALFPOSITION
const uint stride_POS = 8;
#else
const uint stride_POS = 16;
#endif // VERTEXBUFFER_HALFPOSITION
const uint stride_NOR = 4;
const uint stride_BON_IND = 4;
const uint stride_BON_WEI = 4;
const uint stride_BON_IND = 8;
const uint stride_BON_WEI = 8;
const uint fetchAddress_POS = DTid.x * stride_POS;
const uint fetchAddress_NOR = DTid.x * stride_NOR;
const uint fetchAddress_BON = DTid.x * (stride_BON_IND + stride_BON_WEI);
// Manual type-conversion for pos:
#ifdef VERTEXBUFFER_HALFPOSITION
uint2 pos_u = vertexBuffer_POS.Load2(fetchAddress_POS);
float4 pos = 0;
{
pos.x = f16tof32((pos_u.x & 0x0000FFFF) >> 0);
pos.y = f16tof32((pos_u.x & 0xFFFF0000) >> 16);
pos.z = f16tof32((pos_u.y & 0x0000FFFF) >> 0);
pos.w = f16tof32((pos_u.y & 0xFFFF0000) >> 16);
}
#else
uint4 pos_u = vertexBuffer_POS.Load4(fetchAddress_POS);
float4 pos = asfloat(pos_u);
#endif // VERTEXBUFFER_HALFPOSITION
// Manual type-conversion for normal:
@@ -89,19 +74,19 @@ void main(uint3 DTid : SV_DispatchThreadID)
// Manual type-conversion for bone props:
uint2 ind_wei_u = vertexBuffer_BON.Load2(fetchAddress_BON);
uint4 ind_wei_u = vertexBuffer_BON.Load4(fetchAddress_BON);
float4 ind = 0;
float4 wei = 0;
{
ind.x = (float)((ind_wei_u.x >> 0) & 0x000000FF);
ind.y = (float)((ind_wei_u.x >> 8) & 0x000000FF);
ind.z = (float)((ind_wei_u.x >> 16) & 0x000000FF);
ind.w = (float)((ind_wei_u.x >> 24) & 0x000000FF);
ind.x = (float)((ind_wei_u.x >> 0) & 0x0000FFFF);
ind.y = (float)((ind_wei_u.x >> 16) & 0x0000FFFF);
ind.z = (float)((ind_wei_u.y >> 0) & 0x0000FFFF);
ind.w = (float)((ind_wei_u.y >> 16) & 0x0000FFFF);
wei.x = (float)((ind_wei_u.y >> 0) & 0x000000FF) / 255.0f;
wei.y = (float)((ind_wei_u.y >> 8) & 0x000000FF) / 255.0f;
wei.z = (float)((ind_wei_u.y >> 16) & 0x000000FF) / 255.0f;
wei.w = (float)((ind_wei_u.y >> 24) & 0x000000FF) / 255.0f;
wei.x = (float)((ind_wei_u.z >> 0) & 0x0000FFFF) / 65535.0f;
wei.y = (float)((ind_wei_u.z >> 16) & 0x0000FFFF) / 65535.0f;
wei.z = (float)((ind_wei_u.w >> 0) & 0x0000FFFF) / 65535.0f;
wei.w = (float)((ind_wei_u.w >> 16) & 0x0000FFFF) / 65535.0f;
}
@@ -111,17 +96,7 @@ void main(uint3 DTid : SV_DispatchThreadID)
// Manual type-conversion for pos:
#ifdef VERTEXBUFFER_HALFPOSITION
pos_u = 0;
{
pos_u.x |= f32tof16(pos.x) << 0;
pos_u.x |= f32tof16(pos.y) << 16;
pos_u.y |= f32tof16(pos.z) << 0;
pos_u.y |= f32tof16(pos.w) << 16;
}
#else
pos_u = asuint(pos);
#endif // VERTEXBUFFER_HALFPOSITION
// Manual type-conversion for normal:
@@ -133,12 +108,8 @@ void main(uint3 DTid : SV_DispatchThreadID)
nor_u |= (uint)(nor.w * 255.0f) << 24; // occlusion
}
#ifdef VERTEXBUFFER_HALFPOSITION
streamoutBuffer_PRE.Store2(fetchAddress_POS, streamoutBuffer_POS.Load2(fetchAddress_POS)); // copy prev frame current pos to current frame prev pos
streamoutBuffer_POS.Store2(fetchAddress_POS, pos_u);
#else
// Store data:
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);
#endif // VERTEXBUFFER_HALFPOSITION
streamoutBuffer_NOR.Store(fetchAddress_NOR, nor_u);
}
+3 -3
View File
@@ -55,11 +55,11 @@ runProcess(function()
if(input.Press(VK_F7)) then
-- LoadModel("C:\\PROJECTS\\WickedEngine\\WickedEngine\\Scene\\Sponza\\","sponza");
runProcess(function()
local row = 6
local row = 16
for i = 1, row do
for j = 1, row do
--LoadModel("C:\\PROJECTS\\BLENDER\\Stormtrooper\\", "Stormtrooper", "_"..i..j,matrix.Translation(Vector(i*2-row,0,j*2-row)));
LoadModel("C:\\PROJECTS\\WickedEngine\\WickedEngine\\models\\Sample\\", "nosun", "_common",matrix.Translation(Vector(i*500-row*500,0,j*500-row*500)));
LoadModel("C:\\PROJECTS\\BLENDER\\Stormtrooper\\", "Stormtrooper", "_"..i..j,matrix.Translation(Vector(i*2-row,0,j*2-row)));
--LoadModel("C:\\PROJECTS\\WickedEngine\\WickedEngine\\models\\Sample\\", "nosun", "_common",matrix.Translation(Vector(i*500-row*500,0,j*500-row*500)));
--waitSeconds(0.05)
end
end
+18 -38
View File
@@ -286,24 +286,6 @@ public:
};
struct Vertex_POS
{
#ifdef VERTEXBUFFER_HALFPOSITION
XMHALF4 pos;
Vertex_POS() :pos(XMHALF4(0.0f, 0.0f, 0.0f, 0.0f)) {}
Vertex_POS(const Vertex_FULL& vert)
{
pos = XMHALF4(vert.pos.x, vert.pos.y, vert.pos.z, vert.pos.w);
}
inline XMVECTOR Load() const
{
return XMLoadHalf4(&pos);
}
static const wiGraphicsTypes::FORMAT FORMAT = wiGraphicsTypes::FORMAT::FORMAT_R16G16B16A16_FLOAT;
#else
XMFLOAT4 pos;
Vertex_POS() :pos(XMFLOAT4(0.0f, 0.0f, 0.0f, 0.0f)) {}
@@ -317,8 +299,6 @@ public:
}
static const wiGraphicsTypes::FORMAT FORMAT = wiGraphicsTypes::FORMAT::FORMAT_R32G32B32A32_FLOAT;
#endif // VERTEXBUFFER_HALFPOSITION
};
struct Vertex_NOR
{
@@ -373,8 +353,8 @@ public:
};
struct Vertex_BON
{
uint32_t ind;
uint32_t wei;
uint64_t ind;
uint64_t wei;
Vertex_BON()
{
@@ -386,24 +366,24 @@ public:
ind = 0;
wei = 0;
ind |= (uint8_t)vert.ind.x << 0;
ind |= (uint8_t)vert.ind.y << 8;
ind |= (uint8_t)vert.ind.z << 16;
ind |= (uint8_t)vert.ind.w << 24;
ind |= (uint64_t)vert.ind.x << 0;
ind |= (uint64_t)vert.ind.y << 16;
ind |= (uint64_t)vert.ind.z << 32;
ind |= (uint64_t)vert.ind.w << 48;
wei |= (uint8_t)(vert.wei.x * 255.0f) << 0;
wei |= (uint8_t)(vert.wei.y * 255.0f) << 8;
wei |= (uint8_t)(vert.wei.z * 255.0f) << 16;
wei |= (uint8_t)(vert.wei.w * 255.0f) << 24;
wei |= (uint64_t)(vert.wei.x * 65535.0f) << 0;
wei |= (uint64_t)(vert.wei.y * 65535.0f) << 16;
wei |= (uint64_t)(vert.wei.z * 65535.0f) << 32;
wei |= (uint64_t)(vert.wei.w * 65535.0f) << 48;
}
inline XMFLOAT4 GetInd_FULL() const
{
XMFLOAT4 ind_FULL(0, 0, 0, 0);
ind_FULL.x = (float)((ind >> 0) & 0x000000FF);
ind_FULL.y = (float)((ind >> 8) & 0x000000FF);
ind_FULL.z = (float)((ind >> 16) & 0x000000FF);
ind_FULL.w = (float)((ind >> 24) & 0x000000FF);
ind_FULL.x = (float)((ind >> 0) & 0x0000FFFF);
ind_FULL.y = (float)((ind >> 16) & 0x0000FFFF);
ind_FULL.z = (float)((ind >> 32) & 0x0000FFFF);
ind_FULL.w = (float)((ind >> 48) & 0x0000FFFF);
return ind_FULL;
}
@@ -411,10 +391,10 @@ public:
{
XMFLOAT4 wei_FULL(0, 0, 0, 0);
wei_FULL.x = (float)((wei >> 0) & 0x000000FF) / 255.0f;
wei_FULL.y = (float)((wei >> 8) & 0x000000FF) / 255.0f;
wei_FULL.z = (float)((wei >> 16) & 0x000000FF) / 255.0f;
wei_FULL.w = (float)((wei >> 24) & 0x000000FF) / 255.0f;
wei_FULL.x = (float)((wei >> 0) & 0x0000FFFF) / 65535.0f;
wei_FULL.y = (float)((wei >> 16) & 0x0000FFFF) / 65535.0f;
wei_FULL.z = (float)((wei >> 32) & 0x0000FFFF) / 65535.0f;
wei_FULL.w = (float)((wei >> 48) & 0x0000FFFF) / 65535.0f;
return wei_FULL;
}
+1 -1
View File
@@ -9,7 +9,7 @@ namespace wiVersion
// minor features, major updates
const int minor = 13;
// minor bug fixes, alterations, refactors, updates
const int revision = 12;
const int revision = 13;
long GetVersion()