-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'refraction' of https://github.com/slmtnm/pyRT into refr…
…action
- Loading branch information
Showing
3 changed files
with
51 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,49 @@ | ||
from pyrt.geometry.sphere import Sphere | ||
from typing import List | ||
from pyrt.math import * | ||
from pyrt.light import * | ||
from pyrt.geometry import Triangle, Vertex, Sphere | ||
from pyrt.geometry.vertex import Vertex | ||
from pyrt import material | ||
from pyrt.math import Vec3 | ||
from pyrt.scene import Scene | ||
from pyrt.light import PointLight | ||
from pyrt.geometry import Sphere, Triangle | ||
from pyrt.material import PhongMaterial | ||
from pyrt.camera import PerspectiveCamera | ||
from pyrt.renderer import SimpleRT | ||
from pyrt.scene import Scene | ||
from pyrt.renderer import SimpleRT | ||
from PIL import Image | ||
|
||
floormaterial = PhongMaterial(color=Vec3(0.5,0.5,0.5)) | ||
sphere0material = PhongMaterial(color=Vec3(1.,0.,0.), transparency=0.5) | ||
sphere1material = PhongMaterial(color=Vec3(0.,0.,1.), transparency=0.1, reflectivity=0.5) | ||
sphere2material = PhongMaterial(color=Vec3(0.,1.,0.)) | ||
width = 1000 | ||
height = 800 | ||
|
||
camera = PerspectiveCamera(640, 480, 45) | ||
camera.setView(Vec3(0.,-10.,0.0), Vec3(0.,0.,0.), Vec3(0.,0.,1.)) | ||
camera = PerspectiveCamera(width, height, 60) | ||
camera.setView(Vec3(0,-10,0), Vec3(0,0,0), Vec3(0,0,1)) | ||
|
||
scene = Scene() | ||
scene.add(Triangle(Vertex(position=(0, 0, 0)), | ||
Vertex(position=(0, 5, 0)), | ||
Vertex(position=(1, 5, 0)), material=PhongMaterial())) | ||
scene.setCamera(camera) | ||
scene.addLight(PointLight(Vec3(0,0,15))) | ||
scene.addLight(PointLight(Vec3(-1,-8,1))) | ||
|
||
# Add "floor" | ||
# A = Vertex(position=(-5.0, -5.0, 0.0)) | ||
# B = Vertex(position=( 5.0, -5.0, 0.0)) | ||
# C = Vertex(position=( 5.0, 5.0, 0.0)) | ||
# D = Vertex(position=(-5.0, 5.0, 0.0)) | ||
# scene.add(Triangle(A,B,C, material=floormaterial)) | ||
scene.add( | ||
Triangle( | ||
Vertex(position=(-1.5,10,0)), | ||
Vertex(position=(3.5,10,0)), | ||
Vertex(position=(1,10,5.)), | ||
material=PhongMaterial(color=Vec3(1,1,1)) | ||
) | ||
) | ||
|
||
# Add spheres | ||
scene.add(Sphere(center=Vec3(0,-5.5,0), radius=1, material=sphere0material)) | ||
scene.add(Sphere(center=Vec3(0,-0.5,0), radius=1, material=sphere1material)) | ||
scene.add(Sphere(center=Vec3(3,-0.5,0), radius=1, material=sphere2material)) | ||
scene.add(Sphere(center=Vec3(-3,-0.5,0), radius=0.5, material=sphere2material)) | ||
#scene.add( | ||
# Sphere( | ||
# center=Vec3(1, 10, 0), | ||
# radius = 1.5, | ||
# material=PhongMaterial(color=Vec3(1, 1, 0)) | ||
# ) | ||
#) | ||
|
||
imgdata = SimpleRT(shadow=True, iterations=7).render(scene) | ||
imgdata.save('a.png') | ||
scene.add( | ||
Sphere( | ||
center=Vec3(0, 0, 0), | ||
radius=1.5, | ||
material=PhongMaterial(color=Vec3(.9, .9, .9), transparency=0.4, refraction=1.33) | ||
) | ||
) | ||
|
||
scene.setCamera(camera) | ||
engine = SimpleRT(iterations=10) | ||
image = engine.render(scene) | ||
image.save("a.png") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters