SlideShare a Scribd company logo
1 of 16
Depth of Field

    김정희
    최유표
Table of Contents
• DOF?

• Our DOF

• QnA
DOF
• Depth Of Field (피사계심도)
  – 렌즈로 피사체를 바라보면 그 앞/뒤에 초점이 맞는데 그 범위를
    이르는 말


• Circle Of Confusion (착란원)
  – 점모양의 물체가 초점이 맞지 않는 위치에 있으면, 이 물체는 둥
    그런 반점 모양으로 보이는데 이를 COC라고 한다.


• Focal Length (초점거리)
  – 렌즈의 초점거리.
DOF




v


      In computer graphics, we typically project onto our virtual film
      using an idealized pinhole camera that has a lens of zero size,
      so there is only a single path for light to travel from the scene
      to the film. So to achieve the depth-of-field effect, we must
      approximate the blur that would otherwise happen with a
      real lens.
                                                        – GPU Gems1
DOF
D2
• ATI Sample 참고
  – MipMap과 MSAA를 사용하여 DOF
  – 장점
    • Source가 매우 Simple!
    • MipMap 생성에 HW 및 DX API 이용
    • Blur Pass를 절약
  – 단점
    • MipMap 생성을 제어할 수 없다.
    • 이 Sample에서 쓰인 MSAA는 DX10 전용
D2
• Flow
  … 생략…
  Device.CreateTexture(width, height,
     Usage.RenderTarget | Usage.AutoGenerateMipMap,
     format,
     Pool.Default);
  … 생략


  RenderRepository.cs

  … 생략…
  PostProcessing()
     {
        … 생략…
        PostProcessing.TextureHandle.DxTexture.GenerateMipSubLevels();
     }

  BeginViewPort();
       Dof();
  EndViewPort();
D2
float4 DefaultPS( OUTPUT_VS In ) : COLOR
{
                                                                             * Uniform 상수
     float lodLevel = GetLod(In.tex);
                                                                             maxLevel = 2.5f
     float3 deferredRgb = GetLodColor(In.tex, lodLevel);
                                                                             distance = 100
     return float4(deferredRgb,1);
}

float GetLod(float2 tex)
{
      float viewZ = tex2D(depthSampler, tex).a; // MRT1번
      float blur = abs(viewZ - dofZ); // 렌더링 물체의 viewZ와 Focal Plane의 viewZ (= 카메라와 캐릭터의 거리)
      return maxLevel * saturate(blur / distance);
}

float3 GetLodColor(float2 tex, float lod)
{
      return tex2Dlod(ldSampler, float4(tex, 0, lod)).rgb; // PostProcessing, MotionBlur까지 끝낸 Texture
}
D2
• Artifact
  – MipLevel이 커질수록 Aliasing 발생
  – MipLevel이 차이나는 곳에서 Aliasing 발생


• 원인
  – MipMap에서 이미 Blurring 되었기 때문에
D2
D2



Level0                         Level1




         0   0
         1   0
                      Screen
D2
• Solution
  – MipMap을 자동생성하지 않고 깊이를 비교하
    여 생성 (귀찮음 적용하지 않음)
  – Sampling 할 때 인접 픽셀들과 평균
  – 인접픽셀은 대각선 방향의 4개 픽셀을 사용
    • Aliasing은 대각선에만 발생되기 때문에 상하좌우
      보다 대각선방향의 픽셀을 가져오는 것이 효과적
      인 것 같다!
D2
float4 DefaultPS( OUTPUT_VS In ) : COLOR
{
    float lodLevel = GetLod(In.tex);
    float3 deferredRgb = GetLodColor(In.tex, lodLevel);

    // 좌상, 우상, 우하, 좌하 + 중앙
    float p = lodLevel * 2;
    float offsetA = offsetAB.xy * p;
    float offsetB = offsetAB.zw * p;
    deferredRgb += GetLodColor(In.tex+offsetA, lodLevel);
    deferredRgb += GetLodColor(In.tex-offsetA, lodLevel);
    deferredRgb += GetLodColor(In.tex+offsetB, lodLevel);
    deferredRgb += GetLodColor(In.tex-offsetB, lodLevel);
    deferredRgb /= 5;
    return float4(deferredRgb,1);
}
D2
D2
QnA
• Future Work
  – 없어

