Ejemplo n.º 1
0
def raycast(tile):
    sampler = ren.get_sampler()
    camera = ren.get_camera()
    film = ren.get_film()

    shapes = ren.isect_shapes()
    isect = renmas.shapes.isect #intersection rutine
    shade = renmas.core.shade

    background = renmas.core.Spectrum(0.00, 0.00, 0.00) 
    hp2 = renmas.shapes.HitPoint()
    hp2.spectrum = background

    sample = renmas.samplers.Sample()
    x, y, width, height = tile
    sampler.tile(x, y, width, height)

    while True:
        sam = sampler.get_sample(sample)
        if sam is None: break 
        ray = camera.ray(sample)
        hp = isect(ray, shapes)

        if hp is None:
            film.add_sample(sample, hp2) #background
        else:
            hp.wo = ray.dir * -1.0
            shade(hp)
            film.add_sample(sample, hp) #background
Ejemplo n.º 2
0
def raycast(tile):
    sampler = ren.get_sampler()
    camera = ren.get_camera()
    film = ren.get_film()

    shapes = ren.isect_shapes()
    isect = renmas.shapes.isect  #intersection rutine
    shade = renmas.core.shade

    background = renmas.core.Spectrum(0.00, 0.00, 0.00)
    hp2 = renmas.shapes.HitPoint()
    hp2.spectrum = background

    sample = renmas.samplers.Sample()
    x, y, width, height = tile
    sampler.tile(x, y, width, height)

    while True:
        sam = sampler.get_sample(sample)
        if sam is None: break
        ray = camera.ray(sample)
        hp = isect(ray, shapes)

        if hp is None:
            film.add_sample(sample, hp2)  #background
        else:
            hp.wo = ray.dir * -1.0
            shade(hp)
            film.add_sample(sample, hp)  #background
Ejemplo n.º 3
0
def raycast_asm():
    sampler = ren.get_sampler()
    camera = ren.get_camera()
    film = ren.get_film()
    lst_lights = ren.lst_lights()
    shapes = ren.lst_shapes()
    isect = renmas.shapes.isect  #intersection rutine
    shade = renmas.core.shade

    background = renmas.core.Spectrum(0.05, 0.05, 0.05)
    hp2 = renmas.shapes.HitPoint()
    hp2.spectrum = background

    tile = next_tile()
    if tile is None:
        global image_saved
        if not image_saved:
            save_image(film, "Image5.png")
            image_saved = True
        return None
    sample = renmas.samplers.Sample()
    x, y, width, height = tile
    sampler.tile(x, y, width, height)
    start = time.clock()

    runtime.run("raycast")  #100% rendering in assembly language

    blt_float_img_to_window(0, 0, film.image, win)
    end = time.clock()
    global duration
    duration = duration + (end - start)
    print("Renderiranje jednog tile je trajalo", end - start, duration)
    return True
Ejemplo n.º 4
0
def raycast_asm():
    sampler = ren.get_sampler()
    camera = ren.get_camera()
    film = ren.get_film()
    lst_lights = ren.lst_lights()
    shapes = ren.lst_shapes()
    isect = renmas.shapes.isect #intersection rutine
    shade = renmas.core.shade

    background = renmas.core.Spectrum(0.05, 0.05, 0.05) 
    hp2 = renmas.shapes.HitPoint()
    hp2.spectrum = background

    tile = next_tile()
    if tile is None: 
        global image_saved
        if not image_saved:
            save_image(film, "Image5.png")
            image_saved = True
        return None
    sample = renmas.samplers.Sample()
    x, y, width, height = tile
    sampler.tile(x, y, width, height)
    start = time.clock()

    runtime.run("raycast") #100% rendering in assembly language

    blt_float_img_to_window(0, 0, film.image, win)
    end = time.clock()
    global duration
    duration = duration + (end - start)
    print("Renderiranje jednog tile je trajalo", end - start, duration)
    return True
