다양한 하드웨어에서 그림자 맵 지원
더 빠른 디바이스에서 충실도가 더 높은 섀도를 렌더링하고 덜 강력한 디바이스에서 더 빠른 섀도를 렌더링합니다. 연습: Direct3D 11에서 깊이 버퍼를 사용하여 섀도 볼륨을 구현 4부.
비교 필터 유형
디바이스에서 성능 저하를 감당할 수 있는 경우에만 선형 필터링을 사용합니다. 일반적으로 Direct3D 기능 수준 9_1 디바이스에는 그림자의 선형 필터링을 위한 전원이 부족합니다. 이러한 디바이스에서 포인트 필터링을 대신 사용합니다. 선형 필터링을 사용하는 경우 섀도 가장자리를 혼합할 수 있도록 픽셀 셰이더를 조정합니다.
포인트 필터링을 위한 비교 샘플러를 생성합니다.
D3D11_SAMPLER_DESC comparisonSamplerDesc;
ZeroMemory(&comparisonSamplerDesc, sizeof(D3D11_SAMPLER_DESC));
comparisonSamplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_BORDER;
comparisonSamplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_BORDER;
comparisonSamplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_BORDER;
comparisonSamplerDesc.BorderColor[0] = 1.0f;
comparisonSamplerDesc.BorderColor[1] = 1.0f;
comparisonSamplerDesc.BorderColor[2] = 1.0f;
comparisonSamplerDesc.BorderColor[3] = 1.0f;
comparisonSamplerDesc.MinLOD = 0.f;
comparisonSamplerDesc.MaxLOD = D3D11_FLOAT32_MAX;
comparisonSamplerDesc.MipLODBias = 0.f;
comparisonSamplerDesc.MaxAnisotropy = 0;
comparisonSamplerDesc.ComparisonFunc = D3D11_COMPARISON_LESS_EQUAL;
comparisonSamplerDesc.Filter = D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT;
// Point filtered shadows can be faster, and may be a good choice when
// rendering on hardware with lower feature levels. This sample has a
// UI option to enable/disable filtering so you can see the difference
// in quality and speed.
DX::ThrowIfFailed(
pD3DDevice->CreateSamplerState(
&comparisonSamplerDesc,
&m_comparisonSampler_point
)
);
그런 다음 선형 필터링을 위한 샘플러를 생성합니다.
comparisonSamplerDesc.Filter = D3D11_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR;
DX::ThrowIfFailed(
pD3DDevice->CreateSamplerState(
&comparisonSamplerDesc,
&m_comparisonSampler_linear
)
);
샘플러 선택:
ID3D11PixelShader* pixelShader;
ID3D11SamplerState** comparisonSampler;
if (m_useLinear)
{
pixelShader = m_shadowPixelShader_linear.Get();
comparisonSampler = m_comparisonSampler_linear.GetAddressOf();
}
else
{
pixelShader = m_shadowPixelShader_point.Get();
comparisonSampler = m_comparisonSampler_point.GetAddressOf();
}
// Attach our pixel shader.
context->PSSetShader(
pixelShader,
nullptr,
0
);
context->PSSetSamplers(0, 1, comparisonSampler);
context->PSSetShaderResources(0, 1, m_shadowResourceView.GetAddressOf());
선형 필터링을 사용하여 섀도 가장자리를 혼합합니다.
// Blends the shadow area into the lit area.
float3 light = lighting * (ambient + DplusS(N, L, NdotL, input.view));
float3 shadow = (1.0f - lighting) * ambient;
return float4(input.color * (light + shadow), 1.f);
섀도 버퍼 크기
더 큰 섀도 맵은 고르지 않아 보이지 않지만 그래픽 메모리에서 더 많은 공간을 차지합니다. 게임에서 다양한 섀도 맵 크기를 실험하고 다양한 유형의 장치와 디스플레이 크기로 결과를 관찰합니다. 더 적은 그래픽 메모리로 더 나은 결과를 얻으려면 계단식 섀도 맵과 같은 최적화를 고려합니다. 섀도 깊이 맵 개선을 위한 일반 기술을 참조하세요.
섀도 버퍼 깊이
섀도 버퍼의 정밀도가 높으면 보다 정확한 깊이 테스트 결과가 제공되므로 z 버퍼 병합과 같은 문제를 방지할 수 있습니다. 그러나 더 큰 섀도 맵과 마찬가지로 정밀도는 더 많은 메모리를 차지합니다. 게임에서 여러 깊이 정밀도 형식을 실험하고(DXGI_FORMAT_R24G8_TYPELESS 대 DXGI_FORMAT_R16_TYPELESS) 여러 기능 수준에서 속도와 품질을 확인합니다.
미리 컴파일된 셰이더 최적화
UWP(유니버설 Windows 플랫폼) 앱은 동적 셰이더 컴파일을 사용할 수 있지만 동적 셰이더 연결 사용이 더 빠릅니다. 컴파일러 지시문 및 #ifdef
블록을 사용하여 다른 버전의 셰이더를 생성할 수도 있습니다. 이 작업은 텍스트 편집기에서 Visual Studio 프로젝트 파일을 열고 HLSL에 대한 여러 <FxcCompiler>
항목(각각 적절한 전처리기 정의 포함)을 추가하여 수행됩니다. 이 작업에는 서로 다른 파일 이름이 필요하며, 이 경우 Visual Studio가 _point 및 _linear를 서로 다른 버전의 셰이더에 추가합니다.
선형 필터링된 셰이더 버전의 프로젝트 파일 항목은 LINEAR을 정의합니다.
<FxCompile Include="Content\ShadowPixelShader.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Pixel</ShaderType>
<DisableOptimizations Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">false</DisableOptimizations>
<EnableDebuggingInformation Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</EnableDebuggingInformation>
<DisableOptimizations Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</DisableOptimizations>
<DisableOptimizations Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</DisableOptimizations>
<ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">$(OutDir)%(Filename)_linear.cso</ObjectFileOutput>
<ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">$(OutDir)%(Filename)_linear.cso</ObjectFileOutput>
<ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(OutDir)%(Filename)_linear.cso</ObjectFileOutput>
<ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(OutDir)%(Filename)_linear.cso</ObjectFileOutput>
<ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(OutDir)%(Filename)_linear.cso</ObjectFileOutput>
<ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutDir)%(Filename)_linear.cso</ObjectFileOutput>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">LINEAR</PreprocessorDefinitions>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">LINEAR</PreprocessorDefinitions>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">LINEAR</PreprocessorDefinitions>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">LINEAR</PreprocessorDefinitions>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">LINEAR</PreprocessorDefinitions>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|x64'">LINEAR</PreprocessorDefinitions>
</FxCompile>
선형 필터링된 셰이더 버전에 대한 프로젝트 파일 항목에는 전처리기 정의가 포함되지 않습니다.
<FxCompile Include="Content\ShadowPixelShader.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Pixel</ShaderType>
<DisableOptimizations Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">false</DisableOptimizations>
<EnableDebuggingInformation Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</EnableDebuggingInformation>
<DisableOptimizations Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</DisableOptimizations>
<DisableOptimizations Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</DisableOptimizations>
<ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">$(OutDir)%(Filename)_point.cso</ObjectFileOutput>
<ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">$(OutDir)%(Filename)_point.cso</ObjectFileOutput>
<ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(OutDir)%(Filename)_point.cso</ObjectFileOutput>
<ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(OutDir)%(Filename)_point.cso</ObjectFileOutput>
<ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(OutDir)%(Filename)_point.cso</ObjectFileOutput>
<ObjectFileOutput Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutDir)%(Filename)_point.cso</ObjectFileOutput>
</FxCompile>
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기