Rendering学習日記

日々、3DCGの世界は進歩しています。勉強して理解したことをまとめていきます。RenderMan互換レンダラーやグローバル・イルミネーション。いろんなことに好奇心を持って、面白くなる。目指せShader書き!!
ありがとうございます。

obj読み込み

本来ならば、コンバータをつくればよいのだろうが、
ここはcgkitを使ってobjをribに変換した。
cgkitでは、
>render.py -rレンダラ hogehoge.obj
とやると、指定のレンダラでレンダリング、geomフォルダができて
その中に、ribが生成される。これをgelatoに読み込んでみた。

このobjでは法線ベクトルがないので、カクカクしている。
chawan.jpg

#cha0.pyg
Output ("cha01.tif", "tiff", "rgb", "camera", "float gain", 1, "float gamma",
1, "string filter", "gaussian", "float[2] filterwidth", (2, 2))
Attribute ("string projection", "perspective")
Attribute ("float fov", 20)
Attribute ("int[2] resolution", (640, 480))
#placecam 10 5 -10 0 0 0
Rotate (-19.47, 1.00, 0.00, 0.00)
Rotate (45.00, 0.00, 1.00, 0.00)
Translate (-10.00, -5.00, 10.00)

Attribute ("string geometryset", "+shadows")

World ()
Light ("light1", "pointlight", "float intensity", 350, "point from", (-10, 10, -10),"string shadowname", "shadows")
Light ("light2", "pointlight", "float intensity", 350, "point from", (10, 10, -10),"string shadowname", "shadows")

PushTransform ()
Attribute ("color C", (1, 1, 0.9))
Shader ("surface", "veinedmarble")
Scale (20,20,20)
Translate ( 0, 0, 0)
Input ("chawan.rib")
PopTransform ()

Attribute ("color C", (1, 1, 1))
Shader ("surface", "plastic")
Rotate (90.00, 1.00, 0.00, 0.00)
Input("PlaneGeom.rib")
Render()
  • -
  • -

NVIDIA Gelato 平面状で反射する直線

POV−Rayと数学の関連を紹介しているサイトを参考にしました。
「数学のいずみ」http://izumi-math.jp/sanae/Pov_Ray/Pov_Ray.htm
くりかえし処理whileを使ってTranslateを変更していきました。
連続した球体が生成されます。
勉強になります。ありがとうございます。
sphere_hansya.jpg

#sphere_hansya.pyg
Output ("sphere_hansya.tif", "tiff", "rgb", "camera", "float gain", 1, "float gamma",
1, "string filter", "gaussian", "float[2] filterwidth", (2, 2))
Attribute ("float shadingquality",1.2)
Attribute ("string projection", "perspective")
Attribute ("float fov", 30)
Attribute ("int[2] resolution", (640, 480))
#placecam 0 10 -60 0 0 0
Rotate (-9.46, 1.00, 0.00, 0.00)
Translate (0.00, -10.00, 60.00)

Attribute ("string geometryset", "+shadows")
Attribute ("string geometryset", "+reflection")

World ()
Light ( "light0", "ambientlight", "float intensity", 0.3 )
Light ("light1", "pointlight", "float intensity", 400, "point from", (0, 20, -10),"string shadowname", "shadows")
Light ("light2", "pointlight", "float intensity", 400, "point from", (5, 0, -10),"string shadowname", "shadows")

PushTransform ()
Attribute ("color C", (0.2, 0.4, 0.75))
Sphere (100, -100, 100, 360)
PopTransform ()

MyCounter = -5
while (MyCounter <= 5):
PushTransform ()
Attribute ("color C", (1, 1, 1))
Shader ( "surface", "metal","string envname","reflection" )
Translate ( 2*MyCounter+1, abs(3*MyCounter+2),4*MyCounter+3)
Sphere (0.8, -0.8, 0.8, 360)
PopTransform ()
MyCounter = MyCounter + 0.5


Attribute ("color C", (1, 1, 1))
Rotate (90.00, 1.00, 0.00, 0.00)
Scale (10,10,10)
ShaderGroupBegin ()
Attribute ("color C", (1, 1, 0))
Shader ("surface", "checker", "checklayer","float stilesize",0.1,"float ttilesize",0.1,"color color2", ( 0, 0, 1 ))
Shader ("surface", "plastic", "plasticlayer")
ConnectShaders ("checklayer", "Cout", "plasticlayer", "C")
ConnectShaders ("checklayer", "fout", "plasticlayer", "Ks")
ShaderGroupEnd ()
Input("PlaneGeom.rib")
Render()
  • -
  • -

