10
Wrapped Diffuse 이이이 Shader Study

Wrapped Diffuse 이민웅 Shader Study. Wrapped Diffuse 팀 포트리스 2 에서 사용 subsurface scattering, area light source, 더 부드러운 reflectance 를 표현하기 위해

Embed Size (px)

Citation preview

Page 1: Wrapped Diffuse 이민웅 Shader Study. Wrapped Diffuse 팀 포트리스 2 에서 사용 subsurface scattering, area light source, 더 부드러운 reflectance 를 표현하기 위해

Wrapped Diffuse

이민웅Shader Study

Page 2: Wrapped Diffuse 이민웅 Shader Study. Wrapped Diffuse 팀 포트리스 2 에서 사용 subsurface scattering, area light source, 더 부드러운 reflectance 를 표현하기 위해

Wrapped Diffuse

• 팀 포트리스 2 에서 사용• subsurface scattering, area light

source, 더 부드러운 reflectance 를 표현하기 위해서 Hemisphere( 반구 ) 를 감싸는 셰이딩 모델

Lambert Wrapped Diffuse

Page 3: Wrapped Diffuse 이민웅 Shader Study. Wrapped Diffuse 팀 포트리스 2 에서 사용 subsurface scattering, area light source, 더 부드러운 reflectance 를 표현하기 위해

Wrapped Diffuse

• HarfLambert 공식과 비슷함–W=1 이면 , Half Lambert 공식

• Half Lambert 와 유사하게 투과되는 느낌을 표현하는데 많이 사용–피부 , 나뭇잎 , 파티클 라이팅에 주로 사용

기본 Lambert Diffuse 공식float diffuse = max(0, dot(normal, lightdirection));

기본 HalfLambert Diffuse 공식float halflambert_term = dot(normal, lightdirection) * 0.5f + 0.5f

Wrapped Diffuse 공식 float diffuse = saturate((dot(normal, lightdirection) + OFFSET) / (1.0+OFFSET ));

Page 4: Wrapped Diffuse 이민웅 Shader Study. Wrapped Diffuse 팀 포트리스 2 에서 사용 subsurface scattering, area light source, 더 부드러운 reflectance 를 표현하기 위해

Wrapped Diffuse

Wrapped SH 자세한 내용http://blog.selfshadow.com/2011/12/31/righting-wrap-part-1/http://blog.selfshadow.com/2012/01/07/righting-wrap-part-2/

Wrap Shadingwww.iro.umontreal.ca/~derek/files/jgt_wrap.pdf

Page 5: Wrapped Diffuse 이민웅 Shader Study. Wrapped Diffuse 팀 포트리스 2 에서 사용 subsurface scattering, area light source, 더 부드러운 reflectance 를 표현하기 위해

Wrapped Diffuse

• 팀 포트리스 방식–Wrapped Function 은 Half Lambert 를

이용해서 , 1D Wrapped Diffuse Texture에서 값을 얻어오는 것

– GPU Gems 16. Real-Time Approximation to Subsurface Scattering• Wrap Lighting 계산 내용을 미리 Texture 로

저장하여 사용함

Page 6: Wrapped Diffuse 이민웅 Shader Study. Wrapped Diffuse 팀 포트리스 2 에서 사용 subsurface scattering, area light source, 더 부드러운 reflectance 를 표현하기 위해

http://www.sfdm.scad.edu/faculty/mkesson/vsfx419/wip/spring11/eric_kurzmack/toon.html

Lambert Half Lambert Squared Half Lambert (Not used)Warping Function

Light Color Ambient Albedo

illuminance( P, n, PI) { Ln = normalize(L); halflambert += .5*(Ln.nf)+.5; float chl = clamp(halflambert,0.01,1); accumulateMapColor = texture(warp,chl,0)*2; hlsw_clrlght += Cl*accumulateMapColor; } diffusecolor = albedocolor * (Ka + hlsw_clrlght);

WarpTex

Ka : ambientCl : LightColor

Page 7: Wrapped Diffuse 이민웅 Shader Study. Wrapped Diffuse 팀 포트리스 2 에서 사용 subsurface scattering, area light source, 더 부드러운 reflectance 를 표현하기 위해

http://www.sfdm.scad.edu/faculty/mkesson/vsfx419/wip/spring11/eric_kurzmack/toon.html

Specular Fresnel Primary Specularity Rim Fresnel Rim Specular

Mixed Specular Upward Ambient RimFinal Mix

Page 8: Wrapped Diffuse 이민웅 Shader Study. Wrapped Diffuse 팀 포트리스 2 에서 사용 subsurface scattering, area light source, 더 부드러운 reflectance 를 표현하기 위해

Code

vector i= normalize(-I); float fres=spline((nf.i),1,1,1,.95,.6,.6);

illuminance( P, n, PI/2) { Ln = normalize(L); vector R = reflect(-Ln,nf); ridot += clamp(max(0,(R.i)),.01,.99); phngspec += (1-fres)*pow(ridot,specE); }

vector i= normalize(-I); float rimfres=pow((1-(nf.i)),2);vector i= normalize(-I);

illuminance( P, n, PI/2) { Ln = normalize(L); vector R2 = reflect(Ln,nf); ridot2 += clamp(max(0,(R2.i)),.01,.99); phngrim += rimfres*pow(ridot2,Krim); }

illuminance( P, n, PI/2) { Ln = normalize(L); vector R = reflect(-Ln,nf); vector R2 = reflect(Ln,nf); ridot += clamp(max(0,(R.i)),.01,.99); ridot2 += clamp(max(0,(R2.i)),.01,.99); phngspec += (1-fres)*pow(ridot,specE); phngrim += rimfres*pow(ridot2,Krim); phngmix += Cl*Ks*(max(phngrim,phngspec)*2); } speccolor = phngmix;

float upward = clamp((nf.vector(0,1,0)),0,1); float uprim= upward*rimfres*Kr*(Ka*5);

Ci = Oi*(diffusecolor+speccolor+uprim);

Specular Fresnel

Primary Specularity

Rim Fresnel

Rim Specular

Mixed Specular

Upward Ambient Rim

Final Mix

Page 9: Wrapped Diffuse 이민웅 Shader Study. Wrapped Diffuse 팀 포트리스 2 에서 사용 subsurface scattering, area light source, 더 부드러운 reflectance 를 표현하기 위해

Q&A

Page 10: Wrapped Diffuse 이민웅 Shader Study. Wrapped Diffuse 팀 포트리스 2 에서 사용 subsurface scattering, area light source, 더 부드러운 reflectance 를 표현하기 위해

참고자료• Wrap Shading :

http://www.iro.umontreal.ca/~derek/publication8.html

• Energy-Conserving Wrapped Diffuse • Wrapped Diffuse 와 팀포트리스 셰이딩 :

http://cagetu.egloos.com/5621806• 팀포트리스 셰이딩 따라해보기 :

http://cagetu.egloos.com/4212681 • Energy Conservation in Games :

http://www.rorydriscoll.com/2009/01/25/energy-conservation-in-games/

• http://www.gamedevforever.com/150• http://cagetu.egloos.com/5621806