Ejemplo n.º 5
0
def path_tracer(tile):
    sampler = ren.get_sampler()
    camera = ren.get_camera()
    film = ren.get_film()

    sample = renmas.samplers.Sample()
    x, y, width, height = tile
    sampler.tile(x, y, width, height)

    runtime.run("path_tracer") #100% rendering in assembly language
Ejemplo n.º 6
0
def raycast():
    sampler = ren.get_sampler()
    camera = ren.get_camera()
    film = ren.get_film()
    lst_lights = ren.lst_lights()
    shapes = ren.lst_shapes()
    #isect = renmas.shapes.isect #intersection rutine
    isect = grid.isect
    shade = renmas.core.shade

    background = renmas.core.Spectrum(0.00, 0.00, 0.00)
    hp2 = renmas.shapes.HitPoint()
    hp2.spectrum = background

    tile = next_tile()
    if tile is None:
        global image_saved
        if not image_saved:
            save_image(film, "Image5.png")
            print("Slika je spremljena")
            image_saved = True
        return None
    sample = renmas.samplers.Sample()
    x, y, width, height = tile
    sampler.tile(x, y, width, height)
    start = time.clock()

    while True:
        sam = sampler.get_sample(sample)
        if sam is None: break
        ray = camera.ray(sample)
        #hp = isect(ray, shapes, 999999.0)
        hp = isect(ray)

        if hp is None:
            film.add_sample(sample, hp2)  #background
        else:
            hp.wo = ray.dir * -1.0
            shade(hp)
            film.add_sample(sample, hp)  #background

    blt_float_img_to_window(0, 0, film.image, win)
    end = time.clock()
    global duration
    duration = duration + (end - start)
    print("Renderiranje jednog tile je trajalo", end - start, duration)
    return True
Ejemplo n.º 7
0
def raycast():
    sampler = ren.get_sampler()
    camera = ren.get_camera()
    film = ren.get_film()
    lst_lights = ren.lst_lights()
    shapes = ren.lst_shapes()
    #isect = renmas.shapes.isect #intersection rutine
    isect = grid.isect
    shade = renmas.core.shade

    background = renmas.core.Spectrum(0.00, 0.00, 0.00) 
    hp2 = renmas.shapes.HitPoint()
    hp2.spectrum = background

    tile = next_tile()
    if tile is None: 
        global image_saved
        if not image_saved:
            save_image(film, "Image5.png")
            print("Slika je spremljena")
            image_saved = True
        return None
    sample = renmas.samplers.Sample()
    x, y, width, height = tile
    sampler.tile(x, y, width, height)
    start = time.clock()
    
    while True:
        sam = sampler.get_sample(sample)
        if sam is None: break 
        ray = camera.ray(sample)
        #hp = isect(ray, shapes, 999999.0)
        hp = isect(ray)

        if hp is None:
            film.add_sample(sample, hp2) #background
        else:
            hp.wo = ray.dir * -1.0
            shade(hp)
            film.add_sample(sample, hp) #background

    blt_float_img_to_window(0, 0, film.image, win)
    end = time.clock()
    global duration
    duration = duration + (end - start)
    print("Renderiranje jednog tile je trajalo", end - start, duration)
    return True