More Related Content

What's hot

게임에서 사용할 수 있는 포물선 운동
게임에서 사용할 수 있는 포물선 운동게임에서 사용할 수 있는 포물선 운동
게임에서 사용할 수 있는 포물선 운동세민 이
 
Rendering realistic Ice objects
Rendering realistic Ice objectsRendering realistic Ice objects
Rendering realistic Ice objectsyong gyun im
 
Unity Surface Shader for Artist 02
Unity Surface Shader for Artist 02Unity Surface Shader for Artist 02
Unity Surface Shader for Artist 02SangYun Yi
 
Unity Surface Shader for Artist 04
Unity Surface Shader for Artist 04Unity Surface Shader for Artist 04
Unity Surface Shader for Artist 04SangYun Yi
 
Unity Surface Shader for Artist 03
Unity Surface Shader for Artist 03Unity Surface Shader for Artist 03
Unity Surface Shader for Artist 03SangYun Yi
 
1.4.4 입력과 출력
1.4.4 입력과 출력1.4.4 입력과 출력
1.4.4 입력과 출력Park Min Wook
 
Doing math with python.ch05
Doing math with python.ch05Doing math with python.ch05
Doing math with python.ch05Seok-joon Yun
 
Doing mathwithpython.ch02
Doing mathwithpython.ch02Doing mathwithpython.ch02
Doing mathwithpython.ch02Seok-joon Yun
 
밑바닥부터시작하는딥러닝 Ch05
밑바닥부터시작하는딥러닝 Ch05밑바닥부터시작하는딥러닝 Ch05
밑바닥부터시작하는딥러닝 Ch05HyeonSeok Choi
 
[Swift] Higher order function
[Swift] Higher order function[Swift] Higher order function
[Swift] Higher order functionBill Kim
 
Convolutional neural networks
Convolutional neural networksConvolutional neural networks
Convolutional neural networksHyunjinBae3
 
딥러닝 제대로시작하기 Ch04
딥러닝 제대로시작하기 Ch04딥러닝 제대로시작하기 Ch04
딥러닝 제대로시작하기 Ch04HyeonSeok Choi
 
[ES6] 5. Destructuring
[ES6] 5. Destructuring[ES6] 5. Destructuring
[ES6] 5. DestructuringHan JaeYeab
 
밑바닥부터시작하는딥러닝 Ch05
밑바닥부터시작하는딥러닝 Ch05밑바닥부터시작하는딥러닝 Ch05
밑바닥부터시작하는딥러닝 Ch05HyeonSeok Choi
 
Effective c++ item27
Effective c++ item27Effective c++ item27
Effective c++ item27진화 손
 

What's hot (19)

게임에서 사용할 수 있는 포물선 운동
게임에서 사용할 수 있는 포물선 운동게임에서 사용할 수 있는 포물선 운동
게임에서 사용할 수 있는 포물선 운동
 
Rendering realistic Ice objects
Rendering realistic Ice objectsRendering realistic Ice objects
Rendering realistic Ice objects
 
Unity Surface Shader for Artist 02
Unity Surface Shader for Artist 02Unity Surface Shader for Artist 02
Unity Surface Shader for Artist 02
 
Unity Surface Shader for Artist 04
Unity Surface Shader for Artist 04Unity Surface Shader for Artist 04
Unity Surface Shader for Artist 04
 
[데브루키] FOG
[데브루키] FOG[데브루키] FOG
[데브루키] FOG
 
Gan
GanGan
Gan
 
