Ejemplo n.º 1
0
    def ray_intersect(self, orig, dir):
        # Regresa falso o verdadero si hace interseccion con una esfera

        # Formula para un punto en un rayo
        # t es igual a la distancia en el rayo
        # P = O + tD
        # P0 = O + t0 * D
        # P1 = O + t1 * D
        #d va a ser la magnitud de un vector que es
        #perpendicular entre el rayo y el centro de la esfera
        # d > radio, el rayo no intersecta
        #tca es el vector que va del orign al punto perpendicular al centro
        L = vectSubtract(self.center, orig)
        tca = vectDot(L, dir)
        l = vectNormal(L)  # magnitud de L

        d = (l**2 - tca**2)**0.5
        if d > self.radius:
            return None

        # thc es la distancia de P1 al punto perpendicular al centro
        thc = (self.radius**2 - d**2)**0.5
        t0 = tca - thc
        t1 = tca + thc
        if t0 < 0:
            t0 = t1

        if t0 < 0:  # t0 tiene el valor de t1
            return None

        # P = O + tD
        hit = vectAdd(orig, V3(t0 * dir.x, t0 * dir.y, t0 * dir.z))
        norm = vectSubtract(hit, self.center)
        norm_normal = vectNormal(norm)
        norm = V3(norm.x / norm_normal, norm.y / norm_normal,
                  norm.z / norm_normal)

        return Intersect(distance=t0, point=hit, normal=norm, sceneObject=self)
Ejemplo n.º 2
0
 def __init__(self, position=V3(0, 0, 0), _color=WHITE, intensity=1):
     self.position = position
     self.intensity = intensity
     self.color = _color
Ejemplo n.º 3
0
    def __init__(self, position, size, material):
        self.position = position
        self.size = size
        self.material = material
        self.planes = []

        halfSize = size / 2

        self.planes.append(
            Plane(np.add(position, V3(halfSize, 0, 0)), V3(1, 0, 0), material))
        self.planes.append(
            Plane(np.add(position, V3(-halfSize, 0, 0)), V3(-1, 0, 0),
                  material))

        self.planes.append(
            Plane(np.add(position, V3(0, halfSize, 0)), V3(0, 1, 0), material))
        self.planes.append(
            Plane(np.add(position, V3(0, -halfSize, 0)), V3(0, -1, 0),
                  material))

        self.planes.append(
            Plane(np.add(position, V3(0, 0, halfSize)), V3(0, 0, 1), material))
        self.planes.append(
            Plane(np.add(position, V3(0, 0, -halfSize)), V3(0, 0, -1),
                  material))
Ejemplo n.º 4
0
#
# Se carga el fondo de pantalla
# imagen: fondo.bmp
#
print(
    'Se va a cargar una escena, esta operación puede tardar unos minutos...\n')
print('Cargando fondo de la escena...')
fondo = Texture('./models/fondo.bmp')
r.pixels = fondo.pixels
print('Fondo cargado...')

#
# se agrega la camara
# se setea la posición inicial de los modelos respecto a la cámara
#
posModel = V3(0, 0, 200)
r.lookAt(posModel, V3(0, 0, 5))  #5,5,0

#
# Se agrega el modelo de la torre de agua con textura y shader.
# obj:      water_tower.bmp
# textura:  water_tower.obj
# shader:   static_matix
#
print('Cargando modelo torre de agua...')
r.active_texture = Texture('./models/water_tower.bmp')
r.active_shader = static_matrix
r.glLoadModel('./models/water_tower.obj', V3(0, -10, 450), V3(1, 1, 1),
              V3(0, 0, 0))
print('Torre de agua cargada...')
Ejemplo n.º 5
0
from gl import Raytracer, color, V2, V3
from obj import Obj, Texture
from sphere import Sphere, Material, PointLight, AmbientLight
import random

brick = Material(diffuse=color(0.8, 0.25, 0.25), spec=16)
stone = Material(diffuse=color(0.4, 0.4, 0.4), spec=32)
grass = Material(diffuse=color(0.5, 1, 0), spec=32)
glass = Material(diffuse=color(0.25, 1, 1), spec=64)

width = 256
height = 256
r = Raytracer(width, height)

r.pointLight = PointLight(position=V3(-2, 2, 0), intensity=1)
r.ambientLight = AmbientLight(strength=0.1)

r.scene.append(Sphere(V3(0, 0, -5), 1, brick))
r.scene.append(Sphere(V3(-0.5, 0.5, -3), 0.25, stone))
#r.scene.append( Sphere(V3(-1,-1, -5), 0.5, grass) )
#r.scene.append( Sphere(V3( 1,-1, -5), 0.5, glass) )

r.rtRender()

r.glFinish('output.bmp')
Ejemplo n.º 6
0
 def __init__(self, direction = V3(0,-1,0), _color = WHITE, intensity = 1):
     self.direction = direction / np.linalg.norm(direction)
     self.intensity = intensity
     self.color = _color
Ejemplo n.º 7
0
from gl import Render, color, V2, V3
from obj import Obj, Texture
from shaders import *

r = Render()
r.glCreateWindow(500, 500)

r.active_texture = Texture('./models/model.bmp')
r.active_shader = gourad

posModel = V3(0, 3, 0)
r.lookAt(posModel, V3(0, 0, -5))
r.glLoadModel('./models/model.obj', posModel, V3(2, 2, 2), V3(0, 0, 0))
r.glFinish('high_angle.bmp')

r.glClear()

posModel = V3(0, -3, 0)
r.lookAt(posModel, V3(0, 0, -5))
r.glLoadModel('./models/model.obj', posModel, V3(2, 2, 2), V3(0, 0, 0))
r.glFinish('low_angle.bmp')

r.glClear()

posModel = V3(0, 0, 0)
r.lookAt(posModel, V3(0, 0, -5))
r.glLoadModel('./models/model.obj', posModel, V3(2, 2, 2), V3(0, 0, 0))
r.glFinish('medium_angle.bmp')

r.glClear()
Ejemplo n.º 8
0
from gl import Render, color, V2, V3
from obj import Obj, Texture
from shaders import *

r = Render(1920, 1080)

#usamos la textura de dojo para hacer el fondo

texture = Texture('./models/dojo.bmp')

r.glBackground(texture)

#katana (phong)
r.active_shader = phong
posModel = V3(2, 0, -5)

r.active_texture = Texture('./models/Albedo.bmp')

r.loadModel('./models/katana.obj', posModel, V3(4, 4, 4), V3(0, 0, 270))

#cleaver (freedom)

r.active_shader = freedom
posModel = V3(-3, 0, -5)

r.active_texture = Texture('./models/cleaver.bmp')

r.loadModel('./models/cleaver.obj', posModel, V3(10, 10, 10), V3(90, 0, -30))

#dagger (infrarojo)
Ejemplo n.º 9
0
Archivo: room.py Proyecto: cesarvin/RT3
from obj import Obj, Texture, Envmap
from sphere import *
import random

wall = Material(diffuse=color(0.49, 0.67, 0.48), spec=16)
roof = Material(diffuse=color(0.66, 0.84, 0.67), spec=16)
floor = Material(diffuse=color(0.4, 0.35, 0.35), spec=16)
cubo = Material(diffuse=color(0.4, 0.69, 0.8), spec=32)

width = 500
height = 500
r = Raytracer(width, height)
r.glClearColor(0.2, 0.6, 0.8)
r.glClear()

r.pointLight = PointLight(position=V3(1, 1, 3), intensity=0.75)
r.ambientLight = AmbientLight(strength=0.1)

print('\nThis render gonna be legen—\n')

# cuarto
r.scene.append(Plane(V3(0, -15, 0), V3(0, 1, 0), floor))
r.scene.append(Plane(V3(0, 15, 0), V3(0, -1, 0), roof))
r.scene.append(Plane(V3(-15, 0, 0), V3(1, 0, 0), wall))
r.scene.append(Plane(V3(15, 0, 0), V3(-1, 0, 0), wall))
r.scene.append(Plane(V3(0, 0, -45), V3(0, 0, 1), wall))

# cubos
r.scene.append(AABB(V3(0, -2.1, -10), 1.5, cubo))
r.scene.append(AABB(V3(1.3, 1.8, -7), 0.75, cubo))
Ejemplo n.º 10
0
boxMat = Material(texture=Texture('box.bmp'))

earthMat = Material(texture=Texture('earthDay.bmp'))

width = 512
height = 512
r = Raytracer(width, height)
r.glClearColor(0.2, 0.6, 0.8)
r.glClear()

r.envmap = Envmap('envmap.bmp')

# Lights
#r.pointLights.append( PointLight(position = V3(-4,4,0), intensity = 0.5))
#r.pointLights.append( PointLight(position = V3( 4,0,0), intensity = 0.5))
r.dirLight = DirectionalLight(direction=V3(1, -1, -2), intensity=0.5)
r.ambientLight = AmbientLight(strength=0.1)

# Objects
#r.scene.append( Sphere(V3( 0, 0, -8), 2, brick) )
#r.scene.append( Sphere(V3( -0.5, 0.5, -5), 0.25, stone))
#r.scene.append( Sphere(V3( 0.25, 0.5, -5), 0.25, stone))

r.scene.append(AABB(V3(0, -3, -10), V3(5, 0.1, 5), boxMat))
#r.scene.append( AABB(V3(1.5, 1.5, -5), V3(1, 1, 1) , boxMat ) )
#r.scene.append( AABB(V3(-1.5, 0, -5), V3(1, 1, 1) , boxMat ) )

r.scene.append(Sphere(V3(0, 0, -8), 2, earthMat))

r.rtRender()
from gl import Render, color, V2, V3
from obj import Obj

import random

r = Render(1000, 1000)

r.loadModel('./models/natsuki.obj', V3(500, 500, 0), V3(300, 300, 300))

r.glFinish('output.bmp')
r.glZBuffer('zbuffer.bmp')
Ejemplo n.º 12
0
from gl import Render, color, V2, V3
from obj import Obj, Texture

import random

r = Render(1000,1000)

