際際滷

際際滷Share a Scribd company logo
Reflective Shadow Maps 1
Reflective Shadow Maps
覈谿
1. Reflective Shadow Maps 
2. 蟲 覦
3. 譴  襷 
4. 螳蟯 螻
5. 豕譬 
6.  
7. 襷豺覃
8. Reference
Reflective Shadow Maps 
Reflective Shadow Maps(危 RSMs) Shadow Maps朱 企 豢 蟆螻朱 るゴ蟆 蠏碁殊襯
蠏碁Μ   蠍磯 . RSMs 蠏碁企 螳蟯(Indirect Light) 蠏殊 覦朱 
螳朱  譟磯(Global Illumination)  螻襴讀. る 蠏 覦 譴  襷
(Standard Shadow Map, 危 SSM) ロ 覦願鍵 覓語 企 企 覿り 螳.
 蠍 RSMs襯 螳 朱(Dachsbacher04) 蠍磯朱 Direct3D 11/12襦 蟲 蟆郁骸覓殊 牛
RSMs 蠍磯蓋 蟲 覦覯 螳蟆給.
蟲 覦
RSMs れ螻 螳 襦 蟲.
1. SSM ロ れ螻 螳 覲企ゼ れ 蠍磯.
a.  譬 豺 (World Position)
b.  碁 (World Normal)
RSMs Off RSMs On
Reflective Shadow Maps 2
c. 覦 覦 (Reflected Radiant Flux)
2. 豌 覃 蠍一 螳 蠏碁Μ覃伎 伎 螻 れ 蠍磯 覲企ゼ 覦朱 螳蟯 螻
壱.
3. 讌蟯 螻壱覃伎 螳蟯 螻 蟆郁骸襯 燕 豕譬 蟆郁骸襯 螻壱.
危襦 螳 螻襯 譬  誤 危エ覲企襦 蟆給.
譴  襷 
RSMs SSM ロ 蟲蠍 覓語 轟壱蟆 SSM 蟲   . 蠍一
SSM 蟲 伎 る讌 螻 蠍一ヾ 蟲  SSM RSMs 企至 ロ讌 
覲願給. 危 螳 RSMs 覯朱れ れ螻 螳 ル伎 蠍一朱 焔給.
SSM 譟磯  覓殊牡 蟾企ゼ ロ給. RSMs 豢螳襦 3螳讌 覲企ゼ  蠍磯.
豌 覯讌碁  譬 豺 (World Position)
. 覃覈襴 曙 伎 蟾企ゼ 蠍磯伎 
 譬襯 燕  讌襷 蟲 ク煙
 RGBA_FLOAT 襷血 れ  譬襯
讌 蠍磯給.
Reflective Shadow Maps 3
 覯讌碁  碁 (World Normal). 
覲企 碁ジ 碁 襷糾骸 覘 るジ 覈旧碁
Octahedron normal vector encoding 
R10G10B10A2 襷血 れ 蠍磯蠍 覓語
.
 覯讌碁 覦 覦 (Reflected Radiant Flux)
. 覦  螳  襦
 讌襯 詩. 磯殊 覦 覦
 譟磯 覦豢 觜 讌螳 覓殊牡 覃伎
覦 れ  觜 讌襯 詩.
伎 れ 貊襯 覲企伎 螳 覲願 企至 蠍磯讌 危エ覲願給.
一 覯 一企 碁 曙 一企襦 伎 覩襦 豺襷  蠍一ヾ 貊 れ螻 螳
 碁 豢螳.
struct VS_INPUT
{
float3 position : POSITION;
#if EnableRSMs == 1
float3 normal : NORMAL;
#endif
uint primitiveId : PRIMITIVEID;
};
struct VS_OUTPUT
{
float4 position : POSITION;
Reflective Shadow Maps 4
#if EnableRSMs == 1
float3 normal : NORMAL;
#endif
};
VS_OUTPUT main( VS_INPUT input )
{
// ...
#if EnableRSMs == 1
output.normal = mul( float4( input.normal, 0.f ), transpose( primitiveData.m_invWorldMatrix ) ).xyz;
#endif
return output;
}
曙 一企 MRT(Multi Render Target)襯   3螳讌 覲企ゼ れ 蠍磯蠍  
企 覃  覦 螳 蟲譟一牡襦 襷れ 覲襯 豢螳螻  覲企ゼ 蠍磯. 覦 覦
螻一 譟磯 瑚鍵 讌 讀襯  螻燕伎 螻壱   伎 磯 豢螳 一企 襴
 覦碁 .
讌  磯殊  れ  覃螳 螳讌 讌 螳讌
蟆曙一  豕襯   蟆  蟆郁骸朱  り 覓願碓讌
  蟆 螳給.
struct PS_OUTPUT
{
float depth : SV_TARGET0;
#if EnableRSMs == 1
float3 worldPos : SV_TARGET1;
float4 packedNormal : SV_TARGET2;
float4 flux : SV_TARGET3;
#endif
};
PS_OUTPUT main( PS_INPUT input ) : SV_TARGET
{
// ...
#if EnableRSMs == 1
output.worldPos = input.worldPos;
float3 enc = SignedOctEncode( normalize( input.normal ) );
output.packedNormal = float4( 0.f, enc );
output.flux = Diffuse * GetLight( LightIdx ).m_diffuse;
#endif
return output;
}
螳蟯 螻
 螻殊  襷旧 ロ 3譬襯 れ襯 詞給. RSMs  襷旧 螳 
蟯(Point light)朱 螳譯狩.
企 蟯 Virtual Point Light(危 VPL)手 .
Reflective Shadow Maps 5
蟯 蠍郁 襷れ   鏤遂逢レ朱 覦豢 覲旧 螳(Radiant intensity) れ螻 螳給.
鏤: 蟯
鏤: 覦 覦
鏤: 碁 覯″
鏤: 伎(dot product)
磯殊 碁 覯″郁 鏤
 覃伎  鏤
  蟯 鏤
 誤 覦 譟磯(Irradiance) れ螻 螳給.
鏤: 覯″ 鏤
 蠍語
  れ螻 螳 覿襴 覲企  危危蠍  蟇磯 螳.
鏤
 蟯 鏤酔豺襦 朱襷殊 觜 覦讌襯 . 讀 覃伎 
覯 貊 覯豺(Lamberts cosine law) 磯ゴ蠍 覓語.
  蠏 覯″郁 蠍 覓語 覿覈 蠏襯  鏤
螳 .
 豌豌 危エ覲企 蟆郁記 貊語 蟲 蟆企朱 蟇   給.
w
I 
(w) =
p 陸 
max{0,n 
w}
p p
p
陸 
p
n 
p
b
n x p
E 
(x,n) =
p 陸  
p
bx  x 
b
p
4
max{0,n 
x  x 
}max{0,nx 
 x}
p p p
bvb v
E 
(x,n) =
p 陸   
p
bx  x 
b
p
max{0,n 
x  x 
}
p p
bx  x 
b
p
max{0,nx   x}
p
bx  x 
b
p
2
1

bxx 
b
p
max{0,n 
xx 
}
p p
x 
p
豢豌 : https://en.wikipedia.org/wiki/Lambert's_cosine_law
x  xp bx  x 
b
p
{   }
Reflective Shadow Maps 6
鏤
 觜 覦 覃伎  觜  . 觜 覦 覃伎 磯 覦蠍郁 
讌蠍 覓語 企ゼ 螻壱.
鏤
 蟇磯Μ 磯ジ 觜 螳襯 . 觜 蟯 覃伎襦  覃伎 覦 觜
 伎覃 企 蟇磯Μ 螻煙 覦觜襦蟆 .
蟲 蟆 願 蟇磯Μ 磯 讀螳 觜 螻壱 覲企 .
伎 覦 譟磯 螻一 伎 螳蟯 螻壱覃 .  螻殊  豺襯 蠍一朱 殊
覯襯  襷旧 襷 Dachsbacher04  襷 伎 れ螻 螳 朱 
蟆 .
鏤:  襷 れ 譬
鏤: 襷 豕 覯(0 ~ 1)
鏤: 蠏 覿襯 磯ゴ 覓伎 螳
蠏碁Μ螻 企蟆 焔  鏤衰譴豺襯 譯殊 襷 覦襯 覲伎.
蟇磯Μ螳 覃伎襦 襷 覦螳 伎蠍 覓語朱 螳.

bxx 
b
p
max{0,nx 
x}
p
豢豌 : https://www.scratchapixel.com/lessons/3d-basic-rendering/introduction-to-
shading/diffuse-lambertian-shading.html

bxx 
b
p
2
1
豢豌 : http://brabl.com/light-attenuation/
(s + r 
両 
sin(2両 
),t +
max 1 2 r 
両 
cos(2両 
))
max 1 2
s,t
r 
max
両 
,両 
1 2
両 
1
2
Reflective Shadow Maps 7
企蟆 焔 襷 伎 覈旧 れ螻 螳給.  蠍郁 螳譴豺襯 .
讌蠍蟾讌 伎手鍵 伎 れ 貊襯 牛 襴襦 蟆給.
一 襷   貊覿 覲願給.
void RSMsRenderer::CreateSamplingPattern()
{
// 豕 400螳 襷 伎 燕  給.
constexpr uint32 MaxNumSamplingPattern = 400;
uint32 numSamplingPattern = std::min( MaxNumSamplingPattern, DefaultRenderCore::RSMsNumSampling() );
// 襷 伎 伎 覯朱ゼ 燕.
agl::BufferTrait trait = {
.m_stride = sizeof( Vector ),
.m_count = numSamplingPattern,
.m_access = agl::ResourceAccessFlag::GpuRead | agl::ResourceAccessFlag::GpuWrite,
.m_bindType = agl::ResourceBindType::ShaderResource,
.m_miscFlag = agl::ResourceMisc::None,
.m_format = agl::ResourceFormat::R32G32B32_FLOAT
};
Vector samplingPattern[MaxNumSamplingPattern] = {};
std::random_device rd;
std::mt19937 mt( rd() );
// 蠏 覿襦 0 ~ 1 伎 襯 燕.
std::uniform_real_distribution<float> dis( 0, 1 );
for ( uint32 i = 0; i < numSamplingPattern; ++i )
{
float xi1 = dis( mt );
float xi2 = dis( mt );
// Equation 3.
豢豌 : Dachsbacher04
Reflective Shadow Maps 8
samplingPattern[i][0] = xi1 * std::sin( 2.f * std::numbers::pi_v<float> * xi2 );
samplingPattern[i][1] = xi1 * std::cos( 2.f * std::numbers::pi_v<float> * xi2 );
samplingPattern[i][2] = xi1; // 螳譴豺襯  xi1襯 磯 ロ 給.
}
m_samplingPattern = agl::Buffer::Create( trait, samplingPattern );
assert( m_samplingPattern != nullptr );
m_samplingPattern->Init();
// 襷 伎 螳 豕 覯襯  覯朱ゼ 牛 GPU .
RSMsConstantParameters params = {
.m_numSamplingPattern = numSamplingPattern,
.m_maxRadius = DefaultRenderCore::RSMsMaxSamplingRadius(),
};
m_constantParams.Update( params );
}
れ 螳蟯 螻 曙 一企 貊.
float4 main( PS_INPUT input ) : SV_TARGET
{
//  ろ襴 譬 曙 豺企 螻糾 豺襯 螻壱.
float viewSpaceDistance = ViewSpaceDistance.Sample( BlackBorderSampler, input.uv ).x;
float3 viewPosition = normalize( input.viewRay ) * viewSpaceDistance;
// 豺企 螻糾 豺  豺襯 螻壱.
float4 worldPosition = mul( float4( viewPosition, 1 ), InvViewMatrix );
worldPosition /= worldPosition.w;
//  ろ襴 譬 曙  襷旧 UV襯 螻壱.
int cascadeIndex = SearchCascadeIndex( viewPosition.z );
float4 shadowCoord = mul( worldPosition, ShadowViewProjection[cascadeIndex] );
float2 shadowMapUV = shadowCoord.xy / shadowCoord.w;
shadowMapUV.xy = shadowMapUV * float2( 0.5f, -0.5f ) + 0.5f;
//  ろ襴 譬 曙  碁 詞伎給.
float3 packedNormal = WorldNormal.Sample( BlackBorderSampler, input.uv ).yzw;
float3 worldNormal = SignedOctDecode( packedNormal );
// 貂れ企 螻 磯殊 襷 蟇磯Μ襯 譟一.
float cascadeScale = CascadeConstants[0].m_zFar / CascadeConstants[cascadeIndex].m_zFar;
float3 indirectLight = 0.f;
[loop]
for ( uint i = 0; i < NumSamplingPattern; ++i )
{
//  襷旧 襷 UV譬襯 螻壱.
float3 samplingOffset = SamplingPattern[i];
float3 uv = float3( shadowMapUV + MaxRadius * cascadeScale * samplingOffset.xy, cascadeIndex );
// 襷 豺  豺, 碁, 覦 覦 詞伎給.
float3 positionP = RSMsWorldPosition.SampleLevel( BlackBorderSampler, uv, 0 ).xyz;
float3 normalP = SignedOctDecode( RSMsNormal.SampleLevel( BlackBorderSampler, uv, 0 ).yzw );
float3 fluxP = RSMsFlux.SampleLevel( BlackBorderSampler, uv, 0 );
// Equation 1.
// 覦 譟磯 螻一
float3 irrandiance = fluxP * ( ( max( 0.f, dot( normalP, worldPosition - positionP ) )
* max( 0.f, dot( worldNormal, positionP - worldPosition ) ) )
/ pow( length( worldPosition - positionP ), 4 ) );
// 襷 蟇磯Μ 磯ジ 螳譴豺 覦
irrandiance *= samplingOffset.z * samplingOffset.z;
Reflective Shadow Maps 9
indirectLight += irrandiance;
}
return float4( indirectLight, 1.f );
}
企蟆 れ螻 螳 螳蟯 詞  給.
豕譬 
伎 螳蟯 螻 蟆郁骸襯 豕譬 ル伎 燕覃 .  蟲  襷朱 讌蟯 螻
 螻殊 螳蟯 燕襦 給.
