Rendering学習日記

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

Go言語でRenderMan

RenderMan bindings for the Go Language. 
Go言語でRenderManをLinuxで設定するのは簡単にできましたが、Windowsにインストールするのは大変でした。Program Filesのスペースに悩まされました。結果としてはPixar RenderManProServerはC:\Program filesにインストールしないで、C:\Pixarにインストールしなおしました。
grasshopper.jpg
付属go_test.goを実行して得た画像。prman16.5でオクルージョンを出せました。prman17.0、prman18.0ではうまく出ません。

追記2013/10/26:
(prman17以降の仕様変更でocclusionは
Attribute "visibility" "int transmission" [1]
とすれば、きちんと表示されます。)


以下、まとめてみました。
■必要なもの
●Windows 32bitの場合
Go言語32bit版
gccコンパイラ MinGWを使いました。

●Windows64bit版
Go言語64bit版
gccコンパイラ TDM-GCC Compiler Suite for Windowsを使いました。
TDM64 bundleをインストールしました
http://tdm-gcc.tdragon.net/

●RenderMan bindings for the Go Language.
gormanはこちらです。
https://github.com/prideout/gorman

1. Download Zipからファイルgorman-master.zipを取得します


 C:\gormanに解凍します。

2. Go言語をC:\goにインストールします


Windows XpへのGo言語のインストールでは、GOPATHは、環境変数として記入する必要があります。バッチでset GOPATH= と設定しても、go envで確認すると反映されていません。

3. gccコンパイラをインストールします


  MinGWだと「C++ Compiler」「MSYS Basic System」「MinGW Developer Toolkit」のコンポーネントを選択してインストールします。
環境変数のPathに編集でパスの最後に以下を追記します。
;C:\MinGW

64bitの場合、TDM-GCC Compiler Suite for WindowsをC:\TDM-GCC-64にインストールします。

4. Pixar RenderManProServerをC:\Pixarにインストールします



5. C:\gormanフォルダにコマンドプロンプトを作ります


  コマンドプロンプトショートカットアイコンを右クリックしプロパティを開きます。
  リンク先の部分を以下のように書き換えます。
  %windir%\system32\cmd.exe /k "chcp 65001"

6. Go言語の確認


  エディタで以下をhello.goで保存します。保存先C:\gorman

package main

import "fmt"

func main() {
fmt.Printf("hello, world\n")
}


コマンドプロンプトから
>go build hello.go
>hello.exe
hello, world

>
と出ればGoは動いています。

7 gormanの設定


64bitではTDM-GCC Compiler Suite for Windowsを読み込むために、以下のようにバッチファイルを作成します。
ファイル名gobat.bat
保存先C:\gorman

set GOROOT=C:\go
set GOPATH=C:\gorman
set PATH=%GOROOT%\bin;C:\TDM-GCC-64\bin;%PATH%



32bitでは
ファイル名gobat.bat
保存先C:\gorman

set GOROOT=C:\go
set GOPATH=C:\gorman
set PATH=%GOROOT%\bin;%PATH%



バッチファイルができたらコマンドプロンプトで
>gobat.bat
続いて環境を確認します。
>go env
set GOARCH=amd64
set GOBIN=
set GOCHAR=6
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:\gorman
set GORACE=
set GOROOT=C:\go
set GOTOOLDIR=C:\go\pkg\tool\windows_amd64
set TERM=dumb
set CC=gcc
set GOGCCFLAGS=-g -O2 -m64 -mthreads
set CGO_ENABLED=1

GOPATH=C:\gormanが表記されていないと、この後のパッケージrmanがインストールできません。Windows Xpでは、GOPATHを環境変数として記入する必要があります。

8. rmanパッケージのインストール


C:\gormanのコマンドプロンプトから
>go install ./src/rman
たぶんエラーが出ます。
Pixar RenderManProServerのパスが正確でないためです。
C:\gorman\src\rmanフォルダのrman.goを編集します。
エディタで開き、最初の3行目から6行目部分のパスを以下のような相対パスで記述してください。適宜prmanのバージョンは変えてください。

package rman

// #cgo CFLAGS: -I../../../Pixar/RenderManProServer-18.0/include
// #cgo LDFLAGS: -L../../../Pixar/RenderManProServer-18.0/lib -lprman -Wl,-rpath ../../../Pixar/RenderManProServer-18.0/lib
// #include
// #include "ri.h"



