Wednesday, July 29, 2009

Structure SynthとSunflowで街頭の明かりがついた町並みを描画する

Structure SynthとSunflowで街頭の明かりがついた町並みを描画するには、以下のスクリプトを実行します。


1 * { x -100 z 100 } 3 * { x 40 color #e0e0e0 } 3 * { z -40 } block

rule block {
{ x -30 z -30 } streetlamp
{ x -30 z -20 } streetlampz
{ x -20 z -30 } streetlampx
{ x -10 z -30 } streetlampx
{ x 0 z -30 } streetlampx
{ x -20 z -20 } building
{ x -10 z -20 } building
{ x -0 z -20 } building
{ x -30 z -10 } streetlampz
{ x -20 z -10 } building
{ x -10 z -10 } building
{ x -0 z -10 } building
{ x -30 z -0 } streetlampz
{ x -15 z 0 } building1x2
{ x -0 z 0 } building
}

rule block {
{ x -30 z -30 } streetlamp
{ x -20 z -30 } streetlampx
{ x -10 z -30 } streetlampx
{ x 0 z -30 } streetlampx
{ x -30 z -20 } streetlampz
{ x -20 z -20 } building
{ x -10 z -20 } building
{ x -0 z -20 } building
{ x -30 z -10 } streetlampz
{ x -20 z -10 } building
{ x -10 z -10 ry 90 } building
{ x -0 z -10 } building
{ x -30 z 0 } streetlampz
{ x -20 z 0 } building
{ x -10 z 0 ry 90 } building
{ x -0 z 0 } building
}


rule building {
1 * { x -4 z -6 y 10.5 s 1 21 1 } 5 * { z 2 } box
1 * { x 4 z -6 y 10.5 s 1 21 1 } 5 * { z 2 } box
{ y 10.5 s 7 21 9 } box
1 * { y -3 s 9 1 9 } 8 * { y 3 } box
{ y 22 s 8 1 8 } box
}

rule building {
1 * { x -4 z -6 y 11 s 1 22 1 } 5 * { z 2 } box
1 * { x 4 z -6 y 11 s 1 22 1 } 5 * { z 2 } box
{ y 10.5 s 7 22 9 } box
1 * { y -2 s 9 1 9 } 12 * { y 2 } box
{ y 23 s 8 2 8 } box
{ y 24 s 6 1 6 } box
{ x 2 z 2 y 25 s 2 2 2 } box
}

rule building {
1 * { y -2 s 9 1 9 } 9 * { y 2 } box
1 * { x -5 z -5 y -1 } 8 * { y 2 } 9 * { x 1 } 9 * { z 1 } 1 * { s 0.95 } box
1 * { y 18 s 7 3 3 } box
}

rule building {
1 * { y -2 s 9 1 9 } 8 * { y 2 } box
1 * { x -5 z -5 y -1 } 7 * { y 2 } 9 * { x 1 } 9 * { z 1 } 1 * { s 0.95 } box
1 * { y 14 s 7 1 7 } 6 * { y 2 } box
1 * { x -4 z -4 y 13 } 6 * { y 2 } 7 * { x 1 } 7 * { z 1 } 1 * { s 0.95 } box
1 * { y 27 s 5 1 5 } box
}

rule building1x2 {
1 * { y -2 z -0.5 s 19 1 8 } 8 * { y 2 } box
1 * { x -10 z -5 y -1 } 7 * { y 2 } 19 * { x 1 } 8 * { z 1 } 1 * { s 0.95 } box
{ s 6 2 1 z 4 y 0.25 } box
}

rule streetlamp {
{ y 1 x 2.5 z 2.5 } sphere::light
{ y 1 x 2.5 z -2.5 } sphere::light
{ y 1 x -2.5 z 2.5 } sphere::light
{ y 1 x -2.5 z -2.5 } sphere::light
}

rule streetlampx {
{ y 1 x 5 z 2.5 } sphere::light
{ y 1 x 5 z -2.5 } sphere::light
{ y 1 x 2.5 z 2.5 } sphere::light
{ y 1 x 2.5 z -2.5 } sphere::light
{ y 1 x 0 z 2.5 } sphere::light
{ y 1 x 0 z -2.5 } sphere::light
{ y 1 x -2.5 z 2.5 } sphere::light
{ y 1 x -2.5 z -2.5 } sphere::light
{ y 1 x -5 z 2.5 } sphere::light
{ y 1 x -5 z -2.5 } sphere::light
}

rule streetlampz {
{ y 1 x 2.5 z 5 } sphere::light
{ y 1 x 2.5 z 2.5 } sphere::light
{ y 1 x 2.5 z 0 } sphere::light
{ y 1 x 2.5 z -2.5 } sphere::light
{ y 1 x 2.5 z -5 } sphere::light
{ y 1 x -2.5 z 5 } sphere::light
{ y 1 x -2.5 z 2.5 } sphere::light
{ y 1 x -2.5 z 0 } sphere::light
{ y 1 x -2.5 z -2.5 } sphere::light
{ y 1 x -2.5 z -5 } sphere::light
}

// 白色の地面
{ y -0.5 s 400 0.1 400 color white } box


Structure Synthでの出力画像


Sunflowでレンダリングする際、以下のテンプレートファイルを使用します。
以下のテンプレートではsphere::lightで指定した球を球形光源に置き換えます。


<template defaultExtension="Sunflow scene file (*.sc)" name="Sunflow" runAfter="%SUNFLOW%\sunflow.bat "$FILE" -o "$FILE.png"" >
<description>
night template.

Original template by Syntopia.
The Sunflow coloring was added by Tom Beddard ('subblue')
</description>
<primitive name="begin" ><![CDATA[
%photons {
% caustics 10000000 kd 64 0.5
%}

%% common settings
image {
resolution {width} {height}
aa 0 2
}

gi {
type ambocc
% bright { "sRGB nonlinear" 1 1 1 }
bright { "sRGB nonlinear" 0.5 0.6 0.9 }
dark { "sRGB nonlinear" 0 0 0 }
samples 64
maxdist 3.0
}

accel bih
filter mitchell
bucket 32 spiral

%% camera
camera {
type pinhole
eye {CamPosX} {CamPosY} {CamPosZ}
target {CamTargetX} {CamTargetY} {CamTargetZ}
up {CamUpX} {CamUpY} {CamUpZ}
fov {fov}
aspect {aspect}
}


%% scene background - comment out if not needed
background {
% color { "sRGB nonlinear" {BR} {BG} {BB} }
color { "sRGB nonlinear" 0.5 0.6 0.8 }
}


%% geometry
object {
shader none
transform col 0.001 0 0 0 0 0.001 0 0 0 0 0.001 0 0 0 0 1
type generic-mesh
name "Box"
points 8
1 1 1
1 0 1
0 0 1
0 1 1
0 1 0
0 0 0
1 0 0
1 1 0

triangles 12
0 3 2
0 2 1
2 3 4
2 4 5
3 0 7
3 7 4
0 1 6
0 6 7
1 2 5
1 5 6
5 4 7
5 7 6
normals none
uvs none
}
]]></primitive>
<primitive name="end" ><![CDATA[

]]></primitive>
<primitive name="box" ><![CDATA[
shader {
name "shader{uid}"
type diffuse
diff { "sRGB nonlinear" {r} {g} {b} }
}

instance {
name "{uid}"
geometry "Box"
transform col {matrix}
shader "shader{uid}"
}
]]></primitive>
<primitive name="sphere" ><![CDATA[
shader {
name "shader{uid}"
type diffuse
diff { "sRGB nonlinear" {r} {g} {b} }
}

object {
shader "shader{uid}"
type sphere
c {cx} {cy} {cz}
r {rad}
}
]]></primitive>
<primitive type="light" name="sphere" ><![CDATA[
light {
type spherical
color { "sRGB nonlinear" 0.900 0.900 0.700 }
radiance 4.0
center {cx} {cy} {cz}
radius {rad}
samples 16
}
]]></primitive>

</template>


Sunflowでの出力結果

No comments: