Displacement Map
สร้างฉากใต้ทะเล โดยใช้ Displacement Map
Chamferbox
ขั้นตอนการสร้าง เตียง ผ้าคลุมเตียง หมอนใบนั้น
Compesite Map
ขั้นตอนการสร้างวัสดุ น้ำ Compesite Map

[Introduction to Shading Language Part 3]
ตอนนี้เราจะพูดกันถึงเรื่อง Procedural Texturing...
มันคืออะไร...
ลองดูตัวอย่างก่อนครับ

เสาที่สร้างด้วย NURBS อย่างง่ายๆ และแสง 3 ดวง

วาง Coordinate system ของ RAT เอาไว ้ในกรณีนี้Coordinate system ทำหน้าที่คล้าย Place3D ของ Maya ครับ คือทำ หน้าที่วางตำแหน่งให้กับ texture แบบ 3D

สร้าง Blin หนึ่งอัน และต่อ diffuse coefficient และ specular rolloff เข้ากับ oakgrain

manifold ต่อเข้ากับ SurfacePoint

ใส่ชื่อ Shape Node ของ Coordinate system ลง ในที่นี้ก็ชื่อว่า mtorCoordSysShape และก็ใส่คำสั่ง coordsys ลงไปข้างหน้า เพื่อบอก slim ว่านี่คือ Coordinate system
attach shader เข้ากับ object และ render ออกมาจะได้แบบนี้

OakGrain ที่เราใช้ไปคือ Procedural Texture ครับ เป็น texture ที่ไม่ได้เกิดจากการวาดภาพ แต่เกิดจากสมการทางคณิตศาสตร ์ทำให Procedural texture มีข้อดีหลายอย่างด้วยกัน เช่น procedural texture มีความละเอียดสูงเสมอ และเราสามารถเพิ่มรายละเอียดความถี่สูง เข้าไปได ้โดย ไม่เปลือง memory procedural texture ไม่มีพื้นที่สิ้นสุด เราสามารถสร้าง procedural texture ที่มีขนาดใหญ่โดยที่ลายไม่ซํ้ากันเลยก็ได procedural texture ไม่ต้องใช harddisk ในการเก็บข้อมูล
แต่ข้อเสียก็มีอยู่หลายอย่างเช่นกัน เช่น ยากในการปรับแต่ง procedural texture ให้ได้ลายที่ต้องการ เนื่องจากเป็นการเขียน สมการทางคณิตศาสตร จึงทำให้แก้ไขเปลี่ยน แปลงยากมาก ต่างจาก texture ธรรมดาที่เราสามารถวาดลงไปได้เลย
จากข้อดีและข้อเสีย ดังกล่าว ทำให้การใช้งานของ procedural texture ต่างจาก texture ธรรมดาพอสมควรโดยปกติแล้วนิยมใช procedural texture เพื่อสร้างลวดลาย (pattern) ที่ไม่ซํ้ากัน เช่นทำให้ลายของพื้นดินไม่เหมือนกันทั้งแผ่น เป็นต้น หรือใช้ทำลาย สำหรับ effect ต่างๆ เช่นไฟ ควัน และอื่นๆอีก ขึ้นอยู่กับความคิดในการประยุกต์ใช้งานของแต่ละคน
procedural texture มีทั้งแบบ 2D,3D และ 4D 2D procedural texture ใช้ค่า s,t (คล้ายค่า uv ของ Maya) เพื่อกำหนดตำหน่งสร้าง pattern ขึ้นมา ดังนั้น procedural texture
แบบนี้จะวิ่งตามแนวของ UV เหมือนกับ 2D texture ของ Maya นั่นเอง การใช procedural texture แบบนี้จึงต้องมีการคลี่UV ซะ ก่อน 3D procedural texture ใชค่า point p(x,y,z) เป็นตัวกำหนดตำแหน่งเพื่อสร้างลวดลายขึ้นมา เช่น OakGrain ที่เราใช้ด้านบน ดัง
นั้น texture แบบนี้จะไม่สนค่า UV object ที่นำมาใช้จึงไม่จำเป็นต้องคลี่UV แต่ต้องการ Coordinate system เพื่อกำหนดค่า tranform (tranlate, rotate, scale) ดังนั้นลายจะใหญ่หรือเล็กขึ้นกับ Coordinate system 4D procedural texture คือ 3D procedural texture ที่มีการเปลี่ยแปลงไปตามเวลา เราจะลองสร้าง procedural texture กันครับโดยจะลองทำ checker หรือลายตาหมากรุก
ลองดูcode กันเลยครับ

slim 1 extensions pixardb

