1. ShaderX5
8.1 Postprocessing Effects
in Design
http://ohyecloudy.com
http://cafe.naver.com/shader.cafe
2009.02.23
2. Introduction
• 사용하는 Post-processing Effect가 증가.
– Color correction, depth-of-field, motion blur,
night vision, HDR tone mapping…
• 확장이 쉽고 다양한 요구 사항에 유연하게
적응 가능한 framework를 제시.
3. The Goals
• Stability
– 믿을 수 있고 일관된 결과.
• Robustness
– 다른 시나리오와 이펙트에서 stability 보장.
• Extensibility
– 이펙트 추가가 손쉬움.
• Performance
– 가능한 최적, 효율적으로 동작.
• Flexibility
– 풍부한 제어가 가능.
• Scalability
– 지원하는 플랫폼에서 잠재적인 제한이 있더라도 잘 동작한다.
– 예) 비디오 카드에 따라 다른 구성
5. HDR
Downsample Calculate Generate Bloom Tone-map and
scene texture luminance bright-pass bright-pass final composite
Set Set Set Set Set
RenderTarget RenderTarget RenderTarget RenderTarget RenderTarget
Draw Draw Draw Draw Draw
Overlay Overlay Overlay Overlay Overlay
Set
RenderTarget
Draw
Overlay
Set
RenderTarget
Draw
Overlay
6. A Short Test Drive
<Effect Name="SepiaTone" Requirements="DX9“
Description="Output a Sepia-toned image.">
<Phase Description="">
<Step Type="SetRenderTarget" Target="*CompositeOut" />
<Step Type="Overlay" ShaderTechnique="RenderSepiaTone">
<Texture Name="*CompositeIn" Alias="g_Texture"/>
<Texture Name="Media/sepiatone.tga"
Alias="g_DependantReadTexture" Type="File"/>
<Param Name="Amout" Alias="g_fBlendAmout"
Function="FadeIn"/>
</Step>
<Step Type="SetRenderTarget" Target="*Framebuffer"/>
</Phase>
</Effect>
7. A Short Test Drive
<Effect Name = "Output" Requirements = "DX9"
Description = "Output the final results to the screen.">
<Phase Description = "">
<Step Type = "SetRenderTarget" Target ="*Framebuffer" />
<Step Type = "Overlay" ShaderTechnique = "RenderScreenQuad">
<Texture Name = "*CompositeIn" Alias = "g_Texture" />
</Step>
</Phase>
</Effect>
8. Implementation Issue
Night
HDR Sepia Output
Vision
INPUT A B A B
OUTPUT B A B A
Disable Wrong!
10. class CPostProcessEffect
{
protected:
// The list of effects phases.
vector< CPostProcessEffectPhase * > m_Phases;
// The list of user created render targets.
vector< CRTTexture * > m_UserRenderTargets;
// The effect file name.
char *m_strFileName;
// The effect name.
char *m_strEffectName;
// The next effect in the linked-list.
CPostProcessEffect *m_pNext;
// Whether this effect is enabled or not.
bool m_bIsEnabled;
// The current texture input/output group.
CPostProcessTextureIoGroup *m_pCurIoGroup;
// The original texture input/output group.
CPostProcessTextureIoGroup m_OrigIoGroup;
};
11. void CPostProcessEffect::Enable( bool bEnable )
// If we're disabling the effect.
if ( !bEnable )
{
CPostProcessEffect *pCurEffect = GetNext();
CPostProcessTextureIoGroup *pCurIoGroup = NULL;
CPostProcessTextureIoGroup *pPrevIoGroup = GetCurIoGroup();
// For every active effect after this effect,
// move the io groups forward to maintain
// the proper texture io group mappings.
for ( ; pCurEffect; pCurEffect = pCurEffect->GetNext() )
{
if ( !pCurEffect->GetIsEnabled() )
{
continue;
}
// Get the current io group.
pCurIoGroup = pCurEffect->GetCurIoGroup();
// Set the current io group and fixup texture pointers.
pCurEffect->SetCurIoGroup( pPrevIoGroup );
pCurEffect->FixupTexturePointers();
// Update the previous io group.
pPrevIoGroup = pCurIoGroup;
}
}
12. void CPostProcessEffect::Enable( bool bEnable )
if ( bEnable )
{
CPostProcessEffect *pCurEffect = CPostProcessEffectsSystem::m_pInstance->GetEffectsHead();
CPostProcessEffect *pNxtActiveEffectHead = pCurEffect;
CPostProcessEffect *pNxtActiveEffect = NULL;
// To enable the effect we need to traverse the entire effect list twice,
// once moving forward through each original io groups, and second finding
// the next active effect that we can give that io group to.
for ( ; pCurEffect; pCurEffect = pCurEffect->GetNext() )
{
// Where there are no more active effects we're done.
if ( !pNxtActiveEffect )
{
break;
}
// Set the next active effects
pNxtActiveEffect->SetCurIoGroup(
(CPostProcessTextureIoGroup *)&pCurEffect->GetOrigIoGroup() );
pNxtActiveEffect->FixupTexturePointers();
}
} // if ( bEnable )
15. Conclusion
• Post processing effects는 텍스쳐를 바꾸어
가며 SetRenderTarget을 한다.
– 이 짓의 연속.
• 이 섹션에서 제시하는 Framework에서 확
장성있고 변화에 유연한 Post processing
effect 엔진 구현에 대한 힌트를 얻을 수 있
다.