再度C:\gormanのコマンドプロンプトから
>go install ./src/rman
しばらくして・・・何もなかったらOK!!
pkgフォルダができていたら完成です。

9. テストをしてみる


テストの前にPixar RenderManProServerのlibフォルダから
libprman.dllをC:\gorman\src\rmanフォルダへコピーします。
C:\gormanのコマンドプロンプトを閉じていたら
>gobat.bat
続いてテストをします。
>go test ./src/rman
しばらくして、本記事の一番上にある画像が出てきたら成功です。
これはC:\gorman\src\rmanフォルダのrman_test.goを実行しています。
フォルダ内にdebug.ribが書き出されるので便利です。


10. サンプル球をビルドしてみる


続いてlibprman.dllをC:\gormanフォルダへコピーします。
>go build sphere.go
>sphere.exe
sphere.jpg
レンダリング画像。
その他、開発者Philip RideoutさんのL-Systemによる画像素晴らしいです。
Go And Renderman
https://github.com/prideout/gorman
Thank You.ありがとうございます。
  • -
  • -

Go言語でRenderMan その2

rman.goにLightSourceを追加する

func LightSource(name string, varargs ...interface{}) {
pName := C.CString(name)
defer C.free(unsafe.Pointer(pName))
names, values, ownership := unzipArgs(varargs...)
defer freeArgs(names, ownership)
nArgs := C.RtInt(len(varargs) / 2)
pNames, pVals := safeArgs(names, values)
C.RiLightSourceV(pName, nArgs, pNames, pVals)
}



Teapotをレンダリング

package main

import (
ri "rman"
)

func color(r, g, b float32) [3]float32 {
return [3]float32{r, g, b}
}

func point(x, y, z float32) [3]float32 {
return [3]float32{x, y, z}
}

func main() {
launch := "launch:prman? -t -ctrl $ctrlin $ctrlout -capture test2.rib"
ri.Begin(launch)
ri.Format(512, 480, 1)
ri.Display("test2", "framebuffer", "rgba")
ri.ShadingRate(4)
ri.Option("limits", "int threads", 4)
ri.PixelSamples(4, 4)
ri.Declare("color", "color")
ri.Imager("background","color",color(0.2,0.4,0.6))
ri.Projection("perspective", "fov", 45.)
ri.Translate(0, 0, 9)
ri.WorldBegin()
ri.Declare("from", "point")
ri.Declare("intensity", "float")
ri.LightSource("pointlight","intensity",300. ,"from", point(-10,10,-10))
ri.LightSource("pointlight","intensity",300. ,"from", point(10,10,-10))
ri.LightSource("pointlight","intensity",300. ,"from", point(-10,-10,-10))
ri.Translate(0, -1.2, 0)
ri.Rotate(-110,1,0,0)
ri.Color(0.9, 0, 0.1)
ri.Surface("plastic")
ri.Geometry("teapot")
ri.WorldEnd()
ri.End()
}


test2.jpg
  • -
  • -

Guile RMan is a set of bindings for the RenderMan API

Guile RMan is a set of bindings for the RenderMan API as implemented by Aqsis, using SWIG and libffi.
Support for function callbacks written in Scheme
Support Scheme RiProcedurals
Type checking for named paramter lists
Support for both immediate rendering and RIB output
A utilities module to provide simple wrapper around RenderMan block structure
https://github.com/tcolgate/guile-rman

インストール方法いろいろ試してみました。
32ビットLinuxで動作します。
Aqsisは1.6.0
gnu guile2.0.9(最低2.0.0で動きます。)
guile-lib0.2.2(最低0.2.0で動きます。)

■Windows7 64bitにVirtualBoxを入れ、CentOS6.3 i686上で動作確認しました。
●準備
Aqsis1.6をインストールします。
リポジトリにEPELを設定するとしAqsis1.6があります。
http://www.tooyama.org/yum-addrepo-epel.html
を参考にEPELを設定します。
管理者で
#yum --enablerepo=epel search aqsis
で探します。
============================== N/S Matched: aqsis ==============================
aqsis-core.i686 : Command-line tools for Aqsis Renderer
aqsis-data.noarch : Example content for Aqsis Renderer
aqsis-devel.i686 : Development files for Aqsis Renderer
aqsis-libs.i686 : Library files for Aqsis Renderer
aqsis.i686 : Open source 3D rendering solution adhering to the RenderMan: standard
と出てきたら、
yum --enablerepo=epel install aqsis-devel.i686
をインストールすると関連ファイルも含めて全部入れてくれます。

●guile-rman関連のインストール
1. SWIGをインストールします。swig-2.0.11をダウンロードし
$ ./configure
$ make
# make install
します。
CentOSのSWIGは1.3と古いので入れていたら削除します。

2. gnu guile2.0.9をダウンロードします。
https://www.gnu.org/software/guile/download.html

$./configure

うまく行かない場合は、指示を見て
以下のツールをあらかじめインストールします。
readline-devel
texinfo
ltdl-devel
gmp-devel
libunistring-devel
libffi-devel
gc-devel
gc
PCRE-devel

入れたら
$ ./configure
$ make
とても時間がかかります。
管理者になって
# make install
/usr/local/binにインストールされます。

アンインストールは
# make uninstall
でできます。

3. guile-lib0.2.2をダウンロードします。
http://www.nongnu.org/guile-lib/download/
$ ./configure
$ make
管理者になって
# make install
アンインストールは
# make uninstall
でできます。

4. guile-rman のインストール
$ sh autogen.sh
$ ./configure
以上を行います。
guile-rman-master/src/Makefileを以下のように変更。

-I/usr/local/include/aqsisを
-I/usr/include/aqsis

-I/usr/local/includeを
-I/usr/local/include/guile/2.0

rispec.iを以下のように変更。
includeで検索し、
4行目ri.h
ri/ri.h

5行目rif.h
ri/rif.h

107行目ri_types.h
ri/ritypes.h

308行目aqsis/config.h
config.h

309行目ri.h
ri/ri.h

310行目rif.h
ri/rif.h

313行目ri.inl
ri/ri.inl

$ make
をします。
うまく行かない場合。
$ make 2>&1 | tee make.log
を使ってエラー確認、make.logをのぞいて確認すると良いです。

無事makeできたら、
管理者になって
# make install

アンインストールは
# make uninstall
でできます。

以下のサンプルを試してみましょう。simple.scmとして保存します。

#!/usr/bin/guile -s
!#

(use-modules (rman rispec))
(use-modules (rman utilities))

(RiBegin "simple.rib")
(RiDisplay "simple.tif" "file" "rgb")
(RiFormat 640 480 1)
(RiProjection "perspective" '("fov" 30))
(RiTranslate 0 0 5)
; (RiProgressHandler progress)
(RiPixelFilter RiBoxFilter 1 1)
(RiWorldBegin)
(RiLightSource "ambientlight" (list "intensity" 0.2))
(RiLightSource "distantlight" (list "intensity" 1.2 ))
(RiAttributeBegin)
(RiColor (Color 1.0 0.6 0.0))
(RiSurface "plastic")
(RiTransformBegin)
(RiRotate 90 1 0 0)
(RiSphere 1 -1 1 360)
(RiTransformEnd)
(RiAttributeEnd)
(RiWorldEnd)
(RiEnd)


$ guile simple.scm
と実行することで、simple.tifが出力されれば成功です。
simple.jpg

次はtest2.scmで保存します。

#!/usr/bin/guile -s
!#

(use-modules (rman rispec))
(use-modules (rman utilities))

(RiBegin "test2.rib")
(RiDisplay "sphere2.tif" "file" "rgb")
(RiFormat 640 480 1)
(RiProjection "perspective" '("fov" 40.0))
(RiTranslate 0 0 6)
; (RiProgressHandler progress)
(RiPixelFilter RiBoxFilter 1 1)
(RiWorldBegin)
(let ((o1 (Object (RiSphere 1 -1 1 360))))
(RiLightSource "ambientlight" (list "intensity" 0.2))
(RiLightSource "distantlight" (list "intensity" 1.2
"uniform point from" (Point 3 3 -3)))
(RiColor (Color 1.0 0.0 0.0))
(RiSurface "plastic")
(RiTranslate -2.0 0 0)
(RiObjectInstance o1)
(RiColor (Color 0.0 1.0 0.0))
(RiSurface "plastic")
(RiTranslate 2.0 0 0)
(RiObjectInstance o1)
(RiColor (Color 0.0 0.0 1.0))
(RiSurface "plastic")
(RiTranslate 2.0 0 0)
(RiObjectInstance o1))
(RiWorldEnd)
(RiEnd)

$ guile test2.scm
とやることで、sphere2.tifが出力されれば成功です。
sphere2.jpg
  • -
  • -
<< 44/50 >>