t = Texture('./models/model.bmp')
r.loadModel('./models/model.obj', V3(500,500,0), V3(300,300,300), t)

r.glFinish('output.bmp')
#r.glZBuffer('zbuffer.bmp')




from gl import Render, color, V2, V3
from obj import Obj, Texture

from shaders import *

r = Render(768, 432)

r.active_texture = Texture('./models/model.bmp')
r.active_shader = phong

posModel = V3(0, 0, -5)

# Medium shot

r.lookAt(posModel, V3(0, -1, 0))

r.loadModel('./models/model.obj', posModel, V3(1, 1, 1), V3(0, 0, 0))

r.glFinish('medium.bmp')

# Low angle

r = Render(768, 432)

r.active_texture = Texture('./models/model.bmp')
r.active_shader = phong

posModel = V3(0, 0, -5)

r.lookAt(posModel, V3(0, -5, 0))
Ejemplo n.º 14
0
import random

snowman = Material(diffuse=color(1, 1, 1), spec=16)
button = Material(diffuse=color(0, 0, 0), spec=32)
nose = Material(diffuse=color(1, 0.5, 0), spec=64)

width = 960
height = 1280

# width = 240
# height = 320

r = Raytracer(width, height)
r.glClearColor(0.3, 0.5, 0.8)

r.pointLight = PointLight(position=V3(-2, 2, 0), intensity=1)
r.ambientLight = AmbientLight(strength=0.1)

r.glClearColor(0.3, 0.5, 0.8)

print('\nThis render gonna be legen—\n')

r.scene.append(Sphere(V3(0.15, 1.6, -4), 0.05, button))
r.scene.append(Sphere(V3(-0.15, 1.6, -4), 0.05, button))
r.scene.append(Sphere(V3(0, 1.4, -3.9), 0.10, nose))

r.scene.append(Sphere(V3(0.20, 1.25, -4), 0.04, button))
r.scene.append(Sphere(V3(-0.08, 1.20, -4), 0.04, button))
r.scene.append(Sphere(V3(0.08, 1.20, -4), 0.04, button))
r.scene.append(Sphere(V3(-0.20, 1.25, -4), 0.04, button))
Ejemplo n.º 15
0
brick = Material(diffuse = color(0.8, 0.25, 0.25 ), spec = 16)
stone = Material(diffuse = color(0.4, 0.4, 0.4 ), spec = 32)
mirror = Material(spec = 64, matType = REFLECTIVE)

glass = Material(spec = 64, ior = 1.5, matType= TRANSPARENT) 


width = 256
height = 256
r = Raytracer(width,height)
r.glClearColor(0.2, 0.6, 0.8)
r.glClear()

r.envmap = Envmap('envmap.bmp')

r.pointLight = PointLight(position = V3(0,0,0), intensity = 1)
r.ambientLight = AmbientLight(strength = 0.1)

#r.scene.append( Sphere(V3( 1, 1, -10), 1.5, brick) )
#r.scene.append( Sphere(V3( 0, -1, -5),  1, glass) )
#r.scene.append( Sphere(V3(-3, 3, -10),  2, mirror) )

r.scene.append( Plane( V3(-2,-3,0), V3(1,1,0), stone))

#r.scene.append( AABB(V3(0, 1.5, -5), 1.5, stone ) )
r.scene.append( AABB(V3(1.5, -1.5, -5), 1.5, mirror ) )
r.scene.append( AABB(V3(-1.5, -1.5, -5), 1.5, glass ) )


r.rtRender()
from numpy import random

r = Render(2500, 1800)

for x in range(15, 2500 - 2):
    for y in range(15, 1800 - 2):
        size = random.randint(1, 1080)
        if size == 2 and x % 2 != 0 and y % 2 != 0:
            for i in range(1, 15):
                r.glVertex_coord(x, y)
                r.glVertex_coord(x + i, y)
                r.glVertex_coord(x, y + i)
                r.glVertex_coord(x - i, y)
                r.glVertex_coord(x, y - i)

posModel = V3(0, 0, -5)

r.lookAt(posModel, V3(0, 0, 0))

r.active_texture = Texture('./models/earthday.bmp')
r.active_shader = mutedColors
r.loadModel('./models/earth.obj', V3(-4, -2.5, -7), V3(0.003, 0.003, 0.003),
            V3(0, 0, 45))

r.active_texture = Texture('./models/spaceship.bmp')
r.active_shader = phong
r.loadModel('./models/spaceship.obj', V3(2, 1.4, -6), V3(0.003, 0.003, 0.003),
            V3(0, 0, -30))

r.active_texture = Texture('./models/rocket.bmp')
r.active_shader = toon
Ejemplo n.º 17
0
from gl import Render, color, V2, V3
from obj import Obj, Texture
import glMath

from shaders import *

import random

r = Render(1000, 1000)

r.active_texture = Texture('./models/earthDay.bmp')
r.active_texture2 = Texture('./models/earthNight.bmp')

r.active_shader = toon

luz = V3(0, 0, 1)
r.light = glMath.normalize(luz)

r.loadModel('./models/earth.obj', V3(500, 500, 0), V3(1, 1, 1))

r.glFinish('toon.bmp')