{ extensions pixar pxsl

{ template color schecker

{

parameter color color1 {
detail varying
default {1 1 1}
}
parameter color color2 {
detail varying
default {0 0 0}
}
parameter float repeats {
detail varying
default {2}
}
parameter float repeatt {
detail varying
default {2}
}
collection manifold manifold {
detail mustvary "pixar,SurfacePoint"
state locked
parameter point p {
detail mustvary
}
parameter vector dpu {
detail mustvary
}
parameter vector dpv {
detail mustvary
}
}
parameter color result {
access output
display hidden
}
RSLFunction {
void pxslschecker (
color c1;
color c2;
float repeats;
float repeatt;
point p;
vector dpu;
vector dpv;
output color res; ) {
extern float s;
extern float t;
float css = mod(s*repeats,1);
float ctt = mod(t*repeatt,1);
if (ctt>=0.5) {
css = 1- css;
}
if (css>=0.5) {
res = c1;
} else
res = c2;
}
}
}
}
}

}
จาก code มีการเรียกค่า s,t มาใช้งาน
extern float s; extern float t;
โดยใช้คำสั่ง extern
float css = mod(s*repeats,1); float ctt = mod(t*repeatt,1);
กำหนดตัวแปล css และ ctt เพื่อสร้างลายให้กับทิศ s และ t
if (ctt>=0.5) {
css = 1- css;
}
if (css>=0.5) {
res = c1;
} else
res = c2;
}
กำหนดเงื่อนไขเพื่อใส่สีลงไปแบบสลับช่อง
เรียกเข้าไปใน slim และต่อเข้ากับ shader ครับ

ในที่นี้ผมต่อเข้ากับ ceramic ครับ

ทดสอบ shader สร้าง object ขึ้นมาและใส่ไฟลงไปในฉาก

ออกมาแบบนี้เหมือนกับ checker ของ Maya นั่นเองครับ จาก code เราใช้ค่า s,t เพื่อกำหนดตำแหน่งของการเกิดลาย จึงทำให้เป็น 2D procedural texture ลายจะวิ่งตามแนวของ UV
ลองมาทำ 3D procedural texture กันบ้างครับ
slim 1 extensions pixardb {
extensions pixar pxsl {
template color schecker3d {
parameter color color1 {
detail varying
default {1 1 1}
}
parameter color color2 {
detail varying
default {0 0 0}
}
parameter float repeatx {
detail varying
default {2}
}
parameter float repeaty {
detail varying
default {2}
}
parameter float repeatz {
detail varying
default {2}
}
collection manifold manifold {
detail mustvary "pixar,SurfacePoint"
state locked
parameter point p {
detail mustvary

}
parameter vector dpu {
detail mustvary
}
parameter vector dpv {
detail mustvary
}
}
parameter color result {
access output
display hidden
}
RSLFunction {
void pxslschecker3d (
color c1;
color c2;
float repeatx;
float repeaty;
float repeatz;
point p;
vector dpu;
vector dpv;
output color res; ) {
float cxx = mod(xcomp(p)*repeatx,1);
float cyy = mod(ycomp(p)*repeaty,1);
float czz = mod(zcomp(p)*repeatz,1);
if (cyy>=0.5) {
cxx = 1- cxx;
}
if (czz>=0.5) {
cxx = 1- cxx;
}
if (cxx>=0.5) {
res = c1;
} else
res = c2;
}
}
}
}
}
}
จาก code เราจะเห็นการใช้งาน point p
float cxx = mod(xcomp(p)*repeatx,1); float cyy = mod(ycomp(p)*repeaty,1); float czz = mod(zcomp(p)*repeatz,1);
นำ component x,y,z มาใช้งาน ผ่าน function xcomp(p),ycomp(p),zcomp(p) ครับ
if (cyy>=0.5) { cxx = 1- cxx; } if (czz>=0.5) { cxx = 1- cxx; } if (cxx>=0.5) { res = c1; } else res = c2; }

ส่วนตรงนี้ก็เป็นการกำหนดเงื่อนไขในการลงสีคล้ายกับ แบบ 2D ครับ เสร็จแล้วก็โหลดเข้าไปใน slim เช่นเคย

มีค่า reapeat x,y,z แทนที่จะเป็น s,t เหมือนกับแบบ 2D หมายถึงเราสามารถปรับไดทั้ง 3 แกนนั่นเองครับ

สลับ texture มาเป็นตัวใหม่ที่เราสร้างขึ้นมา

ลายที่ได้ออกมาก็จะไม่ขึ้นกับ UV แต่จะขึ้นกับค่า Coordinate system แทนครับ มาลองใช Coordinate system กันดู

สร้าง Coordinate system โดยไปที่renderman>> new Coordinate system จะได้แผ่นสี่เหลี่ยมมาหนึ่งอัน

เปลี่ยน display mode เป็น 3 ใช scale และ rotate ตามความเหมาะสม และจดค่า Shape ของ Coordinate system เอาไว ้ในที่นี้คือ mtorCoordSysShape

ต่อ surface point เข้ากับ checker3d ที่เราสร้างขึ้นมาครับ

ใส่ค่า mtorCoordSysShape ลงไปในช่อง Space และเติม coordsys ลงไปเพื่อแสดงว่า mtorCoordSysShape เป็น Coordinate system

render ดูอีกครั้งก็จะได้แบบนี้ครับ ขนาดของลายใหญ่ขึ้น และมีการหมุนตาม Coordinate system ที่เราสร้างขึ้นมา Procedural texture เป็นทางเลือกที่ดีในการสร้าง pattern ครับ เมื่อใช้ผสมกับ texture แบบธรรมดา (painted texture) ก็จะ สามารถสร้างงานคุณภาพสูงออกมาได ้เช่นเคย ถ้ามีข้อเสนอ และสงสัย mail มาได้เลยครับ xteapot@hotmail.com

<<Back