Unity Surface Shader for Artist 03
Unity Surface Shader for Artist 03Unity Surface Shader for Artist 03
Unity Surface Shader for Artist 03
 
1.4.4 입력과 출력
1.4.4 입력과 출력1.4.4 입력과 출력
1.4.4 입력과 출력
 
D2 Havok
D2 HavokD2 Havok
D2 Havok
 
Doing math with python.ch05
Doing math with python.ch05Doing math with python.ch05
Doing math with python.ch05
 
Doing mathwithpython.ch02
Doing mathwithpython.ch02Doing mathwithpython.ch02
Doing mathwithpython.ch02
 
밑바닥부터시작하는딥러닝 Ch05
밑바닥부터시작하는딥러닝 Ch05밑바닥부터시작하는딥러닝 Ch05
밑바닥부터시작하는딥러닝 Ch05
 
[Swift] Higher order function
[Swift] Higher order function[Swift] Higher order function
[Swift] Higher order function
 
Week9 quicksort
Week9 quicksortWeek9 quicksort
Week9 quicksort
 
Convolutional neural networks
Convolutional neural networksConvolutional neural networks
Convolutional neural networks
 
딥러닝 제대로시작하기 Ch04
딥러닝 제대로시작하기 Ch04딥러닝 제대로시작하기 Ch04
딥러닝 제대로시작하기 Ch04
 
[ES6] 5. Destructuring
[ES6] 5. Destructuring[ES6] 5. Destructuring
[ES6] 5. Destructuring
 
밑바닥부터시작하는딥러닝 Ch05
밑바닥부터시작하는딥러닝 Ch05밑바닥부터시작하는딥러닝 Ch05
밑바닥부터시작하는딥러닝 Ch05
 
Effective c++ item27
Effective c++ item27Effective c++ item27
Effective c++ item27
 

Viewers also liked

GPU Gems3 Vegetation
GPU Gems3 VegetationGPU Gems3 Vegetation
GPU Gems3 VegetationYoupyo Choi
 
D2 Horizon Occlusion
D2 Horizon OcclusionD2 Horizon Occlusion
D2 Horizon OcclusionYoupyo Choi
 
How to Write the Fastest JSON Parser/Writer in the World
How to Write the Fastest JSON Parser/Writer in the WorldHow to Write the Fastest JSON Parser/Writer in the World
How to Write the Fastest JSON Parser/Writer in the WorldMilo Yip
 

Viewers also liked (6)

GPU Gems3 Vegetation
GPU Gems3 VegetationGPU Gems3 Vegetation
GPU Gems3 Vegetation
 
D2 Rain (1/2)
D2 Rain (1/2)D2 Rain (1/2)
D2 Rain (1/2)
 
D2 Job Pool
D2 Job PoolD2 Job Pool
D2 Job Pool
 
D2 Horizon Occlusion
D2 Horizon OcclusionD2 Horizon Occlusion
D2 Horizon Occlusion
 
D2 Hdr
D2 HdrD2 Hdr
D2 Hdr
 
How to Write the Fastest JSON Parser/Writer in the World
How to Write the Fastest JSON Parser/Writer in the WorldHow to Write the Fastest JSON Parser/Writer in the World
How to Write the Fastest JSON Parser/Writer in the World
 

Similar to D2 Depth of field

[GPU Gems3] Chapter 28. Practical Post Process Depth Of Field
[GPU Gems3] Chapter 28. Practical Post Process Depth Of Field[GPU Gems3] Chapter 28. Practical Post Process Depth Of Field
[GPU Gems3] Chapter 28. Practical Post Process Depth Of Field종빈 오
 
[0326 박민근] deferred shading
[0326 박민근] deferred shading[0326 박민근] deferred shading
[0326 박민근] deferred shadingMinGeun Park
 
[0312 조진현] good bye dx9
[0312 조진현] good bye dx9[0312 조진현] good bye dx9
[0312 조진현] good bye dx9진현 조
 
NDC2016 프로젝트 A1의 AAA급 캐릭터 렌더링 기술
NDC2016 프로젝트 A1의 AAA급 캐릭터 렌더링 기술NDC2016 프로젝트 A1의 AAA급 캐릭터 렌더링 기술
NDC2016 프로젝트 A1의 AAA급 캐릭터 렌더링 기술Ki Hyunwoo
 
NDC11_슈퍼클래스
NDC11_슈퍼클래스NDC11_슈퍼클래스
NDC11_슈퍼클래스noerror
 
Hierachical z Map Occlusion Culling
Hierachical z Map Occlusion CullingHierachical z Map Occlusion Culling
Hierachical z Map Occlusion CullingYEONG-CHEON YOU
 
Unity Surface Shader for Artist 01
Unity Surface Shader for Artist 01Unity Surface Shader for Artist 01
Unity Surface Shader for Artist 01SangYun Yi
 
[IGC2018] 퍼니파우 최재영 - 감성을 위한 개발요소
[IGC2018] 퍼니파우 최재영 - 감성을 위한 개발요소[IGC2018] 퍼니파우 최재영 - 감성을 위한 개발요소
[IGC2018] 퍼니파우 최재영 - 감성을 위한 개발요소강 민우
 
[shaderx6] 3.7 Robust Order-Independent Transparency via Reverse Depth Peelin...
[shaderx6] 3.7 Robust Order-Independent Transparency via Reverse Depth Peelin...[shaderx6] 3.7 Robust Order-Independent Transparency via Reverse Depth Peelin...
[shaderx6] 3.7 Robust Order-Independent Transparency via Reverse Depth Peelin...종빈 오
 
Screen space reflection
Screen space reflectionScreen space reflection
Screen space reflectionBongseok Cho
 
Tips and experience of DX12 Engine development .
Tips and experience of DX12 Engine development .Tips and experience of DX12 Engine development .
Tips and experience of DX12 Engine development .YEONG-CHEON YOU
 
Ndc2010 전형규 마비노기2 캐릭터 렌더링 기술
Ndc2010 전형규   마비노기2 캐릭터 렌더링 기술Ndc2010 전형규   마비노기2 캐릭터 렌더링 기술
Ndc2010 전형규 마비노기2 캐릭터 렌더링 기술henjeon
 
SGL : 소프트웨어 3D 렌더링 엔진
SGL : 소프트웨어 3D 렌더링 엔진SGL : 소프트웨어 3D 렌더링 엔진
SGL : 소프트웨어 3D 렌더링 엔진SUNGCHEOL KIM
 
Implements Cascaded Shadow Maps with using Texture Array
Implements Cascaded Shadow Maps with using Texture ArrayImplements Cascaded Shadow Maps with using Texture Array
Implements Cascaded Shadow Maps with using Texture ArrayYEONG-CHEON YOU
 
제노블레이도 2 ray marching을사용한 구름 표현
제노블레이도 2 ray marching을사용한 구름 표현제노블레이도 2 ray marching을사용한 구름 표현
제노블레이도 2 ray marching을사용한 구름 표현민웅 이
 
[Ndc11 박민근] deferred shading
[Ndc11 박민근] deferred shading[Ndc11 박민근] deferred shading
[Ndc11 박민근] deferred shadingMinGeun Park
 
Reflective Shadow Maps
Reflective Shadow MapsReflective Shadow Maps
Reflective Shadow MapsBongseok Cho
 
Rendering realistic Ice objects
Rendering realistic Ice objectsRendering realistic Ice objects
Rendering realistic Ice objectsyong gyun im
 

Similar to D2 Depth of field (20)

[GPU Gems3] Chapter 28. Practical Post Process Depth Of Field
[GPU Gems3] Chapter 28. Practical Post Process Depth Of Field[GPU Gems3] Chapter 28. Practical Post Process Depth Of Field
[GPU Gems3] Chapter 28. Practical Post Process Depth Of Field
 
