• 沒有找到結果。

Project #4: Ray Tracer Project #4: Ray Tracer

N/A
N/A
Protected

Academic year: 2022

Share "Project #4: Ray Tracer Project #4: Ray Tracer"

Copied!
12
0
0

加載中.... (立即查看全文)

全文

(1)

Project #4: Ray Tracer Project #4: Ray Tracer

A i 9/3 Assign: 9/3

Due: 11:59pm 9/8

Submission: send all your java sources in a zip file and send it to me. Note that the project is accumulated. p j You may update files in previous projects. Thus, for each submission, please include all files including ones p g from previous projects.

(2)

PointLight

public class PointLight { Point p;

Point p;

RGB intensity;

} }

(3)

Diffuse shading (Gouraud 1971)

• Applies to diffuse, Lambertian or matte surfaces

surfaces

(albedo)

( )

(4)

Shape

• Add material into shape

public abstract class Shape {

RGB rd;

public RGB getMaterial() { public RGB getMaterial() {

return new RGB(rd);

} }

(5)

Modify constructors for material

• For example,

Sphere(Point p, float r, RGB rd);

(6)

Scene file

Perspective -0.5 0.5 0.375 -0.375 640 480 PointLight 10.0 10.0 0.0 100.0 100.0 100.0g Sphere -1.0 -1.0 10.0 1.0 0.6 0.75 1.0

Triangle -5.0 1.1339746 15.696152 5.0 -3.8660254 7 035898 5 0 3 8660254 7 035898 0 0 0 8660254 7.035898 -5.0 -3.8660254 7.035898 0.0 0.8660254 - 0.5 0.0 0.8660254 -0.5 0.0 0.8660254 -0.5 0.8 0.8 0.8

(7)

Scene file

• Perspective left right top bottom width height

height

• Orthographic left right top bottom width heightg

• PointLight x y z r g b

• Sphere x y z radius r g bp y g

• Triangle p1 p2 p3 n1 n2 n3 r g b

• (p1 is a point; n1 is a vector; both(p1 is a point; n1 is a vector; both consist of three float)

(8)

RayTracer

public class RayTracer { Camera camera;

Camera camera;

Shape[] shape;

PointLight[] light;

PointLight[] light;

int ShapeCount;

int ShapeCount;

int LightCount;

} }

Java RayTracer scene file image file Java RayTracer scene_file image_file

(9)

Main loop

for (y=0; y<height; y++)

for (x=0; x<width; x++) { for (x=0; x<width; x++) {

Ray r=camera.GenerateRay(x, y);

Intersection isect=null new isect;

Intersection isect=null,new_isect;

for (i=0; i<ShapeCount; i++) {

new isect=shape[i] Intersect(r);

new_isect=shape[i].Intersect(r);

if (new_sect!=null) isect = new isect;

isect new_isect;

}

if (isect!=null) if (isect! null)

camera.AddSample(x, y,

isect.Shade(light, LightCount)) isect.Shade(light, LightCount)) }

(10)

Shade intersections

public class Intersection {

RGB Shade(PointLight[] light, int count)

int count) }

for (int i=0; i<count; i++) {

if (dot(n,lv)>0) shade +=

shade + … }

return shade;

(11)

Example

(12)

Notes

• You could support add, mul and scaling for RGB B f l b t h ki ( 1 2 3) 1

• Be careful about checking (s1+s2+s3)==1

• It is usually better to check whether

abs(s1+s2+s3-1)<threshold

參考文獻

相關文件

• The Java programming language is based on the virtual machine concept. • A program written in the Java language is translated by a Java compiler into Java

Place the code elements in order so that the resulting Java source file will compile correctly, resulting in a class called “com.sun.cert.AddressBook”。..

[r]

[r]

[r]

coordinates consisting of the tilt and rotation angles with respect to a given crystallographic orientation A pole figure is measured at a fixed scattering angle (constant d

圖中A部分為加法器的電路,其中 L型鋁條上裝置一個BNC接頭作為 AC IN,兩個端子作為DC

存放檔案的 inode 資訊, inode 一旦滿了也一樣會 無法儲存新檔案, inode 會告知檔案所使用的 data block 位置。. Q :如何知道那些 inode 和