-
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 pull request #5 from zhenyatos/4-mipmap
4 mipmap
- Loading branch information
Showing
10 changed files
with
98 additions
and
9 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
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,67 @@ | ||
# Example 17: Textured raytracing | ||
# | ||
# This time we render a triangle and scene with mipmaps | ||
# Used textures contain funny digits | ||
# Digit corresponds to level of detalization | ||
|
||
from pyrt.light import PointLight | ||
from pyrt.scene import * | ||
from pyrt.material.texturematerial import TextureMaterial | ||
from pyrt.camera import PerspectiveCamera | ||
from pyrt.renderer import SimpleRT | ||
|
||
from pyrt.renderer import RGBImage | ||
from pyrt.math import Vec3 | ||
from pyrt.geometry import Triangle, Vertex | ||
import moviepy.editor as mpy | ||
|
||
|
||
def make_frame(t): | ||
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, -t - 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(0, -2, 0))) | ||
|
||
# Create a triangle | ||
t1 = Triangle(Vertex(position=(-5, -4, 5), texcoord=(0, 0)), | ||
Vertex(position=(5, -4, 5), texcoord=(1, 0)), | ||
Vertex(position=(5, -4, -5), texcoord=(1, 1)), | ||
material= | ||
TextureMaterial(texturepath=['tex17-1.png', 'tex17-2.png'])) | ||
|
||
t2 = Triangle(Vertex(position=(-5, -4, 5), texcoord=(0, 0)), | ||
Vertex(position=(5, -4, -5), texcoord=(1, 1)), | ||
Vertex(position=(-5,-4, -5), texcoord=(0, 1)), | ||
material= | ||
TextureMaterial(texturepath=['tex17-1.png', 'tex17-2.png'])) | ||
|
||
# Add triangle and sphere to the scene: | ||
scene.add(t1) | ||
scene.add(t2) | ||
|
||
# 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) | ||
return image.data | ||
|
||
|
||
clip = mpy.VideoClip(make_frame, duration=10) | ||
clip.write_gif("17.gif",fps=20) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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