3 minutes reading time
(555 words)
amber.vfl
/* * Shader Info : 호박(琥珀:광물) shader 입니다. * Modifed By : 정현준 */ #pragma hint center_color00 color #pragma hint center_color01 color #pragma hint edge_color00 color #pragma hint edge_color01 color #include <prman.h> //snoise 함수입니다. #define snoise(x) (noise(x) * 2 - 1) // MINFILTERWIDTH 정의 #define MINFILTERWIDTH 1e-7 //해당 값의 제곱근을 구해서, MINFITLERWIDTH와 비교해서 큰값을 받습니다. #define filterwidth_point(p) (max(sqrt(area(p)), MINFILTERWIDTH)) // turbulence 함수입니다. float turbulence( point PP ) { float fade, f, maxfreq, width, cutoff, turb , total; maxfreq = 16; width = filterwidth_point( PP ); cutoff = clamp( 0.5 / width, 0, maxfreq ); turb = 0; total = 0; // f를 f*2의 주기로 cutoff의 절반만큼 반복 for (f = 1; f < 0.5 * cutoff; f *= 2 ) { turb += abs(snoise( PP * f )) / f; // 노이즈 절대값화 -> 음수 그래프부분 반전 total += 1 / f; // total = total + 1 / f } fade = clamp( 2 * (cutoff - f) / cutoff, 0, 1); // 2 * (cutoff - f) / cutoff 값을 0~1사이 clamp 값 반환 turb += fade * abs( snoise( PP * f ) ) / f; // // 노이즈 절대값화 -> 음수 그래프부분 반전 total += fade / f; // total = total fade/f turb /= total; // turb = turb / total return turb; } // 메인 쉐이더 surface hjcAmber( vector center_color00 = {1, 0.678, 0}; vector center_color01 = {0.338, 0, 0}; float center_gain = 1; float center_turb_freq = 3; float center_turb_gain = 1.5; vector edge_color00 = {1, 0.678, 0}; vector edge_color01 = {0.338, 0, 0}; float edge_gain = 0.3; float edge_turb_freq = 2; float edge_turb_gain = 1; float falloff_attenuation = 1; float falloff_gain = 1; float Ks00 = 1; float roughness00 = 0.15; float metalness00 = 0; float Ks01 = 0.7; float roughness01 = 0.5; float metalness01 = 1; float Kd = 0.7; float Ka = 0.2; float lightness = 0.6; float opacity = 0.7; ) { vector cs, specular00, specular01, NN, II; // spec, 노말, 시선벡터 변수선언 normal Nf; // 노말 temp 변수선언 point PP; // 포인트 temp 변수선언 float center_turb, edge_turb, falloff; // center, edge turb변수, bias역할을하는 falloff 변수 선언 color center_color, edge_color; // center, edge 색상 변수 PP = ctransform("shader", P); NN = normalize(N); // 노말벡터 정규화 II = normalize(I); // 시선벡터 정규화 falloff = dot(II,NN); // falloff 노말벡터와 시선벡터 내적 center_turb = turbulence( PP * center_turb_freq ) * center_turb_gain; // center turbulence edge_turb = turbulence( PP * edge_turb_freq ) * edge_turb_gain; // edge turbulence center_color = mix( center_color00, center_color01, center_turb ) * center_gain; // cetner color edge_color =mix( edge_color00, edge_color01, edge_turb ) * edge_gain; // edge color falloff = 1.0 - (falloff * falloff / (dot(II,II) * dot(NN,NN))); // falloff의 제곱한 값에 시선벡터끼리, 노말벡터끼리의 내적값의 곱과 나눠준 후 1에서 뺄셈연산 falloff = clamp(pow( falloff, falloff_attenuation ) * falloff_gain, 0, 1); // falloff를 falloff_att 만큼 제곱해서 falloff_gain곱해준 값을 0~1 clamp cs = mix( center_color, edge_color, falloff ); // center_color와 edge_color을 mix bias : falloff Nf = faceforward( normalize( N ), I ); // dot(normalize(N), I) < 0 이면 N값 반전 specular00 = Ks00*specular(Nf,-normalize(I),roughness00)*((cs*metalness00)+(1.0-metalness00)); // spec모델에 적용 specular01 = Ks01*specular(Nf,-normalize(I),roughness01)*((cs*metalness01)+(1.0-metalness01)); // spec모델에 적용 Ci = (cs*(Ka*ambient() + Kd*diffuse(Nf) + lightness)) + specular00 + specular01; // 기본 shader모델에 적용 Of = opacity; }
Comments