Beispiel #1
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
Beispiel #2
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
Beispiel #3
0
def shade(hp):
    #loop through lights
    lights = ren.lst_lights()
    tmp_spec = renmas.core.Spectrum(0.0, 0.0, 0.0)
    for light in lights:
        if light.L(hp) is True:  #light is visible
            ren.get_material(hp.material).brdf(hp)
            tmp_spec = tmp_spec + hp.spectrum
    hp.spectrum = tmp_spec
    return hp
Beispiel #4
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
Beispiel #5
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
Beispiel #6
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
Beispiel #7
0
    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

asm_structs = renmas.utils.structs("sample", "ray", "hitpoint")
ASM = """
#DATA
"""
Beispiel #8
0
            th = h
            if i == xcoords[-1]:
                tw = last_w
            if j == ycoords[-1]:
                th = last_h
            tiles.append((i, j, tw, th))

    #print(xcoords)
    #print(ycoords)
    #print(last_w, last_h)
    #print(tiles)
    return tiles


lst_tiles = list_tiles(WIDTH, HEIGHT, NSAMPLES)
lst_lights = ren.lst_lights()


def save_image(film):
    blitter = renmas.gui.Blitter()

    wid, he = film.image.get_size()
    img = renmas.gui.ImageRGBA(wid, he)

    dw, dh = img.get_size()
    da, dpitch = img.get_addr()
    sw, sh = film.image.get_size()
    sa, spitch = film.image.get_addr()
    blitter.blt_floatTorgba(da, 0, 0, dw, dh, dpitch, sa, 0, 0, sw, sh, spitch)
    renmas.gui.save_image("Image1.png", img)
Beispiel #9
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
Beispiel #10
0
def generate_shade(runtime, label, visible_label):
    materials = ren.lst_materials()
    lights = ren.lst_lights()

    nmaterials = len(materials)
    nlights = len(lights)

    asm_structs = util.structs("hitpoint")
    #loop through list of lights and do shading
    #TODO later implement smarter shade where we on random pick just light??? study this aproach
    #eax is pointer to hitpoint
    ASM = """
        #DATA
    """
    ASM += asm_structs
    ASM += "uint32 lights_ptrs[" + str(nlights) + "]\n"
    ASM += "uint32 materials_ptrs[" + str(nmaterials) + "]\n"
    ASM += "uint32 nlights \n"
    ASM += "uint32 cur_light \n"
    ASM += """
        float zero_spectrum[4] = 0.0, 0.0, 0.0, 0.0
        float curr_spectrum[4]

        uint32 hp_ptr 

        #CODE
    """
    ASM += "global " + label + ":\n" + """
        macro eq128 curr_spectrum = zero_spectrum
        mov dword [cur_light], 0 
        mov dword [hp_ptr], eax

        next_light:
        ; check if include all lights and finish shading if we are  
        mov ebx, dword [cur_light]
        cmp ebx, dword [nlights]
        je _end_shading

        ; call shading for current light
        mov eax, dword [hp_ptr]
        call dword [lights_ptrs + ebx*4]
        add dword [cur_light], 1 ;move to next light in next iteration
        
        ; check to see if we must call brdf of material
        mov eax, dword [hp_ptr]
        mov edx, dword [eax + hitpoint.visible]
        cmp edx, 0
        je next_light
        
        ; call brdf of material
        mov eax, dword [hp_ptr]
        mov ebx, dword [eax + hitpoint.mat_index]
        call dword [materials_ptrs + 4*ebx] 
        mov eax, dword [hp_ptr]
        macro eq128 curr_spectrum = curr_spectrum + eax.hitpoint.spectrum
        jmp next_light

        _end_shading:
        mov eax, dword [hp_ptr]
        macro eq128 eax.hitpoint.spectrum = curr_spectrum
        ret

    """

    l_ptrs = []
    for l in lights:
        l.L_asm(runtime, visible_label)
        l_ptrs.append(l.func_ptr)
    l_ptrs = tuple(l_ptrs)
    m_ptrs = []
    for m in materials:
        m.brdf_asm(runtime)
        m_ptrs.append(m.func_ptr)
    m_ptrs = tuple(m_ptrs)

    asm = util.get_asm()
    mc = asm.assemble(ASM, True)
    name = "shade" + str(util.unique())
    ds = runtime.load(name, mc)
    ds["lights_ptrs"] = l_ptrs
    ds["materials_ptrs"] = m_ptrs
    ds["nlights"] = nlights