-
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.
TextureMaterial. Textured triangle example
- Loading branch information
Showing
6 changed files
with
77 additions
and
12 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# Example 16: Textured raytracing | ||
# | ||
# This time we render a triangle | ||
# TODO render sphere in this scene | ||
from pyrt.light import PointLight | ||
from pyrt.material.texturematerial import TextureMaterial | ||
from pyrt.math import * | ||
from pyrt.scene import * | ||
from pyrt.geometry import Sphere | ||
from pyrt.material import PhongMaterial | ||
from pyrt.camera import PerspectiveCamera | ||
from pyrt.renderer import SimpleRT | ||
|
||
from pyrt.renderer import RGBImage | ||
from pyrt.math import Vec2, Vec3 | ||
from pyrt.camera import PerspectiveCamera | ||
from pyrt.geometry import Triangle, Vertex | ||
from PIL import Image | ||
|
||
|
||
w = 320 | ||
h = 240 | ||
|
||
# Create a camera with width, height and field of view: | ||
camera = PerspectiveCamera(w, h, 60) | ||
|
||
# Set View matrix of camera: define where to look at | ||
camera.setView(Vec3(0, -10, 0), Vec3(0, 0, 0), Vec3(0, 0, 1)) | ||
|
||
# Create view-projection matrix (right to left) | ||
vp = camera.projection * camera.view | ||
|
||
# Create a scene | ||
scene = Scene() | ||
|
||
# Add a light to the scene | ||
scene.addLight(PointLight(Vec3(-1, -8, 1))) | ||
|
||
# Create a triangle | ||
t = Triangle(Vertex(position=(-5, 1, 0), texcoord=(0, 0)), | ||
Vertex(position=(0, 1, 5), texcoord=(1, 0)), | ||
Vertex(position=(5, 1, 0), texcoord=(1, 1)), | ||
material= | ||
TextureMaterial(texturepath='tex16.png')) | ||
|
||
# Add a sphere to the scene: | ||
scene.add(t) | ||
|
||
# Now tell the scene which camera we use | ||
scene.setCamera(camera) | ||
|
||
# Create a raytracer using "SimpleRT" | ||
engine = SimpleRT() | ||
|
||
# Render the scene: | ||
image = engine.render(scene) | ||
|
||
|
||
image.save("16.png") |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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