[0326 박민근] deferred shading
[0326 박민근] deferred shading[0326 박민근] deferred shading
[0326 박민근] deferred shading
 
[0312 조진현] good bye dx9
[0312 조진현] good bye dx9[0312 조진현] good bye dx9
[0312 조진현] good bye dx9
 
Volumetric Fog
Volumetric FogVolumetric Fog
Volumetric Fog
 
NDC2016 프로젝트 A1의 AAA급 캐릭터 렌더링 기술
NDC2016 프로젝트 A1의 AAA급 캐릭터 렌더링 기술NDC2016 프로젝트 A1의 AAA급 캐릭터 렌더링 기술
NDC2016 프로젝트 A1의 AAA급 캐릭터 렌더링 기술
 
NDC11_슈퍼클래스
NDC11_슈퍼클래스NDC11_슈퍼클래스
NDC11_슈퍼클래스
 
Hierachical z Map Occlusion Culling
Hierachical z Map Occlusion CullingHierachical z Map Occlusion Culling
Hierachical z Map Occlusion Culling
 
Unity Surface Shader for Artist 01
Unity Surface Shader for Artist 01Unity Surface Shader for Artist 01
Unity Surface Shader for Artist 01
 
[IGC2018] 퍼니파우 최재영 - 감성을 위한 개발요소
[IGC2018] 퍼니파우 최재영 - 감성을 위한 개발요소[IGC2018] 퍼니파우 최재영 - 감성을 위한 개발요소
[IGC2018] 퍼니파우 최재영 - 감성을 위한 개발요소
 
[shaderx6] 3.7 Robust Order-Independent Transparency via Reverse Depth Peelin...
[shaderx6] 3.7 Robust Order-Independent Transparency via Reverse Depth Peelin...[shaderx6] 3.7 Robust Order-Independent Transparency via Reverse Depth Peelin...
[shaderx6] 3.7 Robust Order-Independent Transparency via Reverse Depth Peelin...
 
Screen space reflection
Screen space reflectionScreen space reflection
Screen space reflection
 
Motion blur
Motion blurMotion blur
Motion blur
 
Tips and experience of DX12 Engine development .
Tips and experience of DX12 Engine development .Tips and experience of DX12 Engine development .
Tips and experience of DX12 Engine development .
 
Ndc2010 전형규 마비노기2 캐릭터 렌더링 기술
Ndc2010 전형규   마비노기2 캐릭터 렌더링 기술Ndc2010 전형규   마비노기2 캐릭터 렌더링 기술
Ndc2010 전형규 마비노기2 캐릭터 렌더링 기술
 
SGL : 소프트웨어 3D 렌더링 엔진
SGL : 소프트웨어 3D 렌더링 엔진SGL : 소프트웨어 3D 렌더링 엔진
SGL : 소프트웨어 3D 렌더링 엔진
 
Implements Cascaded Shadow Maps with using Texture Array
Implements Cascaded Shadow Maps with using Texture ArrayImplements Cascaded Shadow Maps with using Texture Array
Implements Cascaded Shadow Maps with using Texture Array
 
제노블레이도 2 ray marching을사용한 구름 표현
제노블레이도 2 ray marching을사용한 구름 표현제노블레이도 2 ray marching을사용한 구름 표현
제노블레이도 2 ray marching을사용한 구름 표현
 
[Ndc11 박민근] deferred shading
[Ndc11 박민근] deferred shading[Ndc11 박민근] deferred shading
[Ndc11 박민근] deferred shading
 
Reflective Shadow Maps
Reflective Shadow MapsReflective Shadow Maps
Reflective Shadow Maps
 
Rendering realistic Ice objects
Rendering realistic Ice objectsRendering realistic Ice objects
Rendering realistic Ice objects
 

