Esempio n. 1
0
def _create_material(name, values, project, directory):
    Ka = Kd = Ks = Ke = Ns = Ni = illum = d = Tr = Tf = None
    map_Ka = map_Kd = map_Ks = map_d = None

    if 'Ka' in values and not _zero_spectrum(values['Ka']):
        Ka = _create_spectrum(values['Ka'], project)
    if 'Kd' in values and not _zero_spectrum(values['Kd']):
        Kd = _create_spectrum(values['Kd'], project)
    if 'Ks' in values and not _zero_spectrum(values['Ks']):
        Ks = _create_spectrum(values['Ks'], project)
    if 'Ke' in values and not _zero_spectrum(values['Ke']):
        Ke = _create_spectrum(values['Ke'], project)
    if 'Ns' in values:
        Ns = float(values['Ns'][0])
    if 'Ni' in values:
        Ni = float(values['Ni'][0])
    if 'd' in values:
        d = float(values['d'][0])
    if 'Tr' in values:
        Tr = float(values['Tr'][0])
    if 'Tf' in values and not _zero_spectrum(values['Tf']):
        Tf = _create_spectrum(values['Tf'], project)
    if 'illum' in values:
        illum = int(values['illum'][0])
    if 'map_Ka' in values:
        map_Ka = values['map_Ka'][0].strip()
    if 'map_Kd' in values:
        map_Kd = values['map_Kd'][0].strip()
    if 'map_Ks' in values:
        map_Ks = values['map_Ks'][0].strip()
    if 'map_d' in values:
        map_d = values['map_d'][0].strip()

    props = {}
    #just basic lambertian and anisotropic ward
    if illum is not None and illum == 6 and Ni is not None:
        props['ior'] = Ni
        mat = project.create_material(name, 'glass', props, dielectric=True)
        project.mat_mgr.add(name, mat)

    elif map_Kd is not None:
        fname = os.path.join(directory, map_Kd)
        image = load_image(fname)
        if image is None:
            raise ValueError("Image is None ", map_Kd)
        props['texture'] = image
        mat = project.create_material(name, 'lambertian_texture', props)
        project.mat_mgr.add(name, mat)

    elif Kd is not None and Ks is not None and Ns is not None:
        props['diffuse'] = Kd
        props['specular'] = Ks
        props['exponent'] = Ns
        mat = project.create_material(name, 'phong', props)
        project.mat_mgr.add(name, mat)

    elif Kd is not None:
        props['diffuse'] = Kd
        mat = project.create_material(name, 'lambertian', props)
        project.mat_mgr.add(name, mat)
Esempio n. 2
0
def _create_material(name, values, project, directory):
    Ka = Kd = Ks = Ke = Ns = Ni = illum = d = Tr = Tf = None
    map_Ka = map_Kd = map_Ks = map_d = None

    if 'Ka' in values and not _zero_spectrum(values['Ka']):
        Ka = _create_spectrum(values['Ka'], project)
    if 'Kd' in values and not _zero_spectrum(values['Kd']):
        Kd = _create_spectrum(values['Kd'], project)
    if 'Ks' in values and not _zero_spectrum(values['Ks']):
        Ks = _create_spectrum(values['Ks'], project)
    if 'Ke' in values and not _zero_spectrum(values['Ke']):
        Ke = _create_spectrum(values['Ke'], project)
    if 'Ns' in values:
        Ns = float(values['Ns'][0])
    if 'Ni' in values:
        Ni = float(values['Ni'][0])
    if 'd' in values:
        d = float(values['d'][0])
    if 'Tr' in values:
        Tr = float(values['Tr'][0])
    if 'Tf' in values and not _zero_spectrum(values['Tf']):
        Tf = _create_spectrum(values['Tf'], project)
    if 'illum' in values:
        illum = int(values['illum'][0])
    if 'map_Ka' in values:
        map_Ka = values['map_Ka'][0].strip()
    if 'map_Kd' in values:
        map_Kd = values['map_Kd'][0].strip()
    if 'map_Ks' in values:
        map_Ks = values['map_Ks'][0].strip()
    if 'map_d' in values:
        map_d = values['map_d'][0].strip()

    props = {}
    #just basic lambertian and anisotropic ward
    if illum is not None and illum == 6 and Ni is not None:
        props['ior'] = Ni
        mat = project.create_material(name, 'glass', props, dielectric=True)
        project.mat_mgr.add(name, mat)

    elif map_Kd is not None:
        fname = os.path.join(directory, map_Kd)
        image = load_image(fname)
        if image is None:
            raise ValueError("Image is None ", map_Kd)
        props['texture'] = image
        mat = project.create_material(name, 'lambertian_texture', props)
        project.mat_mgr.add(name, mat)

    elif Kd is not None and Ks is not None and Ns is not None:
        props['diffuse'] = Kd
        props['specular'] = Ks
        props['exponent'] = Ns
        mat = project.create_material(name, 'phong', props)
        project.mat_mgr.add(name, mat)

    elif Kd is not None:
        props['diffuse'] = Kd
        mat = project.create_material(name, 'lambertian', props)
        project.mat_mgr.add(name, mat)
Esempio n. 3
0
import os.path
from renmas3.base import load_image, save_image
from renmas3.win32 import show_image_in_window

fname = 'lena2.ppm'
filename = os.path.join(os.path.dirname(os.path.abspath(__file__)), fname)
print(filename)
img = load_image(filename)
print(img)

show_image_in_window(img)

fname = "lena3.ppm"
filename = os.path.join(os.path.dirname(os.path.abspath(__file__)), fname)
save_image(filename, img)
Esempio n. 4
0
import time
from renmas3.base import ImagePRGBA, ImageRGBA
from renmas3.utils import blt_prgba_to_rgba, blt_rgba_to_prgba

from renmas3.base import load_image
from renmas3.win32 import show_image_in_window
from renmas3.renderer import generate_samples

#img = load_image('Koala.jpg')
img = load_image('G:/light_probes/grace_probe.hdr')
print(img)

width, height = img.size()

start = time.clock()
samples = generate_samples(img, 10)
elapsed = time.clock() - start
print("Generation of samples took ", elapsed)
for sample in samples:
    pass
    #print (sample.vec)
    #print (sample.pdf)

#img2 = ImagePRGBA(width, height)
#blt_rgba_to_prgba(img, img2)

img3 = ImageRGBA(width, height)
blt_prgba_to_rgba(img, img3)

#show_image_in_window(img3)
Esempio n. 5
0
from renmas3.base import ImageBGRA, load_image, FileLoader, ImagePRGBA
from renmas3.win32 import show_image_in_window
from renmas3.utils import blt_prgba_to_bgra
from renmas3.renderer.renderer import create_props


def create_tmo(tmo_shader='exp_tmo'):
    tmo_loader = FileLoader(["F:/GitRenmas/renmas/renmas3/tmo_shaders"])
    contents = tmo_loader.load(tmo_shader, 'props.txt')
    props = create_props(contents)
    contents = tmo_loader.load(tmo_shader, 'tmo.py')
    tmo = Tmo(contents, props)
    return tmo


hdr_image = load_image('Desk_oBA2.hdr')
#hdr_image = load_image('AtriumNight_oA9D.hdr')
width, height = hdr_image.size()
ldr_image = ImagePRGBA(width, height)

output_image = ImageBGRA(width, height)
reinhard = ReinhardOperator()
tmo = create_tmo('log_tmo')

start = time.clock()

#tmo shader
tmo.tone_map(hdr_image, ldr_image)
blt_prgba_to_bgra(ldr_image, output_image)

#old asm implementation
Esempio n. 6
0
import os.path
from renmas3.base import load_image, save_image
from renmas3.win32 import show_image_in_window

fname = "lena2.ppm"
filename = os.path.join(os.path.dirname(os.path.abspath(__file__)), fname)
print(filename)
img = load_image(filename)
print(img)

