20
Spherical Harmonic Lighting: The Gritty Details(1/3) Shader Study 임임임 임임 08/04/15

Spherical Harmonic Lighting: The Gritty Details(1/3)

  • Upload
    kirra

  • View
    61

  • Download
    5

Embed Size (px)

DESCRIPTION

Spherical Harmonic Lighting: The Gritty Details(1/3). Shader Study 임정환 발표 08/04/15. 발표를 하게된 이유. ShaderX4 2.9 Dynamical global illuminations using Tetrahedron environment mapping  모름 PRT -> 모름 BRDF -> 모름 안에 사용된 SH -> 모름 OTL 걍 처음부터 …. Introduction. - PowerPoint PPT Presentation

Citation preview

Page 1: Spherical Harmonic Lighting: The Gritty Details(1/3)

Spherical Harmonic Lighting:

The Gritty Details(1/3)Shader Study

임정환발표 08/04/15

Page 2: Spherical Harmonic Lighting: The Gritty Details(1/3)

발표를 하게된 이유

• ShaderX4 2.9 Dynamical global illuminations using Tetrahedron environment mapping 모름

• PRT -> 모름• BRDF -> 모름• 안에 사용된 SH -> 모름• OTL• 걍 처음부터…

Page 3: Spherical Harmonic Lighting: The Gritty Details(1/3)

Introduction

• Precomputed Radiance Transfer for Real-Time Rendering. in Dynamic, Slon(02) – Realtime Global Illumination 의 한 획을 그은 역사적인 논문

• 문제는 ?– 어렵다 .– 복잡하다 .– 넘 많은 기초지식을 요해 ..– OTL

• 해서 우리의 Robin Green 께서 Spherical Harmonic Lighting:The Gritty Details 이라는 논문을 내셨다 !! – 해도 넘 어렵더라– 공업수학 내용 나오고 , 돌아버림

Page 4: Spherical Harmonic Lighting: The Gritty Details(1/3)

Introduction

• 발표순서는– 1 페이지부터 순서대로 ..– 모두 이해되면 다시한번 (No 순서대로 )

Page 5: Spherical Harmonic Lighting: The Gritty Details(1/3)

Illumination Calculations(2~3쪽 )

• Diffuse Surface Reflection

• The Rendering Equation, differential angle form

Page 6: Spherical Harmonic Lighting: The Gritty Details(1/3)

Illumination Calculations(4쪽 )

• 용어들– Flux = joules/second (watt)

• 얼마나 많은 photon 이 unit 시간당 면에 부딪히는가 ?• 면이 넓으면 값이 커짐

– Irradiance( 조사 ) = watt/meter2

– Projected Solid Angle 을 통해 들어오는 빛들을 구면전체로 적분을 하면 빛의 밝기가 결정된다…

• 어떻게 위의 수식들을 리얼타임으로 표현할 것인가 ?

Page 7: Spherical Harmonic Lighting: The Gritty Details(1/3)

Monte Carlo Integration(4쪽 )

• 어떻게 적분할 것인가 ?– 몬테카를로 !!

• 몬테카를로는 Probability( 확률 ) 에 기반한 방법• f(x) 는 일반적인 함수• P(x) 는 cummulative distribution function( 축적된

배분함수 )– F(x) 의 각 부분에 대해서 얼마나 자주 불릴 것인가에

대한 확률을 나타내는 확률함수– 예제 : 주사위 (1~6) 를 굴렸을때 4 이하일 P(4) 는 2/

3– 만약 모든 범위에서 확률이 같다면 uniform random va

riable 이라 한다 .

Page 8: Spherical Harmonic Lighting: The Gritty Details(1/3)

Monte Carlo Integration(5쪽 )

• Probability density function– p(x)

– x 가 a 와 b 사이의 값일 확률

– 평균값 ( 기대값 )– 예제 f(x)=2-x 라는 함수에서 0~2 사이의 값의 기대값 ( 평균 ) 을

구하라 ..– 확률이 uniform random variable 이므로 p(x)=1/2

Page 9: Spherical Harmonic Lighting: The Gritty Details(1/3)

Monte Carlo Integration(6쪽 )

• 위의 방법은 적분해서 기대값을 구하는 방법… 허나 컴퓨터에서 하기에는 무리

• 또다른 방법은 ?– 열나게 샘플링해서 평균내기 !

• 이제 f(x) 를 적분해 보자 .

1. f(x) 를 아주 많이 sample 하의 값을 얻고2. PDF 값 ( p(x) ) 로 scaling 한후3. 결과값들을 합한후에4. sample 수로 나누면 f(x) 의 적분값을 구할 수 있다 .

– sampling 을 많이 할수록 정확한 값을 구할 수 있다– p(x)=f(x) 다면 한번만 샘플링해도 된다 .

Page 10: Spherical Harmonic Lighting: The Gritty Details(1/3)

Monte Carlo Integration(6쪽 )

• 위의 식의 또다른 표현법은

• 자 .. 그러면 우리가 할일– p(x) 를 uniform 하게 분포시켜주면 최대한 적게

샘플링하더라도 f(x) 의 적분값을 approximate 할 수 있는 것이다 .

– 구의 표면에서 우리는 적분을 할 것이므로 최대한 고르게 sample 을 분산시켜주는 것이 목표