float4 main( PS_INPUT input ) : SV_Target0
{
GeometryProperty geometry = (GeometryProperty)0;
geometry.worldPos = input.worldPos;
geometry.viewPos = input.viewPos;
geometry.normal = input.normal;
// 豌 覃 UV襯 螻
geometry.screenUV = ( input.projectionPos.xy / input.projectionPos.w ) * float2( 0.5f, -0.5f ) + 0.5f;
return CalcLight( geometry );
}
float4 CalcLight( GeometryProperty geometry )
{
// 讌蟯 螻 覿覿 
// 螳蟯 
#if EnableRSMs == 1
lightColor += MoveLinearSpace( Diffuse ) * IndirectIllumination.Sample( LinearSampler, geometry.screenUV );
#endif
return saturate( lightColor );
}
豕譬 蟆郁骸 ル伎 れ螻 螳給.
れ 蟆郁骸 覦蠍磯ゼ 讀螳 蟆郁骸
Reflective Shadow Maps 10
 
RSMs 觜蟲 螳 蟲朱 蠏碁伎誤 螳蟯   給. 讌襷 螳蟯 螻郁骸
讌   襷 蟆曙一 覿 螻一 企讌螻 伎 磯 蟆郁骸覓殊 伎 
 蟆曙郁 覲伎給.  蟆郁骸覓殊 詞朱る 襷 螳 企  襭螳 蠍語伎襦
焔 螳  蟆 蟯谿磯  覦煙  襴貅伎 蠍一  螳 給
. 企ゼ 願屋蠍   伎 螳蟯 螻壱螻  襷 覦 朱語 螳螻 
.
る  企 覦 蟲讌 一. RSMs 蠍一 螳 蟆 蠏語讌 螻 Light
Propagation Volume(危 LPV)企朱  るジ  GI 蠍磯  螳 豕譬朱 蟲螻 苦
 LPV願鍵 覓語   襴給. 蠏碁 れ 蠍一 螻旧 企 る LPV螳 
蟆朱 螳.
襷豺覃
譴觜 伎 蠍郁讌.
豌 貊  襷襯 谿瑚覃 .
Commits 揃 xtozero/SSR
Screen Space Reflection. Contribute to xtozero/SSR development by creating an
account on GitHub.
https://github.com/xtozero/SSR/commits/reflective_shadow_maps
Reflective Shadow Maps 11
Reference
http://www.klayge.org/material/3_12/GI/rsm.pdf : Dachsbacher04

More Related Content

Reflective Shadow Maps

  • 1. Reflective Shadow Maps 1 Reflective Shadow Maps 覈谿 1. Reflective Shadow Maps 2. 蟲 覦 3. 譴 襷 4. 螳蟯 螻 5. 豕譬 6. 7. 襷豺覃 8. Reference Reflective Shadow Maps Reflective Shadow Maps(危 RSMs) Shadow Maps朱 企 豢 蟆螻朱 るゴ蟆 蠏碁殊襯 蠏碁Μ 蠍磯 . RSMs 蠏碁企 螳蟯(Indirect Light) 蠏殊 覦朱 螳朱 譟磯(Global Illumination) 螻襴讀. る 蠏 覦 譴 襷 (Standard Shadow Map, 危 SSM) ロ 覦願鍵 覓語 企 企 覿り 螳. 蠍 RSMs襯 螳 朱(Dachsbacher04) 蠍磯朱 Direct3D 11/12襦 蟲 蟆郁骸覓殊 牛 RSMs 蠍磯蓋 蟲 覦覯 螳蟆給. 蟲 覦 RSMs れ螻 螳 襦 蟲. 1. SSM ロ れ螻 螳 覲企ゼ れ 蠍磯. a. 譬 豺 (World Position) b. 碁 (World Normal) RSMs Off RSMs On
  • 2. Reflective Shadow Maps 2 c. 覦 覦 (Reflected Radiant Flux) 2. 豌 覃 蠍一 螳 蠏碁Μ覃伎 伎 螻 れ 蠍磯 覲企ゼ 覦朱 螳蟯 螻 壱. 3. 讌蟯 螻壱覃伎 螳蟯 螻 蟆郁骸襯 燕 豕譬 蟆郁骸襯 螻壱. 危襦 螳 螻襯 譬 誤 危エ覲企襦 蟆給. 譴 襷 RSMs SSM ロ 蟲蠍 覓語 轟壱蟆 SSM 蟲 . 蠍一 SSM 蟲 伎 る讌 螻 蠍一ヾ 蟲 SSM RSMs 企至 ロ讌 覲願給. 危 螳 RSMs 覯朱れ れ螻 螳 ル伎 蠍一朱 焔給. SSM 譟磯 覓殊牡 蟾企ゼ ロ給. RSMs 豢螳襦 3螳讌 覲企ゼ 蠍磯. 豌 覯讌碁 譬 豺 (World Position) . 覃覈襴 曙 伎 蟾企ゼ 蠍磯伎 譬襯 燕 讌襷 蟲 ク煙 RGBA_FLOAT 襷血 れ 譬襯 讌 蠍磯給.
  • 3. Reflective Shadow Maps 3 覯讌碁 碁 (World Normal). 覲企 碁ジ 碁 襷糾骸 覘 るジ 覈旧碁 Octahedron normal vector encoding R10G10B10A2 襷血 れ 蠍磯蠍 覓語 . 覯讌碁 覦 覦 (Reflected Radiant Flux) . 覦 螳 襦 讌襯 詩. 磯殊 覦 覦 譟磯 覦豢 觜 讌螳 覓殊牡 覃伎 覦 れ 觜 讌襯 詩. 伎 れ 貊襯 覲企伎 螳 覲願 企至 蠍磯讌 危エ覲願給. 一 覯 一企 碁 曙 一企襦 伎 覩襦 豺襷 蠍一ヾ 貊 れ螻 螳 碁 豢螳. struct VS_INPUT { float3 position : POSITION; #if EnableRSMs == 1 float3 normal : NORMAL; #endif uint primitiveId : PRIMITIVEID; }; struct VS_OUTPUT { float4 position : POSITION;
  • 4. Reflective Shadow Maps 4 #if EnableRSMs == 1 float3 normal : NORMAL; #endif }; VS_OUTPUT main( VS_INPUT input ) { // ... #if EnableRSMs == 1 output.normal = mul( float4( input.normal, 0.f ), transpose( primitiveData.m_invWorldMatrix ) ).xyz; #endif return output; } 曙 一企 MRT(Multi Render Target)襯 3螳讌 覲企ゼ れ 蠍磯蠍 企 覃 覦 螳 蟲譟一牡襦 襷れ 覲襯 豢螳螻 覲企ゼ 蠍磯. 覦 覦 螻一 譟磯 瑚鍵 讌 讀襯 螻燕伎 螻壱 伎 磯 豢螳 一企 襴 覦碁 . 讌 磯殊 れ 覃螳 螳讌 讌 螳讌 蟆曙一 豕襯 蟆 蟆郁骸朱 り 覓願碓讌 蟆 螳給. struct PS_OUTPUT { float depth : SV_TARGET0; #if EnableRSMs == 1 float3 worldPos : SV_TARGET1; float4 packedNormal : SV_TARGET2; float4 flux : SV_TARGET3; #endif }; PS_OUTPUT main( PS_INPUT input ) : SV_TARGET { // ... #if EnableRSMs == 1 output.worldPos = input.worldPos; float3 enc = SignedOctEncode( normalize( input.normal ) ); output.packedNormal = float4( 0.f, enc ); output.flux = Diffuse * GetLight( LightIdx ).m_diffuse; #endif return output; } 螳蟯 螻 螻殊 襷旧 ロ 3譬襯 れ襯 詞給. RSMs 襷旧 螳 蟯(Point light)朱 螳譯狩. 企 蟯 Virtual Point Light(危 VPL)手 .
  • 5. Reflective Shadow Maps 5 蟯 蠍郁 襷れ 鏤遂逢レ朱 覦豢 覲旧 螳(Radiant intensity) れ螻 螳給. 鏤: 蟯 鏤: 覦 覦 鏤: 碁 覯″ 鏤: 伎(dot product) 磯殊 碁 覯″郁 鏤 覃伎 鏤 蟯 鏤 誤 覦 譟磯(Irradiance) れ螻 螳給. 鏤: 覯″ 鏤 蠍語 れ螻 螳 覿襴 覲企 危危蠍 蟇磯 螳. 鏤 蟯 鏤酔豺襦 朱襷殊 觜 覦讌襯 . 讀 覃伎 覯 貊 覯豺(Lamberts cosine law) 磯ゴ蠍 覓語. 蠏 覯″郁 蠍 覓語 覿覈 蠏襯 鏤 螳 . 豌豌 危エ覲企 蟆郁記 貊語 蟲 蟆企朱 蟇 給. w I (w) = p 陸 max{0,n w} p p p 陸 p n p b n x p E (x,n) = p 陸 p bx x b p 4 max{0,n x x }max{0,nx x} p p p bvb v E (x,n) = p 陸 p bx x b p max{0,n x x } p p bx x b p max{0,nx x} p bx x b p 2 1 bxx b p max{0,n xx } p p x p 豢豌 : https://en.wikipedia.org/wiki/Lambert's_cosine_law x xp bx x b p { }
  • 6. Reflective Shadow Maps 6 鏤 觜 覦 覃伎 觜 . 觜 覦 覃伎 磯 覦蠍郁 讌蠍 覓語 企ゼ 螻壱. 鏤 蟇磯Μ 磯ジ 觜 螳襯 . 觜 蟯 覃伎襦 覃伎 覦 觜 伎覃 企 蟇磯Μ 螻煙 覦觜襦蟆 . 蟲 蟆 願 蟇磯Μ 磯 讀螳 觜 螻壱 覲企 . 伎 覦 譟磯 螻一 伎 螳蟯 螻壱覃 . 螻殊 豺襯 蠍一朱 殊 覯襯 襷旧 襷 Dachsbacher04 襷 伎 れ螻 螳 朱 蟆 . 鏤: 襷 れ 譬 鏤: 襷 豕 覯(0 ~ 1) 鏤: 蠏 覿襯 磯ゴ 覓伎 螳 蠏碁Μ螻 企蟆 焔 鏤衰譴豺襯 譯殊 襷 覦襯 覲伎. 蟇磯Μ螳 覃伎襦 襷 覦螳 伎蠍 覓語朱 螳. bxx b p max{0,nx x} p 豢豌 : https://www.scratchapixel.com/lessons/3d-basic-rendering/introduction-to- shading/diffuse-lambertian-shading.html bxx b p 2 1 豢豌 : http://brabl.com/light-attenuation/ (s + r 両 sin(2両 ),t + max 1 2 r 両 cos(2両 )) max 1 2 s,t r max 両 ,両 1 2 両 1 2
  • 7. Reflective Shadow Maps 7 企蟆 焔 襷 伎 覈旧 れ螻 螳給. 蠍郁 螳譴豺襯 . 讌蠍蟾讌 伎手鍵 伎 れ 貊襯 牛 襴襦 蟆給. 一 襷 貊覿 覲願給. void RSMsRenderer::CreateSamplingPattern() { // 豕 400螳 襷 伎 燕 給. constexpr uint32 MaxNumSamplingPattern = 400; uint32 numSamplingPattern = std::min( MaxNumSamplingPattern, DefaultRenderCore::RSMsNumSampling() ); // 襷 伎 伎 覯朱ゼ 燕. agl::BufferTrait trait = { .m_stride = sizeof( Vector ), .m_count = numSamplingPattern, .m_access = agl::ResourceAccessFlag::GpuRead | agl::ResourceAccessFlag::GpuWrite, .m_bindType = agl::ResourceBindType::ShaderResource, .m_miscFlag = agl::ResourceMisc::None, .m_format = agl::ResourceFormat::R32G32B32_FLOAT }; Vector samplingPattern[MaxNumSamplingPattern] = {}; std::random_device rd; std::mt19937 mt( rd() ); // 蠏 覿襦 0 ~ 1 伎 襯 燕. std::uniform_real_distribution<float> dis( 0, 1 ); for ( uint32 i = 0; i < numSamplingPattern; ++i ) { float xi1 = dis( mt ); float xi2 = dis( mt ); // Equation 3. 豢豌 : Dachsbacher04
  • 8. Reflective Shadow Maps 8 samplingPattern[i][0] = xi1 * std::sin( 2.f * std::numbers::pi_v<float> * xi2 ); samplingPattern[i][1] = xi1 * std::cos( 2.f * std::numbers::pi_v<float> * xi2 ); samplingPattern[i][2] = xi1; // 螳譴豺襯 xi1襯 磯 ロ 給. } m_samplingPattern = agl::Buffer::Create( trait, samplingPattern ); assert( m_samplingPattern != nullptr ); m_samplingPattern->Init(); // 襷 伎 螳 豕 覯襯 覯朱ゼ 牛 GPU . RSMsConstantParameters params = { .m_numSamplingPattern = numSamplingPattern, .m_maxRadius = DefaultRenderCore::RSMsMaxSamplingRadius(), }; m_constantParams.Update( params ); } れ 螳蟯 螻 曙 一企 貊. float4 main( PS_INPUT input ) : SV_TARGET { // ろ襴 譬 曙 豺企 螻糾 豺襯 螻壱. float viewSpaceDistance = ViewSpaceDistance.Sample( BlackBorderSampler, input.uv ).x; float3 viewPosition = normalize( input.viewRay ) * viewSpaceDistance; // 豺企 螻糾 豺 豺襯 螻壱. float4 worldPosition = mul( float4( viewPosition, 1 ), InvViewMatrix ); worldPosition /= worldPosition.w; // ろ襴 譬 曙 襷旧 UV襯 螻壱. int cascadeIndex = SearchCascadeIndex( viewPosition.z ); float4 shadowCoord = mul( worldPosition, ShadowViewProjection[cascadeIndex] ); float2 shadowMapUV = shadowCoord.xy / shadowCoord.w; shadowMapUV.xy = shadowMapUV * float2( 0.5f, -0.5f ) + 0.5f; // ろ襴 譬 曙 碁 詞伎給. float3 packedNormal = WorldNormal.Sample( BlackBorderSampler, input.uv ).yzw; float3 worldNormal = SignedOctDecode( packedNormal ); // 貂れ企 螻 磯殊 襷 蟇磯Μ襯 譟一. float cascadeScale = CascadeConstants[0].m_zFar / CascadeConstants[cascadeIndex].m_zFar; float3 indirectLight = 0.f; [loop] for ( uint i = 0; i < NumSamplingPattern; ++i ) { // 襷旧 襷 UV譬襯 螻壱. float3 samplingOffset = SamplingPattern[i]; float3 uv = float3( shadowMapUV + MaxRadius * cascadeScale * samplingOffset.xy, cascadeIndex ); // 襷 豺 豺, 碁, 覦 覦 詞伎給. float3 positionP = RSMsWorldPosition.SampleLevel( BlackBorderSampler, uv, 0 ).xyz; float3 normalP = SignedOctDecode( RSMsNormal.SampleLevel( BlackBorderSampler, uv, 0 ).yzw ); float3 fluxP = RSMsFlux.SampleLevel( BlackBorderSampler, uv, 0 ); // Equation 1. // 覦 譟磯 螻一 float3 irrandiance = fluxP * ( ( max( 0.f, dot( normalP, worldPosition - positionP ) ) * max( 0.f, dot( worldNormal, positionP - worldPosition ) ) ) / pow( length( worldPosition - positionP ), 4 ) ); // 襷 蟇磯Μ 磯ジ 螳譴豺 覦 irrandiance *= samplingOffset.z * samplingOffset.z;
  • 9. Reflective Shadow Maps 9 indirectLight += irrandiance; } return float4( indirectLight, 1.f ); } 企蟆 れ螻 螳 螳蟯 詞 給. 豕譬 伎 螳蟯 螻 蟆郁骸襯 豕譬 ル伎 燕覃 . 蟲 襷朱 讌蟯 螻 螻殊 螳蟯 燕襦 給. float4 main( PS_INPUT input ) : SV_Target0 { GeometryProperty geometry = (GeometryProperty)0; geometry.worldPos = input.worldPos; geometry.viewPos = input.viewPos; geometry.normal = input.normal; // 豌 覃 UV襯 螻 geometry.screenUV = ( input.projectionPos.xy / input.projectionPos.w ) * float2( 0.5f, -0.5f ) + 0.5f; return CalcLight( geometry ); } float4 CalcLight( GeometryProperty geometry ) { // 讌蟯 螻 覿覿 // 螳蟯 #if EnableRSMs == 1 lightColor += MoveLinearSpace( Diffuse ) * IndirectIllumination.Sample( LinearSampler, geometry.screenUV ); #endif return saturate( lightColor ); } 豕譬 蟆郁骸 ル伎 れ螻 螳給. れ 蟆郁骸 覦蠍磯ゼ 讀螳 蟆郁骸
  • 10. Reflective Shadow Maps 10 RSMs 觜蟲 螳 蟲朱 蠏碁伎誤 螳蟯 給. 讌襷 螳蟯 螻郁骸 讌 襷 蟆曙一 覿 螻一 企讌螻 伎 磯 蟆郁骸覓殊 伎 蟆曙郁 覲伎給. 蟆郁骸覓殊 詞朱る 襷 螳 企 襭螳 蠍語伎襦 焔 螳 蟆 蟯谿磯 覦煙 襴貅伎 蠍一 螳 給 . 企ゼ 願屋蠍 伎 螳蟯 螻壱螻 襷 覦 朱語 螳螻 . る 企 覦 蟲讌 一. RSMs 蠍一 螳 蟆 蠏語讌 螻 Light Propagation Volume(危 LPV)企朱 るジ GI 蠍磯 螳 豕譬朱 蟲螻 苦 LPV願鍵 覓語 襴給. 蠏碁 れ 蠍一 螻旧 企 る LPV螳 蟆朱 螳. 襷豺覃 譴觜 伎 蠍郁讌. 豌 貊 襷襯 谿瑚覃 . Commits 揃 xtozero/SSR Screen Space Reflection. Contribute to xtozero/SSR development by creating an account on GitHub. https://github.com/xtozero/SSR/commits/reflective_shadow_maps
  • 11. Reflective Shadow Maps 11 Reference http://www.klayge.org/material/3_12/GI/rsm.pdf : Dachsbacher04