2 minutes reading time
(322 words)
toon.vfl
/*
* Shader Info : 카툰 shader 입니다.
*/
#include <math.h>
#include <shading.h>
// label pragma
#pragma label baseclr1 "Base Color1"
#pragma label baseclr2 "Base Color2"
#pragma label specclr "Spec Color"
#pragma label bline_clr "Black line"
#pragma label spec_rate "Spec rate"
#pragma label dark_rate "Dark rate"
#pragma label bline_rate "BLine rate"
// color pragma
#pragma hint baseclr1 color
#pragma hint baseclr2 color
#pragma hint specclr color
#pragma hint bline_clr color
//범위설정 pragma
#pragma range spec_rate 0 1.0
#pragma range dark_rate 0 1.0
#pragma range bline_rate 0 0.3
// help pragma
#pragma help "This shader colors like a cartoon. Surface elements"
#pragma help "pointing away from the light source will be shaded with"
#pragma help "0.25 the color, there will be a black strip around the"
#pragma help "sillhouette edge from the illuminating light source"
/*
grobal value
N normal at point
*/
surface
hjcToon(
vector baseclr1 = {1, .7, .6}; // 베이스컬러1
vector baseclr2 = { 0.545, 0.525, 0.306 } ; // 베이스컬러2
vector specclr = {1, 1, 1}; // spec 컬러
vector bline_clr = {0, 0, 0}; //bline 컬러
float spec_rate = 0.1 ; // spec 강도
float dark_rate = 0.5 ; // dare 강도
float bline_rate = 0.2 ; // bline 강도
)
{
vector nn;
nn = frontface(normalize(N), I); // dot(normalize(N), I) < 0 이면 N값 반전
Cf = ambient(); // ambient light model
illuminance(P, N, PI) {
Cf += Cl;
if ( dot(nn, normalize(L)) >= ( 1.0 - spec_rate ) )
{
Cf *= specclr ;
}else if ( ( ( dot(nn, normalize(L)) + 1.0 ) * 0.5 ) > dark_rate )
// }else if ( dot(nn, normalize(L)) >= 0.0 )
{
Cf *= baseclr1 ;
}else
{
Cf *= baseclr2 ;
}
}
if ( abs( dot( normalize(nn), normalize(I) ) ) < bline_rate )
{
Cf = bline_clr ;
}
}
Comments