placecam.cで視野を調整する

「実践CGの誘い」や、RenderMan Fastの解説サイト、RenderDotCサイトのマニュアルページに、placecam.cがある。pythonで書き換えるのもできるし、簡単にコンパイルができます。今日もありがとうございます。

/* 
* PlaceCamera(): establish a viewpoint, viewing direction and orientation
* for a scene. This routine must be called before RiWorldBegin().
* position: a point giving the camera position
* aim: a point giving the location at which the camera is aimed
* roll: an optional rotation of the camera about its direction axis
* coneangle: an optional spotlight shader cone angle
*/

#include
#include
#include

#define PI 3.1415926535897932

void usage(void)
{
printf("usage: placecam pos_x pos_y pos_z aim_x aim_y aim_z\n");
printf(" [coneangle] [roll_angle]\n");
printf(" Calculate RenderMan transforms needed for camera transform\n");
printf(" from light position to aim point with the given roll angle.\n");
exit(1);
}

typedef double RtPoint[3];

void RiRotate(double angle, double x, double y, double z)
{
if (fabs(angle) > 0.001) {
printf("Rotate %0.2f %0.2f %0.2f %0.2f\n", angle, x, y, z);
}
}

void RiTranslate(double dx, double dy, double dz)
{
printf("Translate %0.2f %0.2f %0.2f\n", dx, dy, dz);
}

/*
* AimZ(): rotate the world so the direction vector points in
* positive z by rotating about the y axis, then x. The cosine
* of each rotation is given by components of the normalized
* direction vector. Before the y rotation the direction vector
* might be in negative z, but not afterward.
*/
void AimZ(RtPoint direction)
{
double xzlen, yzlen, yrot, xrot;

if (direction[0]==0 && direction[1]==0 && direction[2]==0)
return;

/*
* The initial rotation about the y axis is given by the projection of
* the direction vector onto the x,z plane: the x and z components
* of the direction.
*/
xzlen = sqrt(direction[0]*direction[0]+direction[2]*direction[2]);
if (xzlen == 0)
yrot = (direction[1] < 0) ? 180 : 0;
else
yrot = 180*acos(direction[2]/xzlen)/PI;

/*
* The second rotation, about the x axis, is given by the projection on
* the y,z plane of the y-rotated direction vector: the original y
* component, and the rotated x,z vector from above.
*/
yzlen = sqrt(direction[1]*direction[1]+xzlen*xzlen);
xrot = 180*acos(xzlen/yzlen)/PI; /* yzlen should never be 0 */

if (direction[1] > 0)
RiRotate(xrot, 1.0, 0.0, 0.0);
else
RiRotate(-xrot, 1.0, 0.0, 0.0);

/* The last rotation declared gets performed first */
if (direction[0] > 0)
RiRotate(-yrot, 0.0, 1.0, 0.0);
else
RiRotate(yrot, 0.0, 1.0, 0.0);
}

void PlaceCamera(RtPoint position, RtPoint direction, float roll)
{
RiRotate(-roll, 0.0, 0.0, 1.0);
AimZ(direction);
RiTranslate(-position[0], -position[1], -position[2]);
}

int main(int argc, char *argv[])
{
RtPoint pos, aim, dir;
double roll;
double coneangle, fov;

if (argc < 7) usage();

pos[0] = atof(argv[1]);
pos[1] = atof(argv[2]);
pos[2] = atof(argv[3]);
aim[0] = atof(argv[4]);
aim[1] = atof(argv[5]);
aim[2] = atof(argv[6]);

if (argc > 7) coneangle = atof(argv[7]);
else coneangle = 0.0;

if (argc > 8) roll = atof(argv[8]);
else roll = 0.0;

printf("position: %0.2f, %0.2f, %0.2f\n", pos[0], pos[1], pos[2]);
printf("aim: %0.2f, %0.2f, %0.2f\n", aim[0], aim[1], aim[2]);
printf("coneangle: %0.4f\n", coneangle);
printf("roll: %0.2f\n\n", roll);

if (coneangle != 0.0) {
fov = coneangle * 360.0 / PI;
printf("Projection \"perspective\" \"fov\" [%0.2f]\n", fov);
}

dir[0] = aim[0] - pos[0];
dir[1] = aim[1] - pos[1];
dir[2] = aim[2] - pos[2];

PlaceCamera(pos, dir, roll);
return 0;
}
  • -
  • -
<< 7/10 >>