2008년 4월 23일 수요일

slim expression을 이용한 재미난 장난...

pointbased occlusion이 은근히 불편했다.

bake3d를 이용해서 ptc 파일을 생성하고 이를 불러와서 occlusion을 연산해야하니...
픽사에서 샘플로 만든 템플릿을 사용하면되지만,
slim shading network을 이용해서 rendering을 걸때 발생하는 에러나... 기타의 몇가지 문제점들이 많다.
이에 대한 부분은 차후 프로젝트가 끝나면 정리를 해볼까한다.

우선은...
$ELEMENTTYPE값을 이용해서 쉐이더가 적용되는 값을 바꿔봤다.
ㅋㅋㅋ

#include "normals.h"

surface
masin_occ ( uniform string opa_file = "", filename = "", context = "";
float maxdist = 1e15; )
{
color bkocc;
color opacity;
if ( opa_file != "" )
opacity = texture(opa_file, 1*s, 1*t);
else
opacity = color(1, 1, 1);

if ( context == "reference" )
{
normal Nn = normalize(N);
float a = area(P, "dicing");
float op = 0.333333 * (opacity[0] + opacity[1] + opacity[2]);

a *= op;

if (a > 0)
bake3d(filename, "_area", P, Nn, "interpolate", 1, "_area", a);

bkocc = color(1, 1, 1) * opacity;
}
if ( context == "final" )
{
normal Ns = shadingnormal(N);

float occ;

occ = occlusion(P, Ns, 0, "pointbased", 1, "filename", filename,
"hitsides", "both",
"maxdist", maxdist,
"bias", 0.01,
"falloff", 0,
"falloffmode", 0,
"samplebase", 0,
"clamp", 1,
"maxsolidangle", 0.05);

bkocc = (1 - occ) * opacity;
}

Ci = bkocc;
Oi = opacity;
}

댓글 2개:

SukHee :

상훈씨..렌더맨서포트에 가보니.. 쉐이브앤헤어컷 쉐이더를 고쳐서 sl로 작성해놨더군요. 테스트해보니..하얗게 날라가는 것도 없고 좋던데요..https://renderman.pixar.com/forum/showthread.php?s=&threadid=9327
에 가서 jagger가 쓴글이 있습니다. 참고 하세요.

SukHee :

그냥 여기에다 남길게요.

surface shave_total (float Ka = 0, SHAVEambdiff = .6, SHAVEspec = .35, SHAVEgloss = .07,SHAVEopacity = 1.0,SHAVEselfshad=1;
color SHAVEspec_color=1,rootcolor=1,tipcolor=1;)
{
normal pxslUtilShadingNormal(normal n;){
normal Ns = normalize(n);
extern vector I;
uniform float sides = 2;
uniform float raydepth;
attribute("Sides", sides);
rayinfo("depth", raydepth);
if (sides == 2 || raydepth > 0)Ns = faceforward(Ns, I, Ns);
return Ns;
}
normal Ns = pxslUtilShadingNormal(N);
float occl = 0;
color indiff = 0;
vector T = normalize (dPdv); /* tangent along length of hair */
vector V = -normalize(I); /* V is the view vector */
float df2 = 0,diffterm=0;
color Cspec = 0, Cdiff = 0; /* collect specular & diffuse light */
color mixed=1;
float rawspec;
color Cl2;
float vt;
float tl;
float nondiff = 0;
float nonspec = 0;
lightsource("__nondiffuse", nondiff);
lightsource("__nonspecular", nonspec);
illuminance ("environment", P, Ns, PI,
"lightcache", "refresh",
"send:light:__surfacearea", -10,
"send:light:__coneangle", PI,
"send:light:__coneaxis", Ns,
"light:__nondiffuse", nondiff,
"light:__nonspecular", nonspec,
"light:_indirectdiffuse", indiff,
"light:_occlusion", occl){
float sq2;
df2=(T.normalize(L));
df2*=df2;
df2=1.0-df2;
if (df2<0) df2=0;
if (df2>0)
df2=sqrt(df2);
diffterm=df2; /* diffuse */
if (diffterm<0) diffterm=0;
vt = V.T ;
sq2=1.0-vt*vt;
if (sq2<0) sq2=0;
if (sq2>0)
sq2=sqrt(sq2);
rawspec = df2* sqrt( 1.0- vt * vt ) - (normalize(L). T ) * vt; /* raw specular */
if (rawspec<0) rawspec=0;
diffterm=(1.0-SHAVEambdiff)+diffterm*SHAVEambdiff; /* limits gamut of diffuse term */
Cl2=Cl*SHAVEselfshad+(1-SHAVEselfshad); /* limits the gamut of shadowing */
if (nonspec < 1)
Cspec += (1-nonspec) * Cl2*pow( rawspec, 1.0 / ( 3 * ( .101 - SHAVEgloss ) ) )*SHAVEgloss; /* specular exponent x illumination */
if (nondiff < 1)
Cdiff += (1-nondiff) * Cl2*diffterm; /* diffuse x illumination */
}
illuminance ("-environment", P, "lightcache", "reuse")
{
float nondiff = 0;
float nonspec = 0;
lightsource("__nondiffuse", nondiff);
lightsource("__nonspecular", nonspec);
float sq2;
df2=(T.normalize(L));
df2*=df2;
df2=1.0-df2;
if (df2<0) df2=0;
if (df2>0)
df2=sqrt(df2);
diffterm=df2; /* diffuse */
if (diffterm<0) diffterm=0;
vt = V.T ;
sq2=1.0-vt*vt;
if (sq2<0) sq2=0;
if (sq2>0)
sq2=sqrt(sq2);
rawspec = df2* sqrt( 1.0- vt * vt ) - (normalize(L). T ) * vt; /* raw specular */
if (rawspec<0) rawspec=0;

diffterm=(1.0-SHAVEambdiff)+diffterm*SHAVEambdiff; /* limits gamut of diffuse term */
Cl2=Cl*SHAVEselfshad+(1-SHAVEselfshad); /* limits the gamut of shadowing */
if (nonspec < 1)
Cspec += (1-nonspec) * Cl2*pow( rawspec, 1.0 / ( 3 * ( .101 - SHAVEgloss ) ) )*SHAVEgloss; /* specular exponent x illumination */
if (nondiff < 1)
Cdiff += (1-nondiff) * Cl2*diffterm; /* diffuse x illumination */
}
mixed = mix( rootcolor, tipcolor, v );
Oi = Os*SHAVEopacity;
Ci = Oi * Cs * mixed* (Ka*ambient() + Cdiff) + ( Cspec * SHAVEspec_color *SHAVEspec); /*sum terms and premult color x opac */
}

컴파일하시고 C:\Program Files\JoeAlter\shaveHaircut\maya8.5\plug-ins\prman\lib\shaders 에 집어넣으시면 됩니다.