D2 Depth of field

  • 1. Depth of Field 김정희 최유표
  • 2. Table of Contents • DOF? • Our DOF • QnA
  • 3. DOF • Depth Of Field (피사계심도) – 렌즈로 피사체를 바라보면 그 앞/뒤에 초점이 맞는데 그 범위를 이르는 말 • Circle Of Confusion (착란원) – 점모양의 물체가 초점이 맞지 않는 위치에 있으면, 이 물체는 둥 그런 반점 모양으로 보이는데 이를 COC라고 한다. • Focal Length (초점거리) – 렌즈의 초점거리.
  • 4. DOF v In computer graphics, we typically project onto our virtual film using an idealized pinhole camera that has a lens of zero size, so there is only a single path for light to travel from the scene to the film. So to achieve the depth-of-field effect, we must approximate the blur that would otherwise happen with a real lens. – GPU Gems1
  • 5. DOF
  • 6. D2 • ATI Sample 참고 – MipMap과 MSAA를 사용하여 DOF – 장점 • Source가 매우 Simple! • MipMap 생성에 HW 및 DX API 이용 • Blur Pass를 절약 – 단점 • MipMap 생성을 제어할 수 없다. • 이 Sample에서 쓰인 MSAA는 DX10 전용
  • 7. D2 • Flow … 생략… Device.CreateTexture(width, height, Usage.RenderTarget | Usage.AutoGenerateMipMap, format, Pool.Default); … 생략 RenderRepository.cs … 생략… PostProcessing() { … 생략… PostProcessing.TextureHandle.DxTexture.GenerateMipSubLevels(); } BeginViewPort(); Dof(); EndViewPort();
  • 8. D2 float4 DefaultPS( OUTPUT_VS In ) : COLOR { * Uniform 상수 float lodLevel = GetLod(In.tex); maxLevel = 2.5f float3 deferredRgb = GetLodColor(In.tex, lodLevel); distance = 100 return float4(deferredRgb,1); } float GetLod(float2 tex) { float viewZ = tex2D(depthSampler, tex).a; // MRT1번 float blur = abs(viewZ - dofZ); // 렌더링 물체의 viewZ와 Focal Plane의 viewZ (= 카메라와 캐릭터의 거리) return maxLevel * saturate(blur / distance); } float3 GetLodColor(float2 tex, float lod) { return tex2Dlod(ldSampler, float4(tex, 0, lod)).rgb; // PostProcessing, MotionBlur까지 끝낸 Texture }
  • 9. D2 • Artifact – MipLevel이 커질수록 Aliasing 발생 – MipLevel이 차이나는 곳에서 Aliasing 발생 • 원인 – MipMap에서 이미 Blurring 되었기 때문에
  • 10. D2
  • 11. D2 Level0 Level1 0 0 1 0 Screen
  • 12. D2 • Solution – MipMap을 자동생성하지 않고 깊이를 비교하 여 생성 (귀찮음 적용하지 않음) – Sampling 할 때 인접 픽셀들과 평균 – 인접픽셀은 대각선 방향의 4개 픽셀을 사용 • Aliasing은 대각선에만 발생되기 때문에 상하좌우 보다 대각선방향의 픽셀을 가져오는 것이 효과적 인 것 같다!
  • 13. D2 float4 DefaultPS( OUTPUT_VS In ) : COLOR { float lodLevel = GetLod(In.tex); float3 deferredRgb = GetLodColor(In.tex, lodLevel); // 좌상, 우상, 우하, 좌하 + 중앙 float p = lodLevel * 2; float offsetA = offsetAB.xy * p; float offsetB = offsetAB.zw * p; deferredRgb += GetLodColor(In.tex+offsetA, lodLevel); deferredRgb += GetLodColor(In.tex-offsetA, lodLevel); deferredRgb += GetLodColor(In.tex+offsetB, lodLevel); deferredRgb += GetLodColor(In.tex-offsetB, lodLevel); deferredRgb /= 5; return float4(deferredRgb,1); }
  • 14. D2
  • 15. D2
  • 16. QnA • Future Work – 없어