optimized depth prepass vertex buffers
This commit is contained in:
@@ -666,6 +666,12 @@
|
||||
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Vertex</ShaderType>
|
||||
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">Vertex</ShaderType>
|
||||
</FxCompile>
|
||||
<FxCompile Include="objectVS_simple.hlsl">
|
||||
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Vertex</ShaderType>
|
||||
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">Vertex</ShaderType>
|
||||
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Vertex</ShaderType>
|
||||
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">Vertex</ShaderType>
|
||||
</FxCompile>
|
||||
<FxCompile Include="objectVS_voxelizer.hlsl">
|
||||
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Vertex</ShaderType>
|
||||
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">Vertex</ShaderType>
|
||||
|
||||
@@ -567,6 +567,9 @@
|
||||
<FxCompile Include="cubeShadowVS.hlsl">
|
||||
<Filter>VS</Filter>
|
||||
</FxCompile>
|
||||
<FxCompile Include="objectVS_simple.hlsl">
|
||||
<Filter>VS</Filter>
|
||||
</FxCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Filter Include="PS">
|
||||
|
||||
@@ -28,6 +28,14 @@
|
||||
|
||||
#define sampler_objectshader sampler_aniso_wrap
|
||||
|
||||
struct PixelInputType_Simple
|
||||
{
|
||||
float4 pos : SV_POSITION;
|
||||
float clip : SV_ClipDistance0;
|
||||
float2 tex : TEXCOORD0;
|
||||
nointerpolation float dither : DITHER;
|
||||
nointerpolation float3 instanceColor : INSTANCECOLOR;
|
||||
};
|
||||
struct PixelInputType
|
||||
{
|
||||
float4 pos : SV_POSITION;
|
||||
@@ -216,7 +224,16 @@ inline void TiledLighting(in float2 pixel, in float3 N, in float3 V, in float3 P
|
||||
// MACROS
|
||||
////////////
|
||||
|
||||
#define OBJECT_PS_MAKE_SIMPLE \
|
||||
float2 UV = input.tex * g_xMat_texMulAdd.xy + g_xMat_texMulAdd.zw; \
|
||||
float4 baseColor = g_xMat_baseColor * float4(input.instanceColor, 1); \
|
||||
float4 color = baseColor; \
|
||||
float opacity = color.a; \
|
||||
float2 pixel = input.pos.xy;
|
||||
|
||||
|
||||
#define OBJECT_PS_MAKE_COMMON \
|
||||
OBJECT_PS_MAKE_SIMPLE \
|
||||
float3 diffuse = 0; \
|
||||
float3 specular = 0; \
|
||||
float3 N = normalize(input.nor); \
|
||||
@@ -224,10 +241,6 @@ inline void TiledLighting(in float2 pixel, in float3 N, in float3 V, in float3 P
|
||||
float3 V = g_xCamera_CamPos - P; \
|
||||
float dist = length(V); \
|
||||
V /= dist; \
|
||||
float2 UV = input.tex * g_xMat_texMulAdd.xy + g_xMat_texMulAdd.zw; \
|
||||
float4 baseColor = g_xMat_baseColor * float4(input.instanceColor, 1); \
|
||||
float4 color = baseColor; \
|
||||
float opacity = color.a; \
|
||||
float roughness = g_xMat_roughness; \
|
||||
roughness = saturate(roughness); \
|
||||
float metalness = g_xMat_metalness; \
|
||||
@@ -238,8 +251,7 @@ inline void TiledLighting(in float2 pixel, in float3 N, in float3 V, in float3 P
|
||||
float sss = g_xMat_subsurfaceScattering; \
|
||||
float3 bumpColor = 0; \
|
||||
float depth = input.pos.z; \
|
||||
float ao = input.ao; \
|
||||
float2 pixel = input.pos.xy;
|
||||
float ao = input.ao;
|
||||
|
||||
#define OBJECT_PS_MAKE \
|
||||
OBJECT_PS_MAKE_COMMON \
|
||||
@@ -251,11 +263,14 @@ inline void TiledLighting(in float2 pixel, in float3 N, in float3 V, in float3 P
|
||||
float3 T, B; \
|
||||
float3x3 TBN = compute_tangent_frame(N, P, UV, T, B);
|
||||
|
||||
#define OBJECT_PS_SAMPLETEXTURES \
|
||||
#define OBJECT_PS_SAMPLETEXTURES_SIMPLE \
|
||||
baseColor *= xBaseColorMap.Sample(sampler_objectshader, UV); \
|
||||
ALPHATEST(baseColor.a); \
|
||||
color = baseColor; \
|
||||
opacity = color.a; \
|
||||
|
||||
#define OBJECT_PS_SAMPLETEXTURES \
|
||||
OBJECT_PS_SAMPLETEXTURES_SIMPLE \
|
||||
roughness *= xRoughnessMap.Sample(sampler_objectshader, UV).r; \
|
||||
metalness *= xMetalnessMap.Sample(sampler_objectshader, UV).r; \
|
||||
reflectance *= xReflectanceMap.Sample(sampler_objectshader, UV).r;
|
||||
|
||||
@@ -22,6 +22,13 @@ struct Input_Skinning
|
||||
float4 bon : TEXCOORD0;
|
||||
float4 wei : TEXCOORD1;
|
||||
};
|
||||
struct Input_Simple
|
||||
{
|
||||
uint id: SV_VertexID;
|
||||
float4 pos : POSITION;
|
||||
float4 tex : TEXCOORD0;
|
||||
Input_Instance instance;
|
||||
};
|
||||
struct Input
|
||||
{
|
||||
uint id: SV_VertexID;
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
|
||||
|
||||
|
||||
void main(PixelInputType input)
|
||||
void main(PixelInputType_Simple input)
|
||||
{
|
||||
OBJECT_PS_DITHER
|
||||
|
||||
OBJECT_PS_MAKE
|
||||
OBJECT_PS_MAKE_SIMPLE
|
||||
|
||||
OBJECT_PS_SAMPLETEXTURES
|
||||
OBJECT_PS_SAMPLETEXTURES_SIMPLE
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
#include "objectHF.hlsli"
|
||||
|
||||
|
||||
|
||||
PixelInputType_Simple main(Input_Simple input)
|
||||
{
|
||||
PixelInputType_Simple Out = (PixelInputType_Simple)0;
|
||||
|
||||
float4x4 WORLD = MakeWorldMatrixFromInstance(input.instance);
|
||||
|
||||
Out.instanceColor = input.instance.color_dither.rgb;
|
||||
Out.dither = input.instance.color_dither.a;
|
||||
|
||||
float4 pos = input.pos;
|
||||
|
||||
pos = mul(pos, WORLD);
|
||||
|
||||
Out.clip = dot(pos, g_xClipPlane);
|
||||
|
||||
affectWind(pos.xyz, input.tex.w, input.id);
|
||||
|
||||
|
||||
Out.pos = mul(pos, g_xCamera_VP);
|
||||
Out.tex = input.tex.xy;
|
||||
|
||||
|
||||
return Out;
|
||||
}
|
||||
@@ -104,6 +104,7 @@ enum VSTYPES
|
||||
{
|
||||
VSTYPE_OBJECT,
|
||||
VSTYPE_OBJECT10,
|
||||
VSTYPE_OBJECT_SIMPLE,
|
||||
VSTYPE_SHADOW,
|
||||
VSTYPE_SHADOWCUBE,
|
||||
VSTYPE_LINE,
|
||||
@@ -243,6 +244,7 @@ enum CSTYPES
|
||||
enum VLTYPES
|
||||
{
|
||||
VLTYPE_EFFECT,
|
||||
VLTYPE_EFFECT_SIMPLE,
|
||||
VLTYPE_SHADOW,
|
||||
VLTYPE_LINE,
|
||||
VLTYPE_TRAIL,
|
||||
|
||||
@@ -625,6 +625,24 @@ void wiRenderer::LoadShaders()
|
||||
vertexLayouts[VLTYPE_EFFECT] = vsinfo->vertexLayout;
|
||||
}
|
||||
}
|
||||
{
|
||||
VertexLayoutDesc layout[] =
|
||||
{
|
||||
{ "POSITION", 0, FORMAT_R32G32B32A32_FLOAT, 0, APPEND_ALIGNED_ELEMENT, INPUT_PER_VERTEX_DATA, 0 },
|
||||
{ "TEXCOORD", 0, FORMAT_R32G32B32A32_FLOAT, 1, 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 + "objectVS_Simple.cso", wiResourceManager::VERTEXSHADER, layout, numElements));
|
||||
if (vsinfo != nullptr){
|
||||
vertexShaders[VSTYPE_OBJECT_SIMPLE] = vsinfo->vertexShader;
|
||||
vertexLayouts[VLTYPE_EFFECT_SIMPLE] = vsinfo->vertexLayout;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
VertexLayoutDesc layout[] =
|
||||
@@ -3489,6 +3507,11 @@ void wiRenderer::RenderMeshes(const XMFLOAT3& eye, const CulledCollection& culle
|
||||
GetDevice()->BindGS(geometryShaders[GSTYPE_ENVMAP], threadID);
|
||||
GetDevice()->BindVertexLayout(vertexLayouts[VLTYPE_EFFECT], threadID);
|
||||
}
|
||||
else if (shaderType == SHADERTYPE_ALPHATESTONLY)
|
||||
{
|
||||
GetDevice()->BindVS(vertexShaders[VSTYPE_OBJECT_SIMPLE], threadID);
|
||||
GetDevice()->BindVertexLayout(vertexLayouts[VLTYPE_EFFECT_SIMPLE], threadID);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (tessellation && tessF)
|
||||
@@ -3576,6 +3599,7 @@ void wiRenderer::RenderMeshes(const XMFLOAT3& eye, const CulledCollection& culle
|
||||
GetDevice()->BindDepthStencilState(depthStencils[targetDepthStencilState], targetStencilRef, threadID);
|
||||
|
||||
GetDevice()->BindIndexBuffer(nullptr, threadID);
|
||||
|
||||
GPUBuffer* vbs[] = {
|
||||
&Mesh::impostorVBs[VPROP_POS],
|
||||
&Mesh::impostorVBs[VPROP_NOR],
|
||||
@@ -3591,6 +3615,7 @@ void wiRenderer::RenderMeshes(const XMFLOAT3& eye, const CulledCollection& culle
|
||||
sizeof(Instance)
|
||||
};
|
||||
GetDevice()->BindVertexBuffers(vbs, 0, ARRAYSIZE(vbs), strides, threadID);
|
||||
|
||||
GetDevice()->BindResourcePS(mesh->impostorTarget.GetTexture(0), TEXSLOT_ONDEMAND0, threadID);
|
||||
if (!easyTextureBind)
|
||||
{
|
||||
@@ -3709,6 +3734,20 @@ void wiRenderer::RenderMeshes(const XMFLOAT3& eye, const CulledCollection& culle
|
||||
};
|
||||
GetDevice()->BindVertexBuffers(vbs, 0, ARRAYSIZE(vbs), strides, threadID);
|
||||
}
|
||||
else if (shaderType == SHADERTYPE_ALPHATESTONLY)
|
||||
{
|
||||
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
|
||||
{
|
||||
GPUBuffer* vbs[] = {
|
||||
|
||||
Reference in New Issue
Block a user