[ShaderX5] 8 1 Postprocessing Effects In Design

904 views
840 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
904
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
8
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

[ShaderX5] 8 1 Postprocessing Effects In Design

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

×