Ejemplo n.º 8
0
def path_tracer(tile):
    sampler = ren.get_sampler()
    camera = ren.get_camera()
    film = ren.get_film()

    shapes = ren.isect_shapes()
    isect = renmas.shapes.isect  #intersection rutine
    shade = renmas.core.shade

    background = renmas.core.Spectrum(0.00, 0.00, 0.00)
    hp2 = renmas.shapes.HitPoint()
    hp3 = renmas.shapes.HitPoint()
    hp2.spectrum = background

    sample = renmas.samplers.Sample()
    x, y, width, height = tile
    sampler.tile(x, y, width, height)

    Lr = []  #reflection coefficient
    Ld = []  #direct light
    transmitance = 1.0
    cur_depth = 0
    max_depth = 4

    #current implementation stop tracing path when we hit emitter
    while True:
        sam = sampler.get_sample(sample)
        if sam is None: break
        ray = camera.ray(sample)
        hp = isect(ray, shapes)

        if hp is None:
            film.add_sample(sample, hp2)  #background
            continue

        hp.wo = ray.dir * -1.0
        shade(hp)
        kr = hp.brdf * (1.0 / hp.pdf) * hp.ndotwi
        transmitance *= kr.r  #FIXME take component that has maximum value
        Lr.append(kr)
        Ld.append(hp.spectrum)

        cur_depth = 1
        ray.dir = hp.wi  #in wi is next direction
        ray.origin = hp.hit_point
        if hp.le.r > 0.01:  #primiray ray hit emitter - stop path
            hp.spectrum = hp.le
            film.add_sample(sample, hp)
            Lr = []
            Ld = []
            transmitance = 1.0
            cur_depth = 0
            continue

        Le = renmas.core.Spectrum(0.00, 0.00, 0.00)

        while True:
            if cur_depth == max_depth: break
            if transmitance < 0.0001: break
            hp = isect(ray, shapes)
            if hp is None: break
            hp.wo = ray.dir * -1.0
            shade(hp)
            if hp.le.r > 0.0001:
                #Le = hp.le
                break  #we hit emiter FIXME - we dont't have to stop think for better implementation !!!!
            kr = hp.brdf * (1.0 / hp.pdf) * hp.ndotwi
            Lr.append(kr)
            Ld.append(hp.spectrum)
            ray.dir = hp.wi  #in wi is next direction
            ray.origin = hp.hit_point
            transmitance *= kr.r  #FIXME take component that has maximum value
            cur_depth += 1

        tmp_spec = Le
        for i in range(cur_depth):

            brdf = Lr.pop()
            ld = Ld.pop()
            tmp_spec = tmp_spec.mix_spectrum(brdf) + ld

        hp3.spectrum = tmp_spec
        film.add_sample(sample, hp3)

        Lr = []
        Ld = []
        transmitance = 1.0
        cur_depth = 0
Ejemplo n.º 9
0
    _background: ; add background sample to film
    mov eax, background
    mov ebx, sam
    call add_sample

    jmp _next_sample

    
    _end_sampling:
    mov dword [end_sam], 0
#END
"""

ren.prepare_for_rendering()
runtime = Runtime()
ren.get_sampler().get_sample_asm(runtime, "get_sample")
ren.get_camera().ray_asm(runtime, "generate_ray")

renmas.shapes.linear_isect_asm(runtime, "scene_isect", ren.dyn_arrays())
renmas.shapes.visible_asm(runtime, "visible", "scene_isect")
renmas.core.generate_shade(runtime, "shade", "visible")
ren.get_film().add_sample_asm(runtime, "add_sample")

asm = renmas.utils.get_asm()
mc = asm.assemble(ASM)
ds = runtime.load("path_tracer", mc)

def build_runtime():
    runtime = Runtime()
    sam = renmas.samplers.RandomSampler(800, 800, n=200000, pixel=0.8)
    sam.get_sample_asm(runtime, "get_sample")
Ejemplo n.º 10
0
    ; eax = pointer_to_ray, ebx = pointer_to_hitpoint
    mov eax, r1
    mov ebx, hp
    call scene_isect 
    mov dword [hit], eax

    jmp pocetak

    _end_sampling:
    mov dword [end_sam], 0
#END
"""

build_scene()

sampler = ren.get_sampler()
sampler.tile(0, 0, WIDTH, HEIGHT)
camera = ren.get_camera()

def get_runtime():
    runtime = Runtime()
    sampler.get_sample_asm(runtime, "get_sample")
    camera.ray_asm(runtime, "generate_ray")

    dyn_arrays = ren.dyn_arrays()
    renmas.shapes.linear_isect_asm(runtime, "scene_isect", dyn_arrays)
    return runtime

