Rendering学習日記

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

MayaのRIB exportを調べる

mixi RenderManコミュから転載:

MayaからプラグインのRIBexportでカメラは
Transform [ ]で出ていますが、
いろいろと調べてみました。

RIBでの視野変換を以下のようにやるとして、
Rotate RX 1 0 0
Rotate RY 0 1 0
Rotate RZ 0 0 1
Translate -TX -TY TZ
Scale SX SY -SZ

行列は下から上へ、の順で乗算していき、逆行列を求めれば良いです。

Translateの行列は、TX,TX,-TZで求め
Rotate Yは、180-RYで求めました。

以下はMayaのPerspのデフォルト位置を例として
Python CGkitで求めてみました。

Translate X: 28
Translate Y: 21
Translate Z: 28
Rotate X: -27.938
Rotate Y: 45
Rotate Z: 0
Scale X: 1
Scale Y: 1
Scale Z: 1


C:\Python25>python
>>> from cgkit.all import *
>>> tr=mat4(1).translation(vec3(28,21,-28)) 
>>> import math
>>> rx=mat4(1).rotate(-27.938*math.pi/180,vec3(1,0,0))
>>> rx
[1, 0, 0, 0]
[0, 0.883455, 0.468516, 0]
[0, -0.468516, 0.883455, 0]
[0, 0, 0, 1]
>>> ry=mat4(1).rotate((180-45)*math.pi/180,vec3(0,1,0))
>>> ry
[-0.707107, 0, 0.707107, 0]
[0, 1, 0, 0]
[-0.707107, 0, -0.707107, 0]
[0, 0, 0, 1]
>>> v=tr*ry*rx
>>> v
[-0.707107, -0.331291, 0.624697, 28]
[0, 0.883455, 0.468516, 21]
[-0.707107, 0.331291, -0.624697, -28]
[0, 0, 0, 1]
>>> v.inverse() 逆行列
[-0.707107, -2.77556e-017, -0.707107, 0]
[-0.331291, 0.883455, 0.331291, -0.000275937]
[0.624697, 0.468516, -0.624697, -44.8219]
[0, 0, 0, 1]
>>> v.inverse().transpose() 転置行列
[-0.707107, -0.331291, 0.624697, 0]
[-2.77556e-017, 0.883455, 0.468516, 0]
[-0.707107, 0.331291, -0.624697, 0]
[0, -0.000275937, -44.8219, 1]
>>> s2=mat4(1).scaling(vec3(1,1,-1))
>>> s3=mat4(1).scaling(vec3(-1,1,-1))
>>> s2*v.inverse().transpose()*s3 スケールを両側からかけてみました。
[0.707107, -0.331291, -0.624697, 0]
[2.77556e-017, 0.883455, -0.468516, 0]
[-0.707107, -0.331291, -0.624697, 0]
[0, -0.000275937, 44.8219, 1]

よって
ConcatTransform [0.707107 -0.331291 -0.624697 0
2.77556e-017 0.883455 -0.468516 0
-0.707107 -0.331291 -0.624697 0
0 -0.000275937 44.8219 1]

ということで、cgkitで視野変換学べます。
ありがとうございます。
  • -
  • -

NVIDIA Gelatoでreflectを試す

全体を大きな球体に入れ、青で囲んでいます。
青玉は、ブラーがかかっています。
#sphere32.pyg
Output ("sphere32.tif", "tiff", "rgb", "camera", "float gain", 1, "float gamma",
1, "string filter", "gaussian", "float[2] filterwidth", (2, 2))
Attribute ("float shadingquality",2)
Attribute ("string projection", "perspective")
Attribute ("float fov", 13)
Attribute ("int[2] resolution", (640, 480))
#placecam -20 15 0 0 0 0
Rotate (-36.87, 1.00, 0.00, 0.00)
Rotate (-90.00, 0.00, 1.00, 0.00)
Translate (20.00, -15.00, 0.00)

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

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

Light ("light1", "spotlight", "string shadowname", "shadows", "point from", (-20, 50, -20), "point to",
(0, 0, 0), "float intensity", 6000, "float coneangle", 90,"float shadowblur",0.01,"float shadowsamples", 4,"float shadowbias",0.1)


PushTransform ()
Attribute ("color C", (1, 1, 0.25)) #yellow
Shader ("surface", "metal", "string envname", "reflection",
"float Kd", 0.05, "float roughness", 0.1, "float Kr", 0.75,
"float Ka", 0.5,
# "float samples", 4, "float blur", 0.05,
"float twosided", 1
)
Translate ( 0, 1, 0)
Sphere (1, -1, 1, 360)
PopTransform ()

PushTransform ()
Attribute ("color C", (0.25, 0.25, 1)) #blue
Shader ("surface", "metal", "string envname", "reflection",
"float Kd", 0.05, "float roughness", 0.1, "float Kr", 0.75,
"float Ka", 0.5,
"float samples", 4, "float blur", 0.1,
"float twosided", 1
)
Translate ( 0, 1, 2.5)
Sphere (1, -1, 1, 360)
PopTransform ()



PushTransform ()
Attribute ("color C", (1, 0.25, 0.25)) #red
Shader ("surface", "metal", "string envname", "reflection",
"float Kd", 0.05, "float roughness", 0.1, "float Kr", 0.75,
"float Ka", 0.5,
# "float samples", 4, "float blur", 0.1,
"float twosided", 1
)
Translate ( 0, 1, -2.5)
Sphere (1, -1, 1, 360)
PopTransform ()

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

sphere4.jpg
  • -
  • -

NVIDIA Gelatoでアンビエント・オクルージョン

まず、AO(ambient-occlusion)を求める。
#sphere32ao.pyg

Attribute ("int ray:maxdepth", 1)

Output ("sphere32ao.tif", "tiff", "rgb", "camera", "float gain", 1, "float gamma",
1, "string filter", "gaussian", "float[2] filterwidth", (2, 2))
Attribute ("float shadingquality",2)
Attribute ("string projection", "perspective")
Attribute ("float fov", 13)
Attribute ("int[2] resolution", (640, 480))
#placecam -20 15 0 0 0 0
Rotate (-36.87, 1.00, 0.00, 0.00)
Rotate (-90.00, 0.00, 1.00, 0.00)
Translate (20.00, -15.00, 0.00)

Attribute ("string occlusion:spatialdb", "occ.sdb");
Attribute ("string spatialdb:write", "occ.sdb");

World ()
Shader ("surface", "ambocclude", "string occlusionname", "localocclusion", "float samples", 256, "float bias", 0.01)

Attribute ("string geometryset", "+localocclusion")
Attribute ("float occlusion:maxpixeldist", 20)
Attribute ("float occlusion:maxerror", 0.25)

PushTransform ()
Attribute ("color C", (1, 1, 0.25)) #yellow
Translate ( 0, 1, 0)
Sphere (1, -1, 1, 360)
PopTransform ()

PushTransform ()
Attribute ("color C", (0.25, 0.25, 1)) #blue
Translate ( 0, 1, 2.5)
Sphere (1, -1, 1, 360)
PopTransform ()

PushTransform ()
Attribute ("color C", (1, 0.25, 0.25)) #red
Translate ( 0, 1, -2.5)
Sphere (1, -1, 1, 360)
PopTransform ()

Attribute ("color C", (1, 1, 1))
Rotate (90.00, 1.00, 0.00, 0.00)
Input("PlaneGeom.rib")
Render()

sphere3_ao.jpg

つづいて、Photoshopでレイヤーに入れて乗算処理する。
sphere3_multi.jpg
  • -
  • -
<< 4/10 >>