optimized vertex streams part1

This commit is contained in:
turanszkij
2017-05-21 23:42:29 +02:00
parent be6747adfc
commit 41fc925e78
31 changed files with 366 additions and 136 deletions
+1
View File
@@ -1,5 +1,6 @@
This file contains changelog of wiArchive versions
8: refactored vertex wind weight
7: serialized extended mesh properties
6: serialized area light properties
5: serialized color and emissive decal properties
+17 -1
View File
@@ -71,12 +71,22 @@
<FxCompile Include="cubeShadowGS.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Geometry</ShaderType>
</FxCompile>
<FxCompile Include="cubeShadowGS_alphatest.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Geometry</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">4.0</ShaderModel>
</FxCompile>
<FxCompile Include="cubeShadowPS.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Pixel</ShaderType>
</FxCompile>
<FxCompile Include="cubeShadowPS_alphatest.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Pixel</ShaderType>
</FxCompile>
<FxCompile Include="cubeShadowVS.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Vertex</ShaderType>
</FxCompile>
<FxCompile Include="cubeShadowVS_alphatest.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Vertex</ShaderType>
</FxCompile>
<FxCompile Include="cubeVS.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Vertex</ShaderType>
</FxCompile>
@@ -351,6 +361,9 @@
<FxCompile Include="objectVS_debug.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Vertex</ShaderType>
</FxCompile>
<FxCompile Include="objectVS_positionstream.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Vertex</ShaderType>
</FxCompile>
<FxCompile Include="objectVS_simple.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Vertex</ShaderType>
</FxCompile>
@@ -413,12 +426,15 @@
<FxCompile Include="screenVS.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Vertex</ShaderType>
</FxCompile>
<FxCompile Include="shadowPS.hlsl">
<FxCompile Include="shadowPS_alphatest.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Pixel</ShaderType>
</FxCompile>
<FxCompile Include="shadowVS.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Vertex</ShaderType>
</FxCompile>
<FxCompile Include="shadowVS_alphatest.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Vertex</ShaderType>
</FxCompile>
<FxCompile Include="sharpenPS.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Pixel</ShaderType>
</FxCompile>
@@ -231,9 +231,6 @@
<FxCompile Include="screenPS.hlsl">
<Filter>PS</Filter>
</FxCompile>
<FxCompile Include="shadowPS.hlsl">
<Filter>PS</Filter>
</FxCompile>
<FxCompile Include="skyPS.hlsl">
<Filter>PS</Filter>
</FxCompile>
@@ -588,6 +585,24 @@
<FxCompile Include="objectPS_debug.hlsl">
<Filter>PS</Filter>
</FxCompile>
<FxCompile Include="cubeShadowVS_alphatest.hlsl">
<Filter>VS</Filter>
</FxCompile>
<FxCompile Include="shadowVS_alphatest.hlsl">
<Filter>VS</Filter>
</FxCompile>
<FxCompile Include="cubeShadowGS_alphatest.hlsl">
<Filter>GS</Filter>
</FxCompile>
<FxCompile Include="shadowPS_alphatest.hlsl">
<Filter>PS</Filter>
</FxCompile>
<FxCompile Include="cubeShadowPS_alphatest.hlsl">
<Filter>PS</Filter>
</FxCompile>
<FxCompile Include="objectVS_positionstream.hlsl">
<Filter>VS</Filter>
</FxCompile>
</ItemGroup>
<ItemGroup>
<Filter Include="PS">
+1 -4
View File
@@ -2,14 +2,12 @@
struct GS_CUBEMAP_IN
{
float4 Pos : SV_POSITION; // World position
float2 Tex : TEXCOORD0; // Texture coord
float4 Pos : SV_POSITION;
};
struct PS_CUBEMAP_IN
{
float4 Pos : SV_POSITION;
float3 pos3D : POSITION3D;
float2 Tex : TEXCOORD0; // Texture coord
uint RTIndex : SV_RenderTargetArrayIndex;
};
@@ -32,7 +30,6 @@ void main( triangle GS_CUBEMAP_IN input[3], inout TriangleStream<PS_CUBEMAP_IN>
{
output.Pos = mul(input[v].Pos, xCubeShadowVP[f]);
output.pos3D = input[v].Pos.xyz;
output.Tex = input[v].Tex;
CubeMapStream.Append(output);
}
CubeMapStream.RestartStrip();
+40
View File
@@ -0,0 +1,40 @@
#include "globals.hlsli"
struct GS_CUBEMAP_IN
{
float4 Pos : SV_POSITION;
float2 Tex : TEXCOORD0;
};
struct PS_CUBEMAP_IN
{
float4 Pos : SV_POSITION;
float3 pos3D : POSITION3D;
float2 Tex : TEXCOORD0;
uint RTIndex : SV_RenderTargetArrayIndex;
};
CBUFFER(CubemapRenderCB, CBSLOT_RENDERER_CUBEMAPRENDER)
{
float4x4 xCubeShadowVP[6];
}
[maxvertexcount(18)]
void main(triangle GS_CUBEMAP_IN input[3], inout TriangleStream<PS_CUBEMAP_IN> CubeMapStream)
{
[unroll]
for (int f = 0; f < 6; ++f)
{
PS_CUBEMAP_IN output;
output.RTIndex = f;
[unroll]
for (int v = 0; v < 3; v++)
{
output.Pos = mul(input[v].Pos, xCubeShadowVP[f]);
output.pos3D = input[v].Pos.xyz;
output.Tex = input[v].Tex;
CubeMapStream.Append(output);
}
CubeMapStream.RestartStrip();
}
}
-2
View File
@@ -4,12 +4,10 @@ struct VertextoPixel
{
float4 pos : SV_POSITION;
float3 pos3D : POSITION3D;
float2 tex : TEXCOORD0;
uint RTIndex : SV_RenderTargetArrayIndex;
};
float main(VertextoPixel PSIn) : SV_DEPTHLESSEQUAL
{
ALPHATEST(xBaseColorMap.Sample(sampler_linear_wrap,PSIn.tex).a);
return distance(PSIn.pos3D.xyz, g_xColor.xyz) * g_xColor.w; // g_xColor.w = 1.0 / range
}
+15
View File
@@ -0,0 +1,15 @@
#include "objectHF.hlsli"
struct VertextoPixel
{
float4 pos : SV_POSITION;
float3 pos3D : POSITION3D;
float2 tex : TEXCOORD0;
uint RTIndex : SV_RenderTargetArrayIndex;
};
float main(VertextoPixel PSIn) : SV_DEPTHLESSEQUAL
{
ALPHATEST(xBaseColorMap.Sample(sampler_linear_wrap,PSIn.tex).a);
return distance(PSIn.pos3D.xyz, g_xColor.xyz) * g_xColor.w; // g_xColor.w = 1.0 / range
}
+3 -7
View File
@@ -4,21 +4,17 @@
struct GS_CUBEMAP_IN
{
float4 Pos : SV_POSITION; // World position
float2 Tex : TEXCOORD0; // Texture coord
float4 Pos : SV_POSITION; // World position
};
GS_CUBEMAP_IN main(Input_Shadow input)
GS_CUBEMAP_IN main(Input_Shadow_POS input)
{
GS_CUBEMAP_IN Out = (GS_CUBEMAP_IN)0;
float4x4 WORLD = MakeWorldMatrixFromInstance(input.instance);
float4 pos = input.pos;
Out.Pos = mul(pos, WORLD);
Out.Tex = input.tex.xy;
Out.Pos = mul(float4(input.pos.xyz, 1), WORLD);
return Out;
+23
View File
@@ -0,0 +1,23 @@
#include "globals.hlsli"
#include "objectInputLayoutHF.hlsli"
struct GS_CUBEMAP_IN
{
float4 Pos : SV_POSITION; // World position
float2 Tex : TEXCOORD0; // Texture coord
};
GS_CUBEMAP_IN main(Input_Shadow_POS_TEX input)
{
GS_CUBEMAP_IN Out = (GS_CUBEMAP_IN)0;
float4x4 WORLD = MakeWorldMatrixFromInstance(input.instance);
Out.Pos = mul(float4(input.pos.xyz, 1), WORLD);
Out.Tex = input.tex.xy;
return Out;
}
+1 -1
View File
@@ -2,7 +2,7 @@
#include "envMapHF.hlsli"
VSOut main(Input input)
VSOut main(Input_Object_ALL input)
{
VSOut Out = (VSOut)0;
+14 -6
View File
@@ -14,9 +14,14 @@ struct Input_InstancePrev
float4 wiPrev1 : MATIPREV1;
float4 wiPrev2 : MATIPREV2;
};
struct Input_Shadow
struct Input_Shadow_POS
{
float4 pos : POSITION;
Input_Instance instance;
};
struct Input_Shadow_POS_TEX
{
uint id: SV_VertexID;
float4 pos : POSITION;
float4 tex : TEXCOORD0;
Input_Instance instance;
@@ -28,16 +33,19 @@ struct Input_Skinning
float4 bon : TEXCOORD0;
float4 wei : TEXCOORD1;
};
struct Input_Simple
struct Input_Object_POS
{
float4 pos : POSITION;
Input_Instance instance;
};
struct Input_Object_POS_TEX
{
uint id: SV_VertexID;
float4 pos : POSITION;
float4 tex : TEXCOORD0;
Input_Instance instance;
};
struct Input
struct Input_Object_ALL
{
uint id: SV_VertexID;
float4 pos : POSITION;
float4 nor : NORMAL;
float4 tex : TEXCOORD0;
+5 -5
View File
@@ -2,7 +2,7 @@
PixelInputType main(Input input)
PixelInputType main(Input_Object_ALL input)
{
PixelInputType Out = (PixelInputType)0;
@@ -13,8 +13,8 @@ PixelInputType main(Input input)
Out.instanceColor = input.instance.color_dither.rgb;
Out.dither = input.instance.color_dither.a;
float4 pos = input.pos;
float4 posPrev = input.pre;
float4 pos = float4(input.pos.xyz, 1);
float4 posPrev = float4(input.pre.xyz, 1);
pos = mul( pos,WORLD );
posPrev = mul(posPrev, WORLDPREV);
@@ -23,8 +23,8 @@ PixelInputType main(Input input)
Out.clip = dot(pos, g_xClipPlane);
float3 normal = mul(normalize(input.nor.xyz), (float3x3)WORLD);
affectWind(pos.xyz, input.tex.w, input.id, g_xFrame_Time);
affectWind(posPrev.xyz, input.tex.w, input.id, g_xFrame_TimePrev);
affectWind(pos.xyz, input.pos.w, g_xFrame_Time);
affectWind(posPrev.xyz, input.pos.w, g_xFrame_TimePrev);
//VERTEX OFFSET MOTION BLUR
@@ -12,7 +12,7 @@ struct HullInputType
};
HullInputType main(Input input)
HullInputType main(Input_Object_ALL input)
{
HullInputType Out = (HullInputType)0;
@@ -20,17 +20,17 @@ HullInputType main(Input input)
float4x4 WORLD = MakeWorldMatrixFromInstance(input.instance);
float4x4 WORLDPREV = MakeWorldMatrixFromInstance(input.instancePrev);
float4 pos = input.pos;
float4 posPrev = input.pre;
float4 pos = float4(input.pos.xyz, 1);
float4 posPrev = float4(input.pre.xyz, 1);
pos = mul( pos,WORLD );
pos = mul(pos, WORLD);
posPrev = mul(posPrev, WORLDPREV);
float3 normal = mul(normalize(input.nor.xyz), (float3x3)WORLD);
affectWind(pos.xyz, input.tex.w, input.id, g_xFrame_Time);
affectWind(posPrev.xyz,input.tex.w,input.id, g_xFrame_TimePrev);
affectWind(pos.xyz, input.pos.w, g_xFrame_Time);
affectWind(posPrev.xyz,input.pos.w, g_xFrame_TimePrev);
Out.pos=pos.xyz;
+1 -1
View File
@@ -2,5 +2,5 @@
float4 main( float4 pos : POSITION ) : SV_POSITION
{
return mul(pos, g_xTransform);
return mul(float4(pos.xyz, 1), g_xTransform);
}
+19
View File
@@ -0,0 +1,19 @@
#include "objectHF.hlsli"
float4 main(Input_Object_POS input) : SV_POSITION
{
PixelInputType_Simple Out = (PixelInputType_Simple)0;
float4x4 WORLD = MakeWorldMatrixFromInstance(input.instance);
float4 pos = float4(input.pos.xyz, 1);
pos = mul(pos, WORLD);
affectWind(pos.xyz, input.pos.w, g_xFrame_Time);
return mul(pos, g_xCamera_VP);
}
+3 -3
View File
@@ -2,7 +2,7 @@
PixelInputType_Simple main(Input_Simple input)
PixelInputType_Simple main(Input_Object_POS_TEX input)
{
PixelInputType_Simple Out = (PixelInputType_Simple)0;
@@ -11,13 +11,13 @@ PixelInputType_Simple main(Input_Simple input)
Out.instanceColor = input.instance.color_dither.rgb;
Out.dither = input.instance.color_dither.a;
float4 pos = input.pos;
float4 pos = float4(input.pos.xyz, 1);
pos = mul(pos, WORLD);
Out.clip = dot(pos, g_xClipPlane);
affectWind(pos.xyz, input.tex.w, input.id, g_xFrame_Time);
affectWind(pos.xyz, input.pos.w, g_xFrame_Time);
Out.pos = mul(pos, g_xCamera_VP);
@@ -12,18 +12,18 @@ struct HullInputType
};
HullInputType main(Input input)
HullInputType main(Input_Object_ALL input)
{
HullInputType Out = (HullInputType)0;
float4x4 WORLD = MakeWorldMatrixFromInstance(input.instance);
float4 pos = input.pos;
float4 pos = float4(input.pos.xyz, 1);
pos = mul(pos, WORLD);
affectWind(pos.xyz, input.tex.w, input.id, g_xFrame_Time);
affectWind(pos.xyz, input.pos.w, g_xFrame_Time);
float3 normal = mul(normalize(input.nor.xyz), (float3x3)WORLD);
+2 -2
View File
@@ -8,13 +8,13 @@ struct VSOut
float3 instanceColor : COLOR;
};
VSOut main(Input input, uint instanceID : SV_INSTANCEID)
VSOut main(Input_Object_ALL input, uint instanceID : SV_INSTANCEID)
{
VSOut Out = (VSOut)0;
float4x4 WORLD = MakeWorldMatrixFromInstance(input.instance);
Out.pos = mul(input.pos, WORLD);
Out.pos = mul(float4(input.pos.xyz, 1), WORLD);
Out.nor = normalize(mul(input.nor.xyz, (float3x3)WORLD));
Out.tex = input.tex.xy;
Out.instanceColor = input.instance.color_dither.rgb;
+3 -5
View File
@@ -6,20 +6,18 @@
struct VertexOut
{
float4 pos : SV_POSITION;
float2 tex : TEXCOORD0;
};
VertexOut main(Input_Shadow input)
VertexOut main(Input_Shadow_POS input)
{
VertexOut Out = (VertexOut)0;
float4x4 WORLD = MakeWorldMatrixFromInstance(input.instance);
Out.pos = mul(input.pos, WORLD);
affectWind(Out.pos.xyz, input.tex.w, input.id, g_xFrame_Time);
Out.pos = mul(float4(input.pos.xyz, 1), WORLD);
affectWind(Out.pos.xyz, input.pos.w, g_xFrame_Time);
Out.pos = mul(Out.pos, g_xCamera_VP);
Out.tex = input.tex.xy;
return Out;
+26
View File
@@ -0,0 +1,26 @@
#include "globals.hlsli"
#include "objectInputLayoutHF.hlsli"
#include "windHF.hlsli"
struct VertexOut
{
float4 pos : SV_POSITION;
float2 tex : TEXCOORD0;
};
VertexOut main(Input_Shadow_POS_TEX input)
{
VertexOut Out = (VertexOut)0;
float4x4 WORLD = MakeWorldMatrixFromInstance(input.instance);
Out.pos = mul(float4(input.pos.xyz, 1), WORLD);
affectWind(Out.pos.xyz, input.pos.w, g_xFrame_Time);
Out.pos = mul(Out.pos, g_xCamera_VP);
Out.tex = input.tex.xy;
return Out;
}
+4 -4
View File
@@ -23,13 +23,13 @@ inline void Skinning(inout float4 pos, inout float4 posPrev, inout float4 nor, i
mp = boneBuffer[(uint)inBon[i]].prev;
m3 = (float3x3)m;
p += mul(pos, m)*inWei[i];
pp += mul(posPrev, mp)*inWei[i];
p += mul(float4(pos.xyz, 1), m)*inWei[i];
pp += mul(float4(posPrev.xyz, 1), mp)*inWei[i];
n += mul(nor.xyz, m3)*inWei[i];
}
bool w = any(inWei);
pos = w ? p : pos;
posPrev = w ? pp : posPrev;
pos.xyz = w ? p.xyz : pos.xyz;
posPrev.xyz = w ? pp.xyz : posPrev.xyz;
nor.xyz = w ? n : nor.xyz;
}
+1 -1
View File
@@ -1,6 +1,6 @@
#include "objectHF.hlsli"
PixelInputType main(Input input)
PixelInputType main(Input_Object_ALL input)
{
PixelInputType Out = (PixelInputType)0;
+1 -1
View File
@@ -7,7 +7,7 @@
using namespace std;
// this should always be only INCREMENTED and only if a new serialization is implemeted somewhere!
uint64_t __archiveVersion = 7;
uint64_t __archiveVersion = 8;
// this is the version number of which below the archive is not compatible with the current version
uint64_t __archiveVersionBarrier = 1;
+11 -6
View File
@@ -106,7 +106,9 @@ enum VSTYPES
VSTYPE_OBJECT_COMMON_TESSELLATION,
VSTYPE_OBJECT_SIMPLE_TESSELLATION,
VSTYPE_SHADOW,
VSTYPE_SHADOWCUBE,
VSTYPE_SHADOW_ALPHATEST,
VSTYPE_SHADOWCUBEMAPRENDER,
VSTYPE_SHADOWCUBEMAPRENDER_ALPHATEST,
VSTYPE_LINE,
VSTYPE_TRAIL,
VSTYPE_WATER,
@@ -172,7 +174,7 @@ enum PSTYPES
PSTYPE_OBJECT_TEXTUREONLY,
PSTYPE_OBJECT_ALPHATESTONLY,
PSTYPE_SHADOW,
PSTYPE_SHADOW_ALPHATEST,
PSTYPE_LINE,
PSTYPE_TRAIL,
PSTYPE_ENVIRONMENTALLIGHT,
@@ -186,6 +188,7 @@ enum PSTYPES
PSTYPE_TUBELIGHT,
PSTYPE_VOLUMELIGHT,
PSTYPE_SHADOWCUBEMAPRENDER,
PSTYPE_SHADOWCUBEMAPRENDER_ALPHATEST,
PSTYPE_DECAL,
PSTYPE_SKY,
PSTYPE_SUN,
@@ -201,6 +204,7 @@ enum PSTYPES
enum GSTYPES
{
GSTYPE_SHADOWCUBEMAPRENDER,
GSTYPE_SHADOWCUBEMAPRENDER_ALPHATEST,
GSTYPE_STREAMOUT,
GSTYPE_ENVMAP,
GSTYPE_ENVMAP_SKY,
@@ -245,10 +249,11 @@ enum CSTYPES
// vertex layouts
enum VLTYPES
{
VLTYPE_OBJECT,
VLTYPE_OBJECT_SIMPLE,
VLTYPE_OBJECT_DEBUG,
VLTYPE_SHADOW,
VLTYPE_OBJECT_POS,
VLTYPE_OBJECT_POS_TEX,
VLTYPE_OBJECT_ALL,
VLTYPE_SHADOW_POS,
VLTYPE_SHADOW_POS_TEX,
VLTYPE_LINE,
VLTYPE_TRAIL,
VLTYPE_STREAMOUT,
+2 -2
View File
@@ -1401,7 +1401,7 @@ GraphicsDevice_DX11::GraphicsDevice_DX11(wiWindowRegistration::window_type windo
}
UINT createDeviceFlags = 0;
//createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
D3D_DRIVER_TYPE driverTypes[] =
{
@@ -3051,7 +3051,7 @@ void GraphicsDevice_DX11::BindVertexBuffers(const GPUBuffer* const *vertexBuffer
{
assert(count <= 8);
ID3D11Buffer* res[8] = { 0 };
for (UINT i = 0; i < count; ++i)
for (int i = 0; i < count; ++i)
{
res[i] = vertexBuffers[i] != nullptr ? vertexBuffers[i]->resource_DX11 : nullptr;
}
+6 -1
View File
@@ -534,7 +534,7 @@ void LoadWiMeshes(const std::string& directory, const std::string& name, const s
case 'v':
for (int vprop = 0; vprop < VPROP_COUNT; ++vprop)
{
currentMesh->vertices[vprop].push_back(XMFLOAT4(0,0,0,1));
currentMesh->vertices[vprop].push_back(XMFLOAT4(0,0,0,0));
}
file >> currentMesh->vertices[VPROP_POS].back().x;
file >> currentMesh->vertices[VPROP_POS].back().y;
@@ -2347,6 +2347,11 @@ void Mesh::Serialize(wiArchive& archive)
archive >> vertices[VPROP_TEX][i];
archive >> vertices[VPROP_BON][i];
archive >> vertices[VPROP_WEI][i];
if (archive.GetVersion() < 8)
{
vertices[VPROP_POS][i].w = vertices[VPROP_TEX][i].w;
}
}
}
// indices
+8 -8
View File
@@ -36,9 +36,9 @@ class wiArchive;
enum VERTEXPROPERTY
{
VPROP_POS, // pos
VPROP_POS, // pos, wind
VPROP_NOR, // normal, vertexao
VPROP_TEX, // texcoord, materialindex, wind
VPROP_TEX, // texcoord, materialindex, unused
VPROP_BON, // boneindices
VPROP_WEI, // boneweights
VPROP_COUNT,
@@ -46,15 +46,15 @@ enum VERTEXPROPERTY
#define VPROP_PRE VPROP_BON // posprev
struct SkinnedVertex
{
XMFLOAT4 pos; //pos
XMFLOAT4 pos; //pos, wind
XMFLOAT4 nor; //normal, vertex ao
XMFLOAT4 tex; //tex, matIndex, wind
XMFLOAT4 tex; //tex, matIndex, unused
XMFLOAT4 bon; //bone indices
XMFLOAT4 wei; //bone weights
SkinnedVertex(){
pos=XMFLOAT4(0,0,0,1);
pos=XMFLOAT4(0,0,0,0);
nor=XMFLOAT4(0,0,0,1);
tex=XMFLOAT4(0,0,0,0);
bon=XMFLOAT4(0,0,0,0);
@@ -71,13 +71,13 @@ struct SkinnedVertex
};
struct Vertex
{
XMFLOAT4 pos; //pos
XMFLOAT4 pos; //pos, wind
XMFLOAT4 nor; //normal, vertex ao
XMFLOAT4 tex; //tex, matIndex, wind
XMFLOAT4 tex; //tex, matIndex, unused
XMFLOAT4 pre; //previous frame position
Vertex(){
pos=XMFLOAT4(0,0,0,1);
pos=XMFLOAT4(0,0,0,0);
nor=XMFLOAT4(0,0,0,1);
tex=XMFLOAT4(0,0,0,0);
pre=XMFLOAT4(0,0,0,0);
+129 -61
View File
@@ -631,7 +631,7 @@ void wiRenderer::LoadShaders()
VertexShaderInfo* vsinfo = static_cast<VertexShaderInfo*>(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectVS_debug.cso", wiResourceManager::VERTEXSHADER, layout, numElements));
if (vsinfo != nullptr) {
vertexShaders[VSTYPE_OBJECT_DEBUG] = vsinfo->vertexShader;
vertexLayouts[VLTYPE_OBJECT_DEBUG] = vsinfo->vertexLayout;
vertexLayouts[VLTYPE_OBJECT_POS] = vsinfo->vertexLayout;
}
}
{
@@ -654,7 +654,7 @@ void wiRenderer::LoadShaders()
VertexShaderInfo* vsinfo = static_cast<VertexShaderInfo*>(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectVS_common.cso", wiResourceManager::VERTEXSHADER, layout, numElements));
if (vsinfo != nullptr){
vertexShaders[VSTYPE_OBJECT_COMMON] = vsinfo->vertexShader;
vertexLayouts[VLTYPE_OBJECT] = vsinfo->vertexLayout;
vertexLayouts[VLTYPE_OBJECT_ALL] = vsinfo->vertexLayout;
}
}
{
@@ -672,10 +672,26 @@ void wiRenderer::LoadShaders()
VertexShaderInfo* vsinfo = static_cast<VertexShaderInfo*>(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectVS_Simple.cso", wiResourceManager::VERTEXSHADER, layout, numElements));
if (vsinfo != nullptr){
vertexShaders[VSTYPE_OBJECT_SIMPLE] = vsinfo->vertexShader;
vertexLayouts[VLTYPE_OBJECT_SIMPLE] = vsinfo->vertexLayout;
vertexLayouts[VLTYPE_OBJECT_POS_TEX] = vsinfo->vertexLayout;
}
}
{
VertexLayoutDesc layout[] =
{
{ "POSITION", 0, FORMAT_R32G32B32A32_FLOAT, 0, APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 },
{ "MATI", 0, FORMAT_R32G32B32A32_FLOAT, 2, APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
{ "MATI", 1, FORMAT_R32G32B32A32_FLOAT, 2, APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
{ "MATI", 2, FORMAT_R32G32B32A32_FLOAT, 2, APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
{ "COLOR_DITHER", 0, FORMAT_R32G32B32A32_FLOAT, 2, APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
};
UINT numElements = ARRAYSIZE(layout);
VertexShaderInfo* vsinfo = static_cast<VertexShaderInfo*>(wiResourceManager::GetShaderManager()->add(SHADERPATH + "shadowVS.cso", wiResourceManager::VERTEXSHADER, layout, numElements));
if (vsinfo != nullptr) {
vertexShaders[VSTYPE_SHADOW] = vsinfo->vertexShader;
vertexLayouts[VLTYPE_SHADOW_POS] = vsinfo->vertexLayout;
}
}
{
VertexLayoutDesc layout[] =
{
@@ -688,13 +704,12 @@ void wiRenderer::LoadShaders()
{ "COLOR_DITHER", 0, FORMAT_R32G32B32A32_FLOAT, 2, APPEND_ALIGNED_ELEMENT, INPUT_PER_INSTANCE_DATA, 1 },
};
UINT numElements = ARRAYSIZE(layout);
VertexShaderInfo* vsinfo = static_cast<VertexShaderInfo*>(wiResourceManager::GetShaderManager()->add(SHADERPATH + "shadowVS.cso", wiResourceManager::VERTEXSHADER, layout, numElements));
if (vsinfo != nullptr){
vertexShaders[VSTYPE_SHADOW] = vsinfo->vertexShader;
vertexLayouts[VLTYPE_SHADOW] = vsinfo->vertexLayout;
VertexShaderInfo* vsinfo = static_cast<VertexShaderInfo*>(wiResourceManager::GetShaderManager()->add(SHADERPATH + "shadowVS_alphatest.cso", wiResourceManager::VERTEXSHADER, layout, numElements));
if (vsinfo != nullptr) {
vertexShaders[VSTYPE_SHADOW_ALPHATEST] = vsinfo->vertexShader;
vertexLayouts[VLTYPE_SHADOW_POS_TEX] = vsinfo->vertexLayout;
}
}
{
VertexLayoutDesc oslayout[] =
{
@@ -772,7 +787,8 @@ void wiRenderer::LoadShaders()
vertexShaders[VSTYPE_ENVMAP_SKY] = static_cast<VertexShaderInfo*>(wiResourceManager::GetShaderManager()->add(SHADERPATH + "envMap_skyVS.cso", wiResourceManager::VERTEXSHADER))->vertexShader;
vertexShaders[VSTYPE_SPHERE] = static_cast<VertexShaderInfo*>(wiResourceManager::GetShaderManager()->add(SHADERPATH + "sphereVS.cso", wiResourceManager::VERTEXSHADER))->vertexShader;
vertexShaders[VSTYPE_CUBE] = static_cast<VertexShaderInfo*>(wiResourceManager::GetShaderManager()->add(SHADERPATH + "cubeVS.cso", wiResourceManager::VERTEXSHADER))->vertexShader;
vertexShaders[VSTYPE_SHADOWCUBE] = static_cast<VertexShaderInfo*>(wiResourceManager::GetShaderManager()->add(SHADERPATH + "cubeShadowVS.cso", wiResourceManager::VERTEXSHADER))->vertexShader;
vertexShaders[VSTYPE_SHADOWCUBEMAPRENDER] = static_cast<VertexShaderInfo*>(wiResourceManager::GetShaderManager()->add(SHADERPATH + "cubeShadowVS.cso", wiResourceManager::VERTEXSHADER))->vertexShader;
vertexShaders[VSTYPE_SHADOWCUBEMAPRENDER_ALPHATEST] = static_cast<VertexShaderInfo*>(wiResourceManager::GetShaderManager()->add(SHADERPATH + "cubeShadowVS_alphatest.cso", wiResourceManager::VERTEXSHADER))->vertexShader;
vertexShaders[VSTYPE_SKY] = static_cast<VertexShaderInfo*>(wiResourceManager::GetShaderManager()->add(SHADERPATH + "skyVS.cso", wiResourceManager::VERTEXSHADER))->vertexShader;
vertexShaders[VSTYPE_WATER] = static_cast<VertexShaderInfo*>(wiResourceManager::GetShaderManager()->add(SHADERPATH + "waterVS.cso", wiResourceManager::VERTEXSHADER))->vertexShader;
vertexShaders[VSTYPE_VOXELIZER] = static_cast<VertexShaderInfo*>(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectVS_voxelizer.cso", wiResourceManager::VERTEXSHADER))->vertexShader;
@@ -835,8 +851,9 @@ void wiRenderer::LoadShaders()
pixelShaders[PSTYPE_LINE] = static_cast<PixelShader*>(wiResourceManager::GetShaderManager()->add(SHADERPATH + "linesPS.cso", wiResourceManager::PIXELSHADER));
pixelShaders[PSTYPE_SKY] = static_cast<PixelShader*>(wiResourceManager::GetShaderManager()->add(SHADERPATH + "skyPS.cso", wiResourceManager::PIXELSHADER));
pixelShaders[PSTYPE_SUN] = static_cast<PixelShader*>(wiResourceManager::GetShaderManager()->add(SHADERPATH + "sunPS.cso", wiResourceManager::PIXELSHADER));
pixelShaders[PSTYPE_SHADOW] = static_cast<PixelShader*>(wiResourceManager::GetShaderManager()->add(SHADERPATH + "shadowPS.cso", wiResourceManager::PIXELSHADER));
pixelShaders[PSTYPE_SHADOW_ALPHATEST] = static_cast<PixelShader*>(wiResourceManager::GetShaderManager()->add(SHADERPATH + "shadowPS_alphatest.cso", wiResourceManager::PIXELSHADER));
pixelShaders[PSTYPE_SHADOWCUBEMAPRENDER] = static_cast<PixelShader*>(wiResourceManager::GetShaderManager()->add(SHADERPATH + "cubeShadowPS.cso", wiResourceManager::PIXELSHADER));
pixelShaders[PSTYPE_SHADOWCUBEMAPRENDER_ALPHATEST] = static_cast<PixelShader*>(wiResourceManager::GetShaderManager()->add(SHADERPATH + "cubeShadowPS_alphatest.cso", wiResourceManager::PIXELSHADER));
pixelShaders[PSTYPE_TRAIL] = static_cast<PixelShader*>(wiResourceManager::GetShaderManager()->add(SHADERPATH + "trailPS.cso", wiResourceManager::PIXELSHADER));
pixelShaders[PSTYPE_VOXELIZER] = static_cast<PixelShader*>(wiResourceManager::GetShaderManager()->add(SHADERPATH + "objectPS_voxelizer.cso", wiResourceManager::PIXELSHADER));
pixelShaders[PSTYPE_VOXEL] = static_cast<PixelShader*>(wiResourceManager::GetShaderManager()->add(SHADERPATH + "voxelPS.cso", wiResourceManager::PIXELSHADER));
@@ -2627,7 +2644,7 @@ void wiRenderer::DrawDebugEmitters(Camera* camera, GRAPHICSTHREAD threadID)
GetDevice()->EventBegin("DebugEmitters", threadID);
GetDevice()->BindPrimitiveTopology(TRIANGLELIST, threadID);
GetDevice()->BindVertexLayout(vertexLayouts[VLTYPE_OBJECT_DEBUG], threadID);
GetDevice()->BindVertexLayout(vertexLayouts[VLTYPE_OBJECT_POS], threadID);
GetDevice()->BindRasterizerState(rasterizers[RSTYPE_WIRE_DOUBLESIDED_SMOOTH], threadID);
GetDevice()->BindDepthStencilState(depthStencils[DSSTYPE_DEPTHREAD], STENCILREF_EMPTY, threadID);
@@ -3207,7 +3224,6 @@ void wiRenderer::DrawForShadowMap(GRAPHICSTHREAD threadID)
GetDevice()->UnBindResources(TEXSLOT_SHADOWARRAY_2D, 2, threadID);
GetDevice()->BindPrimitiveTopology(TRIANGLELIST, threadID);
GetDevice()->BindVertexLayout(vertexLayouts[VLTYPE_OBJECT], threadID);
GetDevice()->BindDepthStencilState(depthStencils[DSSTYPE_DEFAULT], STENCILREF_DEFAULT, threadID);
@@ -3580,7 +3596,7 @@ PSTYPES GetPSTYPE(SHADERTYPE shaderType, const Material* const material)
}
break;
case SHADERTYPE_SHADOW:
realPS = PSTYPE_SHADOW;
realPS = PSTYPE_SHADOW_ALPHATEST;
break;
case SHADERTYPE_SHADOWCUBE:
realPS = PSTYPE_SHADOWCUBEMAPRENDER;
@@ -3662,38 +3678,38 @@ void wiRenderer::RenderMeshes(const XMFLOAT3& eye, const CulledCollection& culle
{
GetDevice()->BindVS(vertexShaders[VSTYPE_VOXELIZER], threadID);
GetDevice()->BindGS(geometryShaders[GSTYPE_VOXELIZER], threadID);
GetDevice()->BindVertexLayout(vertexLayouts[VLTYPE_OBJECT], threadID);
GetDevice()->BindVertexLayout(vertexLayouts[VLTYPE_OBJECT_ALL], threadID);
}
else
{
if (shaderType == SHADERTYPE_SHADOW)
{
GetDevice()->BindVS(vertexShaders[VSTYPE_SHADOW], threadID);
GetDevice()->BindVertexLayout(vertexLayouts[VLTYPE_SHADOW], threadID);
GetDevice()->BindVS(vertexShaders[VSTYPE_SHADOW_ALPHATEST], threadID);
GetDevice()->BindVertexLayout(vertexLayouts[VLTYPE_SHADOW_POS_TEX], threadID);
}
else if (shaderType == SHADERTYPE_SHADOWCUBE)
{
GetDevice()->BindVS(vertexShaders[VSTYPE_SHADOWCUBE], threadID);
GetDevice()->BindGS(geometryShaders[GSTYPE_SHADOWCUBEMAPRENDER], threadID);
GetDevice()->BindVertexLayout(vertexLayouts[VLTYPE_SHADOW], threadID);
GetDevice()->BindVS(vertexShaders[VSTYPE_SHADOWCUBEMAPRENDER_ALPHATEST], threadID);
GetDevice()->BindGS(geometryShaders[GSTYPE_SHADOWCUBEMAPRENDER_ALPHATEST], threadID);
GetDevice()->BindVertexLayout(vertexLayouts[VLTYPE_SHADOW_POS_TEX], threadID);
}
else if (shaderType == SHADERTYPE_ENVMAPCAPTURE)
{
GetDevice()->BindVS(vertexShaders[VSTYPE_ENVMAP], threadID);
GetDevice()->BindGS(geometryShaders[GSTYPE_ENVMAP], threadID);
GetDevice()->BindVertexLayout(vertexLayouts[VLTYPE_OBJECT], threadID);
GetDevice()->BindVertexLayout(vertexLayouts[VLTYPE_OBJECT_ALL], threadID);
}
else if (shaderType == SHADERTYPE_ALPHATESTONLY || shaderType == SHADERTYPE_TEXTURE)
{
if (tessellatorRequested)
{
GetDevice()->BindVS(vertexShaders[VSTYPE_OBJECT_SIMPLE_TESSELLATION], threadID);
GetDevice()->BindVertexLayout(vertexLayouts[VLTYPE_OBJECT], threadID); // tessellator requires normals
GetDevice()->BindVertexLayout(vertexLayouts[VLTYPE_OBJECT_ALL], threadID); // tessellator requires normals
}
else
{
GetDevice()->BindVS(vertexShaders[VSTYPE_OBJECT_SIMPLE], threadID);
GetDevice()->BindVertexLayout(vertexLayouts[VLTYPE_OBJECT_SIMPLE], threadID);
GetDevice()->BindVertexLayout(vertexLayouts[VLTYPE_OBJECT_POS_TEX], threadID);
}
}
else
@@ -3706,7 +3722,7 @@ void wiRenderer::RenderMeshes(const XMFLOAT3& eye, const CulledCollection& culle
{
GetDevice()->BindVS(vertexShaders[VSTYPE_OBJECT_COMMON], threadID);
}
GetDevice()->BindVertexLayout(vertexLayouts[VLTYPE_OBJECT], threadID);
GetDevice()->BindVertexLayout(vertexLayouts[VLTYPE_OBJECT_ALL], threadID);
}
}
@@ -3838,7 +3854,7 @@ void wiRenderer::RenderMeshes(const XMFLOAT3& eye, const CulledCollection& culle
GetDevice()->BindPS(pixelShaders[PSTYPE_OBJECT_TILEDFORWARD], threadID);
break;
case SHADERTYPE_SHADOW:
GetDevice()->BindPS(pixelShaders[PSTYPE_SHADOW], threadID);
GetDevice()->BindPS(pixelShaders[PSTYPE_SHADOW_ALPHATEST], threadID);
break;
case SHADERTYPE_SHADOWCUBE:
GetDevice()->BindPS(pixelShaders[PSTYPE_SHADOWCUBEMAPRENDER], threadID);
@@ -3934,42 +3950,15 @@ void wiRenderer::RenderMeshes(const XMFLOAT3& eye, const CulledCollection& culle
mesh->UpdateRenderableInstancesPrev(k, threadID);
}
if (!tessellatorRequested && (shaderType == SHADERTYPE_ALPHATESTONLY || shaderType == SHADERTYPE_TEXTURE || shaderType == SHADERTYPE_SHADOW || shaderType == SHADERTYPE_SHADOWCUBE))
enum class BOUNDVERTEXBUFFERTYPE
{
// simple vertex buffers are used in some passes (note: tessellator requires more attributes)
GPUBuffer* vbs[] = {
(mesh->streamoutBuffers[VPROP_POS].IsValid() ? &mesh->streamoutBuffers[VPROP_POS] : &mesh->vertexBuffers[VPROP_POS]),
&mesh->vertexBuffers[VPROP_TEX],
&mesh->instanceBuffer
};
UINT strides[] = {
sizeof(XMFLOAT4),
sizeof(XMFLOAT4),
sizeof(Instance)
};
GetDevice()->BindVertexBuffers(vbs, 0, ARRAYSIZE(vbs), strides, threadID);
}
else
{
// common vertex buffers:
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]), // TODO: rewrite this shit
&mesh->instanceBuffer,
&mesh->instanceBufferPrev,
};
UINT strides[] = {
sizeof(XMFLOAT4),
sizeof(XMFLOAT4),
sizeof(XMFLOAT4),
sizeof(XMFLOAT4),
sizeof(Instance),
sizeof(InstancePrev),
};
GetDevice()->BindVertexBuffers(vbs, 0, ARRAYSIZE(vbs), strides, threadID);
}
NOTHING,
POSITION,
POSITION_TEXCOORD,
EVERYTHING,
};
BOUNDVERTEXBUFFERTYPE boundVBType_Prev = BOUNDVERTEXBUFFERTYPE::NOTHING;
BOUNDVERTEXBUFFERTYPE boundVBType = BOUNDVERTEXBUFFERTYPE::NOTHING;
for (MeshSubset& subset : mesh->subsets)
{
@@ -3977,9 +3966,88 @@ void wiRenderer::RenderMeshes(const XMFLOAT3& eye, const CulledCollection& culle
{
continue;
}
Material* material = subset.material;
if (!tessellatorRequested && (shaderType == SHADERTYPE_ALPHATESTONLY || shaderType == SHADERTYPE_TEXTURE || shaderType == SHADERTYPE_SHADOW || shaderType == SHADERTYPE_SHADOWCUBE))
{
// simple vertex buffers are used in some passes (note: tessellator requires more attributes)
if ((shaderType == SHADERTYPE_ALPHATESTONLY || shaderType == SHADERTYPE_SHADOW || shaderType == SHADERTYPE_SHADOWCUBE) && material->alphaRef > 1.0f - 1.0f / 256.0f)
{
// bypass texcoord stream for non alphatested shadows and zprepass
boundVBType = BOUNDVERTEXBUFFERTYPE::POSITION;
}
else
{
boundVBType = BOUNDVERTEXBUFFERTYPE::POSITION_TEXCOORD;
}
}
else
{
boundVBType = BOUNDVERTEXBUFFERTYPE::EVERYTHING;
}
// Only bind vertex buffers when the layout changes
if (boundVBType == BOUNDVERTEXBUFFERTYPE::NOTHING || boundVBType != boundVBType_Prev)
{
// Assemble the required vertex buffer:
switch (boundVBType)
{
case BOUNDVERTEXBUFFERTYPE::POSITION:
//{
// GPUBuffer* vbs[] = {
// (mesh->streamoutBuffers[VPROP_POS].IsValid() ? &mesh->streamoutBuffers[VPROP_POS] : &mesh->vertexBuffers[VPROP_POS]),
// &mesh->instanceBuffer
// };
// UINT strides[] = {
// sizeof(XMFLOAT4),
// sizeof(Instance)
// };
// GetDevice()->BindVertexBuffers(vbs, 0, ARRAYSIZE(vbs), strides, threadID);
//}
//break;
case BOUNDVERTEXBUFFERTYPE::POSITION_TEXCOORD:
{
GPUBuffer* vbs[] = {
(mesh->streamoutBuffers[VPROP_POS].IsValid() ? &mesh->streamoutBuffers[VPROP_POS] : &mesh->vertexBuffers[VPROP_POS]),
&mesh->vertexBuffers[VPROP_TEX],
&mesh->instanceBuffer
};
UINT strides[] = {
sizeof(XMFLOAT4),
sizeof(XMFLOAT4),
sizeof(Instance)
};
GetDevice()->BindVertexBuffers(vbs, 0, ARRAYSIZE(vbs), strides, threadID);
}
break;
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]), // TODO: rewrite this shit
&mesh->instanceBuffer,
&mesh->instanceBufferPrev,
};
UINT strides[] = {
sizeof(XMFLOAT4),
sizeof(XMFLOAT4),
sizeof(XMFLOAT4),
sizeof(XMFLOAT4),
sizeof(Instance),
sizeof(InstancePrev),
};
GetDevice()->BindVertexBuffers(vbs, 0, ARRAYSIZE(vbs), strides, threadID);
}
break;
default:
assert(0);
break;
}
}
boundVBType_Prev = boundVBType;
bool subsetRenderable = false;
@@ -5650,7 +5718,7 @@ void wiRenderer::CreateImpostor(Mesh* mesh)
GetDevice()->BindRasterizerState(rasterizers[RSTYPE_DOUBLESIDED], threadID);
GetDevice()->BindDepthStencilState(depthStencils[DSSTYPE_DEFAULT], mesh->stencilRef, threadID);
GetDevice()->BindPrimitiveTopology(TRIANGLELIST, threadID);
GetDevice()->BindVertexLayout(vertexLayouts[VLTYPE_OBJECT], threadID);
GetDevice()->BindVertexLayout(vertexLayouts[VLTYPE_OBJECT_ALL], threadID);
GetDevice()->BindVS(vertexShaders[VSTYPE_OBJECT_COMMON], threadID);
GetDevice()->BindPS(pixelShaders[PSTYPE_CAPTUREIMPOSTOR], threadID);
+1 -1
View File
@@ -9,7 +9,7 @@ namespace wiVersion
// minor features, major updates
const int minor = 11;
// minor bug fixes, alterations, refactors, updates
const int revision = 51;
const int revision = 53;
long GetVersion()
+2 -2
View File
@@ -3,8 +3,8 @@
#include "globals.hlsli"
inline void affectWind(inout float3 pos, in float value, in uint randVertex, float time) {
float3 wind = sin(time + (pos.x + pos.y + pos.z))*g_xFrame_WindDirection.xyz*0.1*value;
inline void affectWind(inout float3 pos, in float weight, float time) {
float3 wind = sin(time + (pos.x + pos.y + pos.z))*g_xFrame_WindDirection.xyz*0.1*weight;
pos += wind;
}