runtime = get_runtime()
asm = renmas.utils.get_asm()
mc = asm.assemble(ASM)
Ejemplo n.º 11
0
def raycast():
    sampler = ren.get_sampler()
    camera = ren.get_camera()
    film = ren.get_film()
    lst_lights = ren.lst_lights()

    shapes = ren.isect_shapes()
    isect = renmas.shapes.isect  #intersection rutine
    shade = renmas.core.shade
    recursion_depth = 3

    background = renmas.core.Spectrum(0.00, 0.00, 0.00)
    hp2 = renmas.shapes.HitPoint()
    hp2.spectrum = background

    tile = next_tile()
    if tile is None:
        global image_saved
        if not image_saved:
            save_image(film, "Image5.png")
            print("Slika je spremljena")
            image_saved = True
        return None
    sample = renmas.samplers.Sample()
    x, y, width, height = tile
    sampler.tile(x, y, width, height)
    start = time.clock()

    while True:
        sam = sampler.get_sample(sample)
        if sam is None: break
        ray = camera.ray(sample)
        hp = isect(ray, shapes, 999999.0)

        if hp is None:
            hp2.spectrum = background
            film.add_sample(sample, hp2)  #background
            continue

        Ld1, Brdf1 = calc_brdf(hp, ray)
        hp = isect(ray, shapes, 999999.0)
        if hp is None:
            hp2.spectrum = Ld1
            film.add_sample(sample, hp2)
            continue

        Ld2, Brdf2 = calc_brdf(hp, ray)
        hp = isect(ray, shapes, 999999.0)
        if hp is None:
            hp2.spectrum = Ld1 + Ld2.mix_spectrum(Brdf1)
            film.add_sample(sample, hp2)
            continue

        Ld3, Brdf3 = calc_brdf(hp, ray)
        spectrum = Ld3.mix_spectrum(Brdf2) + Ld2
        spectrum = spectrum.mix_spectrum(Brdf1) + Ld1
        hp.spectrum = spectrum
        film.add_sample(sample, hp)

    blt_float_img_to_window(0, 0, film.image, win)
    end = time.clock()
    global duration
    duration = duration + (end - start)
    print("Renderiranje jednog tile je trajalo", end - start, duration)
    return True
Ejemplo n.º 12
0
    ren.create_triangle((0.291, 0.000, 0.296), (0.291, 0.330, 0.296),
                        (0.133, 0.330, 0.247), idx)
    ren.create_triangle((0.133, 0.330, 0.247), (0.133, 0.000, 0.247),
                        (0.291, 0.000, 0.296), idx)


build_scene()
isect = renmas.shapes.isect  #intersection rutine

#ALGORIHM RayCast

background = renmas.core.Spectrum(0.05, 0.05, 0.05)
hp2 = renmas.shapes.HitPoint()
hp2.spectrum = background

sampler = ren.get_sampler()
camera = ren.get_camera()
film = ren.get_film()
lst_lights = ren.lst_lights()
shapes = ren.lst_shapes()


def get_runtime():
    runtime = Runtime()
    sampler.get_sample_asm(runtime, "get_sample")
    camera.ray_asm(runtime, "generate_ray")

    dyn_arrays = ren.dyn_arrays()
    renmas.shapes.linear_isect_asm(runtime, "scene_isect", dyn_arrays)
    return runtime
