mirror of
https://mirror.ghproxy.com/https://github.com/dexyfex/CodeWalker
synced 2026-05-13 22:24:51 +08:00
Hardware MSAA support for deferred render
This commit is contained in:
@@ -392,6 +392,16 @@
|
||||
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Pixel</ShaderType>
|
||||
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">4.0</ShaderModel>
|
||||
</FxCompile>
|
||||
<FxCompile Include="DirLightPS_MS.hlsl">
|
||||
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Pixel</ShaderType>
|
||||
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|x64'">4.1</ShaderModel>
|
||||
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Pixel</ShaderType>
|
||||
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">4.1</ShaderModel>
|
||||
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Pixel</ShaderType>
|
||||
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">4.1</ShaderModel>
|
||||
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Pixel</ShaderType>
|
||||
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">4.1</ShaderModel>
|
||||
</FxCompile>
|
||||
<FxCompile Include="DirLightVS.hlsl">
|
||||
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Vertex</ShaderType>
|
||||
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|x64'">4.0</ShaderModel>
|
||||
@@ -434,6 +444,16 @@
|
||||
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Vertex</ShaderType>
|
||||
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">4.0</ShaderModel>
|
||||
</FxCompile>
|
||||
<FxCompile Include="LodLightsPS_MS.hlsl">
|
||||
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Pixel</ShaderType>
|
||||
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|x64'">4.1</ShaderModel>
|
||||
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Pixel</ShaderType>
|
||||
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">4.1</ShaderModel>
|
||||
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Pixel</ShaderType>
|
||||
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">4.1</ShaderModel>
|
||||
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Pixel</ShaderType>
|
||||
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">4.1</ShaderModel>
|
||||
</FxCompile>
|
||||
<FxCompile Include="LodLightsPS.hlsl">
|
||||
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Pixel</ShaderType>
|
||||
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|x64'">4.0</ShaderModel>
|
||||
|
||||
@@ -262,6 +262,12 @@
|
||||
<FxCompile Include="LodLightsPS.hlsl">
|
||||
<Filter>Lights</Filter>
|
||||
</FxCompile>
|
||||
<FxCompile Include="DirLightPS_MS.hlsl">
|
||||
<Filter>Lights</Filter>
|
||||
</FxCompile>
|
||||
<FxCompile Include="LodLightsPS_MS.hlsl">
|
||||
<Filter>Lights</Filter>
|
||||
</FxCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="BasicPS.hlsli">
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
#include "LightPS.hlsli"
|
||||
|
||||
|
||||
Texture2DMS<float> DepthTex : register(t0);
|
||||
Texture2DMS<float4> DiffuseTex : register(t2);
|
||||
Texture2DMS<float4> NormalTex : register(t3);
|
||||
Texture2DMS<float4> SpecularTex : register(t4);
|
||||
Texture2DMS<float4> IrradianceTex : register(t5);
|
||||
|
||||
struct VS_Output
|
||||
{
|
||||
float4 Pos : SV_POSITION;
|
||||
float4 Screen : TEXCOORD0;
|
||||
};
|
||||
|
||||
PS_OUTPUT main(VS_Output input)
|
||||
{
|
||||
|
||||
//switch (RenderMode)
|
||||
//{
|
||||
// case 5: c += diffuse.rgb; break;
|
||||
// case 6: c += normal.rgb; break;
|
||||
// case 7: c += specular.rgb; break;
|
||||
//}
|
||||
|
||||
uint2 ssloc = uint2(input.Pos.xy); //pixel location
|
||||
float2 spos = float2(input.Screen.xy / input.Screen.w);
|
||||
float3 c = 0;
|
||||
float d = 0;
|
||||
float a = 0;
|
||||
int sc = min(SampleCount, 8);
|
||||
|
||||
[unroll]
|
||||
for (int i = 0; i < sc; i++)
|
||||
{
|
||||
float depth = DepthTex.Load(ssloc, i);
|
||||
if (depth == 0) continue; //no existing subpixel rendered here
|
||||
|
||||
float4 diffuse = DiffuseTex.Load(ssloc, i);
|
||||
float4 normal = NormalTex.Load(ssloc, i);
|
||||
float4 specular = SpecularTex.Load(ssloc, i);
|
||||
float4 irradiance = IrradianceTex.Load(ssloc, i);
|
||||
|
||||
float4 cpos = mul(float4(spos, depth, 1), ViewProjInv);
|
||||
float3 camRel = cpos.xyz * (1 / cpos.w);
|
||||
float3 norm = normal.xyz * 2 - 1;
|
||||
|
||||
float3 colour = DeferredDirectionalLight(camRel, norm, diffuse, specular, irradiance);
|
||||
|
||||
c += colour;
|
||||
d += depth;
|
||||
a += 1;
|
||||
}
|
||||
|
||||
c *= SampleMult;
|
||||
d *= SampleMult;
|
||||
a *= SampleMult;
|
||||
|
||||
if (d <= 0) discard;
|
||||
|
||||
PS_OUTPUT output;
|
||||
output.Colour = float4(c, a);
|
||||
output.Depth = d;
|
||||
return output;
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ cbuffer PSLightVars : register(b0)
|
||||
uint RenderSamplerCoord;
|
||||
uint LightType; //0=directional, 1=Point, 2=Spot, 4=Capsule
|
||||
uint IsLOD; //useful or not?
|
||||
uint Pad0;
|
||||
uint Pad1;
|
||||
uint SampleCount;//for MSAA
|
||||
float SampleMult;//for MSAA
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
#include "LightPS.hlsli"
|
||||
|
||||
|
||||
Texture2DMS<float> DepthTex : register(t0);
|
||||
Texture2DMS<float4> DiffuseTex : register(t2);
|
||||
Texture2DMS<float4> NormalTex : register(t3);
|
||||
Texture2DMS<float4> SpecularTex : register(t4);
|
||||
Texture2DMS<float4> IrradianceTex : register(t5);
|
||||
|
||||
struct VS_Output
|
||||
{
|
||||
float4 Pos : SV_POSITION;
|
||||
float4 Screen : TEXCOORD0;
|
||||
uint IID : SV_INSTANCEID;
|
||||
};
|
||||
|
||||
float4 main(VS_Output input) : SV_TARGET
|
||||
{
|
||||
uint2 ssloc = uint2(input.Pos.xy); //pixel location
|
||||
float2 spos = float2(input.Screen.xy / input.Screen.w);
|
||||
float4 c = 0;
|
||||
float d = 0;
|
||||
int sc = min(SampleCount, 8);
|
||||
|
||||
[unroll]
|
||||
for (int i = 0; i < sc; i++)
|
||||
{
|
||||
float depth = DepthTex.Load(ssloc, i);
|
||||
if (depth == 0) continue; //no existing subpixel rendered here
|
||||
|
||||
float4 diffuse = DiffuseTex.Load(ssloc, i);
|
||||
float4 normal = NormalTex.Load(ssloc, i);
|
||||
float4 specular = SpecularTex.Load(ssloc, i);
|
||||
float4 irradiance = IrradianceTex.Load(ssloc, i);
|
||||
|
||||
float4 cpos = mul(float4(spos, depth, 1), ViewProjInv);
|
||||
float3 camRel = cpos.xyz * (1 / cpos.w);
|
||||
float3 norm = normal.xyz * 2 - 1;
|
||||
|
||||
float4 colour = DeferredLODLight(camRel, norm, diffuse, specular, irradiance, input.IID);
|
||||
|
||||
c += colour;
|
||||
d += depth;
|
||||
}
|
||||
|
||||
c *= SampleMult;
|
||||
d *= SampleMult;
|
||||
|
||||
if (d <= 0) discard;
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user