show_image_in_window(img)

fname = "lena3.ppm"
filename = os.path.join(os.path.dirname(os.path.abspath(__file__)), fname)
save_image(filename, img)
Esempio n. 7
0
            if round(g1 - g2, places) != 0:
                return False
            if round(b1 - b2, places) != 0:
                return False
    return True


def copy_image(in_img, out_image):
    width, height = in_img.size()
    for y in range(height):
        for x in range(width):
            r1, g1, b1, a1 = in_img.get_pixel(x, y)
            out_image.set_pixel(x, y, r1, g1, b1, a1)


img = load_image('F:/hdr_images/Desk_oBA2.hdr')
print(img)
img_props = calc_img_props(img)
print(img_props)
width, height = img.size()
output_image = ImagePRGBA(width, height)


def tmo_py(props, in_img, out_img):
    pass


code = """
rgb_col = get_rgb(in_img, 25, 25)
key = luminance(rgb_col)
rgb_col = normalize(rgb_col)
Esempio n. 8
0
import time
from renmas3.base import ImagePRGBA, ImageRGBA
from renmas3.utils import blt_prgba_to_rgba, blt_rgba_to_prgba

from renmas3.base import load_image
from renmas3.win32 import show_image_in_window
from renmas3.renderer import generate_samples

# img = load_image('Koala.jpg')
img = load_image("G:/light_probes/grace_probe.hdr")
print(img)

width, height = img.size()

start = time.clock()
samples = generate_samples(img, 10)
elapsed = time.clock() - start
print("Generation of samples took ", elapsed)
for sample in samples:
    pass
    # print (sample.vec)
    # print (sample.pdf)

# img2 = ImagePRGBA(width, height)
# blt_rgba_to_prgba(img, img2)

img3 = ImageRGBA(width, height)
blt_prgba_to_rgba(img, img3)

# show_image_in_window(img3)
Esempio n. 9
0
import time
from renmas3.tone import ReinhardOperator, Tmo
from renmas3.base import ImageBGRA, load_image, FileLoader, ImagePRGBA 
from renmas3.win32 import show_image_in_window
from renmas3.utils import blt_prgba_to_bgra
from renmas3.renderer.renderer import create_props

def create_tmo(tmo_shader='exp_tmo'):
    tmo_loader = FileLoader(["F:/GitRenmas/renmas/renmas3/tmo_shaders"])
    contents = tmo_loader.load(tmo_shader, 'props.txt')
    props = create_props(contents)
    contents = tmo_loader.load(tmo_shader, 'tmo.py')
    tmo = Tmo(contents, props)
    return tmo

hdr_image = load_image('Desk_oBA2.hdr')
#hdr_image = load_image('AtriumNight_oA9D.hdr')
width, height = hdr_image.size()
ldr_image = ImagePRGBA(width, height)

output_image = ImageBGRA(width, height)
reinhard = ReinhardOperator()
tmo = create_tmo('log_tmo')

start = time.clock()

#tmo shader
tmo.tone_map(hdr_image, ldr_image)
blt_prgba_to_bgra(ldr_image, output_image)

#old asm implementation
Esempio n. 10
0
            if round(r1-r2, places) != 0:
                return False
            if round(g1-g2, places) != 0:
                return False
            if round(b1-b2, places) != 0:
                return False
    return True

def copy_image(in_img, out_image):
    width, height = in_img.size()
    for y in range(height):
        for x in range(width):
            r1, g1, b1, a1 = in_img.get_pixel(x, y)
            out_image.set_pixel(x, y, r1, g1, b1, a1)

img = load_image('F:/hdr_images/Desk_oBA2.hdr')
print(img)
img_props = calc_img_props(img)
print(img_props)
width, height = img.size()
output_image = ImagePRGBA(width, height)

def tmo_py(props, in_img, out_img):
    pass

code = """
rgb_col = get_rgb(in_img, 25, 25)
key = luminance(rgb_col)
rgb_col = normalize(rgb_col)
"""