Ejemplo n.º 13
0
def path_tracer(tile):
    sampler = ren.get_sampler()
    camera = ren.get_camera()
    film = ren.get_film()

    shapes = ren.isect_shapes()
    isect = renmas.shapes.isect #intersection rutine
    shade = renmas.core.shade

    background = renmas.core.Spectrum(0.00, 0.00, 0.00) 
    hp2 = renmas.shapes.HitPoint()
    hp3 = renmas.shapes.HitPoint()
    hp2.spectrum = background

    sample = renmas.samplers.Sample()
    x, y, width, height = tile
    sampler.tile(x, y, width, height)

    Lr = [] #reflection coefficient
    Ld = [] #direct light
    transmitance = 1.0
    cur_depth = 0
    max_depth = 4

    #current implementation stop tracing path when we hit emitter
    while True:
        sam = sampler.get_sample(sample)
        if sam is None: break 
        ray = camera.ray(sample)
        hp = isect(ray, shapes)

        if hp is None:
            film.add_sample(sample, hp2) #background
            continue 

        hp.wo = ray.dir * -1.0
        shade(hp)
        kr = hp.brdf * (1.0 / hp.pdf) * hp.ndotwi
        transmitance *= kr.r #FIXME take component that has maximum value
        Lr.append(kr)
        Ld.append(hp.spectrum)

        cur_depth = 1
        ray.dir = hp.wi #in wi is next direction
        ray.origin = hp.hit_point
        if hp.le.r > 0.01: #primiray ray hit emitter - stop path 
            hp.spectrum = hp.le
            film.add_sample(sample, hp) 
            Lr = [] 
            Ld = []
            transmitance = 1.0
            cur_depth = 0
            continue

        Le = renmas.core.Spectrum(0.00, 0.00, 0.00) 

        while True:
            if cur_depth == max_depth: break
            if transmitance < 0.0001: break
            hp = isect(ray, shapes)
            if hp is None: break
            hp.wo = ray.dir * -1.0
            shade(hp)
            if hp.le.r > 0.0001: 
                #Le = hp.le
                break #we hit emiter FIXME - we dont't have to stop think for better implementation !!!!
            kr = hp.brdf * (1.0 / hp.pdf) * hp.ndotwi
            Lr.append(kr)
            Ld.append(hp.spectrum)
            ray.dir = hp.wi #in wi is next direction
            ray.origin = hp.hit_point
            transmitance *= kr.r #FIXME take component that has maximum value 
            cur_depth += 1

        tmp_spec = Le
        for i in range(cur_depth):

            brdf = Lr.pop()
            ld = Ld.pop()
            tmp_spec = tmp_spec.mix_spectrum(brdf) + ld

        hp3.spectrum = tmp_spec 
        film.add_sample(sample, hp3) 
            
        Lr = [] 
        Ld = []
        transmitance = 1.0
        cur_depth = 0
Ejemplo n.º 14
0
def raycast():
    sampler = ren.get_sampler()
    camera = ren.get_camera()
    film = ren.get_film()
    lst_lights = ren.lst_lights()

    shapes = ren.isect_shapes()
    isect = renmas.shapes.isect #intersection rutine
    shade = renmas.core.shade
    recursion_depth = 3

    background = renmas.core.Spectrum(0.00, 0.00, 0.00) 
    hp2 = renmas.shapes.HitPoint()
    hp2.spectrum = background

    tile = next_tile()
    if tile is None: 
        global image_saved
        if not image_saved:
            save_image(film, "Image5.png")
            print("Slika je spremljena")
            image_saved = True
        return None
    sample = renmas.samplers.Sample()
    x, y, width, height = tile
    sampler.tile(x, y, width, height)
    start = time.clock()
    
    while True:
        sam = sampler.get_sample(sample)
        if sam is None: break 
        ray = camera.ray(sample)
        hp = isect(ray, shapes, 999999.0)

        if hp is None:
            hp2.spectrum = background
            film.add_sample(sample, hp2) #background
            continue

        Ld1, Brdf1 = calc_brdf(hp, ray)
        hp = isect(ray, shapes, 999999.0)
        if hp is None:
            hp2.spectrum = Ld1 
            film.add_sample(sample, hp2) 
            continue

        Ld2, Brdf2 = calc_brdf(hp, ray)
        hp = isect(ray, shapes, 999999.0)
        if hp is None:
            hp2.spectrum = Ld1 + Ld2.mix_spectrum(Brdf1)
            film.add_sample(sample, hp2) 
            continue

        Ld3, Brdf3 = calc_brdf(hp, ray)
        spectrum = Ld3.mix_spectrum(Brdf2) + Ld2
        spectrum = spectrum.mix_spectrum(Brdf1) + Ld1
        hp.spectrum = spectrum 
        film.add_sample(sample, hp) 


    blt_float_img_to_window(0, 0, film.image, win)
    end = time.clock()
    global duration
    duration = duration + (end - start)
    print("Renderiranje jednog tile je trajalo", end - start, duration)
    return True