– 이것을 unbiased random samples 이라 한다 .– 구에서는 한쌍의 independent canonical random num

ber ξx 와 ξy 값을 구한후 값을 바꾸어 구상에서 맵핑값으로 사용할 수 있다 .

– Mapping [0..1,0..1] random numbers into spherical coordinates.

Page 11: Spherical Harmonic Lighting: The Gritty Details(1/3)

Monte Carlo Integration(7쪽 )

• 자 .. 좀 더샘플링값을 낮추어 보자• jittered sample

– stratified sampling( 층을 나누는 샘플링 )1. N*N 의 cell 로 나누고 2. 각 cell 마다 random point 를 뽑자 .

– 각셀의 편차의 합은 전체 범위에서 샘플했을때보다 크지않더라 .. 즉 고르게 되더라 ..

Page 12: Spherical Harmonic Lighting: The Gritty Details(1/3)

Monte Carlo Integration(7쪽 )• 지금까지 결과를 코드로 정리해보자 .

void SH_setup_spherical_samples(SHSample samples[], int sqrt_n_samples){

// fill an N*N*2 array with uniformly distributed// samples across the sphere using jittered stratificationint i=0; // array indexdouble oneoverN = 1.0/sqrt_n_samples;for(int a=0; a<sqrt_n_samples; a++) {

for(int b=0; b<sqrt_n_samples; b++) {// generate unbiased distribution of spherical coordsdouble x = (a + random()) * oneoverN; // do not reuse resultsdouble y = (b + random()) * oneoverN; // each sample must be randomdouble theta = 2.0 * acos(sqrt(1.0 - x));double phi = 2.0 * PI * y;samples[i].sph = Vector3d(theta,phi,1.0);// convert spherical coords to unit vectorVector3d vec(sin(theta)*cos(phi), sin(theta)*sin(phi), cos(theta));samples[i].vec = vec;// precompute all SH coefficients for this samplefor(int l=0; l<n_bands; ++l) {

for(int m=-l; m<=l; ++m) {int index = l*(l+1)+m;samples[i].coeff[index] = SH(l,m,theta,phi);

}}

++i;}

}}

struct SHSample {Vector3d sph;Vector3d vec;double *coeff;};

Page 13: Spherical Harmonic Lighting: The Gritty Details(1/3)

Orthogonal Basis Function(8쪽 )

• Basis function( Bi(x) )– 어떤 original function 을 나타낼수있는 작은 조각– basis function 을 scaling, sum 을 통해 original function 을

근사화할 수 있다 .( 이러한 과정을 projection 한다고 한다 )

옆에 과정을 통해 coefficient 를 구할 수 있다 .

구해진 coefficient 와 basis 를 한번 더 곱한 후 그 결과값을

sum 하자

Page 14: Spherical Harmonic Lighting: The Gritty Details(1/3)

Orthogonal Basis Function(9쪽 )

• 방금전에 사용된 것은 linear basis functions 으로 input function으로 piecewise linear approximation( 구분적 선형 근사 ) 을 준다 .

• 여러 basis function 이 있지만 orthogonal polynomials 라 불리는 것이 많이 사용됨

• Orthogonal polynomials( 직교 다항식 )– 성질

– 직관적으로 다항식들간의 간섭하지 않는다는 것을 알 수 있다 .– 가장 유명한 것 중 Legendre polynomials 라 불리는 것이 있다 .– Associated Legendre polynomials

• symbol 로 P 라고 표현• l 과 m 으로 표현 (-1~1 사이 )• real number( 실수 ) 를 반환

Page 15: Spherical Harmonic Lighting: The Gritty Details(1/3)

Orthogonal Basis Function(9쪽 )

• Associated Legendre polynomials– 2 개의 아규먼트 l,m 은 polynomial 을 여러 개의 function band 로

나눈다 .– l 은 band index , 0 을 포함한 양수– m 은 0~l 사이의 값

The first six associatedLegendre polynomials.

위와 같이 n 개면 n(n+1) 개의 coefficient 를 구한다 .

Page 16: Spherical Harmonic Lighting: The Gritty Details(1/3)

Orthogonal Basis Function(10쪽 )

• Associated Legendre polynomials– 각각의 polynomial 을 recursive 하게 나타낼수있다 .– 아래 세가지 법칙에 따라 ..

Page 17: Spherical Harmonic Lighting: The Gritty Details(1/3)

Orthogonal Basis Function(10~11 쪽 )

• Associated Legendre polynomials– 소스코드로 한 번 살펴보자

Page 18: Spherical Harmonic Lighting: The Gritty Details(1/3)

Spherical Harmonics(11~12쪽 )

• SH 함수는 일반적으로 복소수에서 정의가 되나 , 여기서는 근사화된 실수 범위에서 정의

l 과 m 은 좀 Legendre polynomial 과는 좀 다른데 –l 이 0 을포함한 양수 m 은 –ㅣ ~ ㅣ사이의 값

Page 19: Spherical Harmonic Lighting: The Gritty Details(1/3)

Spherical Harmonics(13 쪽 )

• 소스코드를 보자

Page 20: Spherical Harmonic Lighting: The Gritty Details(1/3)

Spherical Harmonics