Implement movie rendering & fix some validation errors.

This commit is contained in:
Skyth
2024-10-20 18:47:26 +03:00
parent 4ee432d759
commit 66c20e73c9
15 changed files with 458 additions and 139 deletions
@@ -0,0 +1,51 @@
#include "../../../thirdparty/ShaderRecomp/ShaderRecomp/shader_common.hlsli"
CONSTANT_BUFFER(VertexShaderConstants, b0)
{
[[vk::offset(2880)]] float4 g_ViewportSize PACK_OFFSET(c180);
};
CONSTANT_BUFFER(PixelShaderConstants, b1)
{
[[vk::offset(0)]] float fZmin PACK_OFFSET(c0);
[[vk::offset(4)]] float fZmax PACK_OFFSET(c1);
};
CONSTANT_BUFFER(SharedConstants, b2)
{
[[vk::offset(0)]] uint Tex0_ResourceDescriptorIndex PACK_OFFSET(c0.x);
[[vk::offset(4)]] uint Tex1_ResourceDescriptorIndex PACK_OFFSET(c0.y);
[[vk::offset(8)]] uint Tex2_ResourceDescriptorIndex PACK_OFFSET(c0.z);
[[vk::offset(12)]] uint Tex3_ResourceDescriptorIndex PACK_OFFSET(c0.w);
[[vk::offset(16)]] uint Tex4_ResourceDescriptorIndex PACK_OFFSET(c1.x);
[[vk::offset(64)]] uint Tex0_SamplerDescriptorIndex PACK_OFFSET(c4.x);
[[vk::offset(68)]] uint Tex1_SamplerDescriptorIndex PACK_OFFSET(c4.y);
[[vk::offset(72)]] uint Tex2_SamplerDescriptorIndex PACK_OFFSET(c4.z);
[[vk::offset(76)]] uint Tex3_SamplerDescriptorIndex PACK_OFFSET(c4.w);
[[vk::offset(80)]] uint Tex4_SamplerDescriptorIndex PACK_OFFSET(c5.x);
SHARED_CONSTANTS;
};
#define bCsc (GET_SHARED_CONSTANT(g_Booleans) & (1 << (16 + 0)))
#define bAmv (GET_SHARED_CONSTANT(g_Booleans) & (1 << (16 + 1)))
#define bZmv (GET_SHARED_CONSTANT(g_Booleans) & (1 << (16 + 2)))
struct VertexShaderInput
{
[[vk::location(0)]] float4 ObjPos : POSITION;
[[vk::location(4)]] float2 UV : TEXCOORD;
};
struct Interpolators
{
float4 ProjPos : SV_Position;
float2 UV : TEXCOORD0;
};
struct PixelShaderOutput
{
float4 Color : SV_Target0;
float Depth : SV_Depth;
};
+102
View File
@@ -0,0 +1,102 @@
#include "movie_common.hlsl"
PixelShaderOutput main(in Interpolators In)
{
#ifdef __spirv__
PixelShaderConstants constants = vk::RawBufferLoad<PixelShaderConstants>(g_PushConstants.PixelShaderConstants, 0x100);
SharedConstants sharedConstants = vk::RawBufferLoad<SharedConstants>(g_PushConstants.SharedConstants, 0x100);
#endif
Texture2D<float4> Tex0 = g_Texture2DDescriptorHeap[GET_SHARED_CONSTANT(Tex0_ResourceDescriptorIndex)];
Texture2D<float4> Tex1 = g_Texture2DDescriptorHeap[GET_SHARED_CONSTANT(Tex1_ResourceDescriptorIndex)];
Texture2D<float4> Tex2 = g_Texture2DDescriptorHeap[GET_SHARED_CONSTANT(Tex2_ResourceDescriptorIndex)];
Texture2D<float4> Tex3 = g_Texture2DDescriptorHeap[GET_SHARED_CONSTANT(Tex3_ResourceDescriptorIndex)];
Texture2D<float4> Tex4 = g_Texture2DDescriptorHeap[GET_SHARED_CONSTANT(Tex4_ResourceDescriptorIndex)];
SamplerState Tex0_s = g_SamplerDescriptorHeap[GET_SHARED_CONSTANT(Tex0_SamplerDescriptorIndex)];
SamplerState Tex1_s = g_SamplerDescriptorHeap[GET_SHARED_CONSTANT(Tex1_SamplerDescriptorIndex)];
SamplerState Tex2_s = g_SamplerDescriptorHeap[GET_SHARED_CONSTANT(Tex2_SamplerDescriptorIndex)];
SamplerState Tex3_s = g_SamplerDescriptorHeap[GET_SHARED_CONSTANT(Tex3_SamplerDescriptorIndex)];
SamplerState Tex4_s = g_SamplerDescriptorHeap[GET_SHARED_CONSTANT(Tex4_SamplerDescriptorIndex)];
PixelShaderOutput Out;
float ValY = Tex0.Sample(Tex0_s, In.UV).r;
float ValU = Tex1.Sample(Tex1_s, In.UV).r - 0.5;
float ValV = Tex2.Sample(Tex2_s, In.UV).r - 0.5;
float ValA = 1.0;
float ValD = 0.0;
if (bAmv)
ValA = (Tex3.Sample(Tex3_s, In.UV).r - 0.0625) * 1.164;
if (bZmv)
{
ValD = (Tex4.Sample(Tex4_s, In.UV).r - 0.0625) * 1.164;
if (ValD < 9.0 / 255.0)
{
ValD = 0.0;
}
else if (ValD < 17.0 / 255.0)
{
ValD = GET_CONSTANT(fZmin);
}
else if (ValD < 224.0 / 255.0)
{
ValD = (ValD - 17.0 / 255.0) / (223.0 / 255.0 - 17.0 / 255.0) * (GET_CONSTANT(fZmax) - GET_CONSTANT(fZmin)) + GET_CONSTANT(fZmin);
}
else if (ValD < 240.0 / 255.0)
{
ValD = GET_CONSTANT(fZmax);
}
else
{
ValD = 1.0;
}
}
if (bCsc)
{
if (ValY < 16.0 / 255.0)
{
ValY = ValY * 3.0 / 2.0;
}
else if (ValY < 176.0 / 255.0)
{
ValY = 24.0 / 255.0 + (ValY - 16.0 / 255.0) / 2.0;
}
else if (ValY < 192.0 / 255.0)
{
ValY = 104.0 / 255.0 + (ValY - 176.0 / 255.0) / 1.0;
}
else
{
ValY = 120.0 / 255.0 + (ValY - 192.0 / 255.0) * 2.0;
}
if (abs(ValU) < 24.0 / 255.0)
{
ValU /= 3.0;
}
else
{
ValU = (8.0 / 255.0 + (abs(ValU) - 24.0 / 255.0) * (120.0 / 104.0)) * sign(ValU);
}
if (abs(ValV) < 24.0 / 255.0)
{
ValV /= 3.0;
}
else
{
ValV = (8.0 / 255.0 + (abs(ValV) - 24.0 / 255.0) * (120.0 / 104.0)) * sign(ValV);
}
Out.Color.r = ValY + ValV * 1.402;
Out.Color.g = ValY - ValU * 0.344 - ValV * 0.714;
Out.Color.b = ValY + ValU * 1.772;
}
else
{
ValY = (ValY - 0.0625) * 1.164;
Out.Color.r = ValY + ValV * 1.596;
Out.Color.g = ValY - ValU * 0.392 - ValV * 0.813;
Out.Color.b = ValY + ValU * 2.017;
}
Out.Color.a = ValA;
Out.Depth = ValD;
return Out;
}
+14
View File
@@ -0,0 +1,14 @@
#include "movie_common.hlsl"
Interpolators main(in VertexShaderInput In)
{
#ifdef __spirv__
VertexShaderConstants constants = vk::RawBufferLoad<VertexShaderConstants>(g_PushConstants.VertexShaderConstants, 0x100);
#endif
Interpolators Out;
Out.ProjPos = In.ObjPos;
Out.ProjPos.xy += float2(GET_CONSTANT(g_ViewportSize).z, -GET_CONSTANT(g_ViewportSize).w);
Out.UV = In.UV;
return Out;
}