コード例 #1
0
ファイル: camera.py プロジェクト: fynv/FeiRaysInline
    def __init__(self,
                 film_width,
                 film_height,
                 camera2world,
                 vfov,
                 aperture=0.0,
                 focus_dist=1.0):
        self.m_film = Film(film_width, film_height)
        self.m_sv_camera2world = vki.SVMat4x4(camera2world)
        theta = vfov * math.pi / 180.0
        half_height = math.tan(theta * 0.5) * focus_dist
        size_pix = half_height * 2.0 / film_height
        lens_radius = aperture * 0.5
        self.m_sv_size_pix = vki.SVFloat(size_pix)
        self.m_sv_lens_radius = vki.SVFloat(lens_radius)
        self.m_sv_focus_dist = vki.SVFloat(focus_dist)
        self.m_cptr = SVCombine_Create(
            {
                'film': self.m_film,
                'camera2world': self.m_sv_camera2world,
                'size_pix': self.m_sv_size_pix,
                'lens_radius': self.m_sv_lens_radius,
                'focus_dist': self.m_sv_focus_dist
            }, '''
void generate_ray(in Comb_#hash# camera, float film_x, float film_y, float lens_x, float lens_y, out vec3 origin, out vec3 dir)
{
	origin = vec3(lens_x*camera.lens_radius, lens_y*camera.lens_radius, 0.0);
	origin = (camera.camera2world*vec4(origin, 1.0)).xyz;
	vec3 pos_pix = vec3((film_x - float(camera.film.width)*0.5)*camera.size_pix, (float(camera.film.height)*0.5 - film_y)*camera.size_pix, -camera.focus_dist);
	pos_pix = (camera.camera2world*vec4(pos_pix, 1.0)).xyz;
	dir = normalize(pos_pix - origin);	
}
''')
コード例 #2
0
 def download_srgb(self, boost=1.0):
     sv_times_expo = vki.SVFloat(self.m_times_exposure)
     sv_boost = vki.SVFloat(boost)
     colorBuf = vki.Texture2D(self.m_width, self.m_height,
                              VK_FORMAT_R8G8B8A8_SRGB)
     self.film2srgb.launch([3], [colorBuf], None, [0.5, 0.5, 0.5, 1.0], 1.0,
                           [self, sv_times_expo, sv_boost])
     srgb = np.empty((self.m_height, self.m_width, 4), dtype=np.uint8)
     colorBuf.download(srgb)
     return srgb
コード例 #3
0
ファイル: test_multithread.py プロジェクト: fynv/VkInline
def thread_func():
    darr_out = vki.SVVector('float', 5)
    darr_out2 = vki.SVVector('int', 5)
    forLoop.launch_n(5, [darr, darr_out, vki.SVFloat(10.0)])
    forLoop.launch_n(5, [darr2, darr_out2, vki.SVInt32(5)])
    print(darr_out.to_host())
    print(darr_out2.to_host())
コード例 #4
0
ファイル: interaction.py プロジェクト: fynv/FeiRaysInline
    def __init__(self):
        self.m_t = vki.SVFloat(0.0)
        self.m_light_id = vki.SVInt32(0)
        self.m_intensity = Spectrum()
        self.m_cptr = SVCombine_Create(
            {
                't': self.m_t,
                'light_id': self.m_light_id,
                'intensity': self.m_intensity
            }, '''
Spectrum Le(in Comb_#hash# self, in vec3 wo, int depth_iter)
{
    Spectrum ret = self.intensity;
    if (depth_iter>0)
    {
        from_rgb(ret, vec3(0.0));
    }
    return ret;
}
''')
コード例 #5
0
ファイル: interaction.py プロジェクト: fynv/FeiRaysInline
    def __init__(self):
        self.m_t = vki.SVFloat(0.0)
        self.m_normal = vki.SVVec3(glm.vec3(0.0))
        self.m_cptr = SVCombine_Create(
            {
                't': self.m_t,
                'normal': self.m_normal,
                'lambert': BxDF_Lambert.dummy
            }, '''
Spectrum evaluate_bsdf(in Comb_#hash# self, in vec3 wo, in vec3 wi)
{
    return f(self.lambert, self.normal, wo, wi);
}

float pdf_bsdf(in Comb_#hash# self, in vec3 wo, in vec3 wi)
{
    return pdf(self.lambert, self.normal, wo, wi);
}

Spectrum sample_bsdf(in Comb_#hash# self, in vec3 wo, inout vec3 wi, inout RNGState state, inout float path_pdf)
{
    return sample_f(self.lambert, self.normal, wo, wi, state, path_pdf);
}
''')
コード例 #6
0
import VkInline as vki
import numpy as np

# interface with numpy
harr = np.array([1.0, 2.0, 3.0, 4.0, 5.0], dtype='float32')
darr = vki.device_vector_from_numpy(harr)

harr2 = np.array([6,7,8,9,10], dtype='int32')
darr2 = vki.device_vector_from_numpy(harr2)

# test launching non-templated for
forLoop = vki.For(['arr_in','arr_out','k'], "inner",
'''
void inner(uint idx)
{
	set_value(arr_out, idx, get_value(arr_in, idx)*k);
}
''')

darr_out = vki.SVVector('float', 5)
forLoop.launch(0, 5, [darr, darr_out, vki.SVFloat(10.0)])
print (darr_out.to_host())

darr_out = vki.SVVector('int', 5)
forLoop.launch_n(5, [darr2, darr_out, vki.SVInt32(5)])
print (darr_out.to_host())

コード例 #7
0
darr = vki.device_vector_from_numpy(harr)
print(darr.to_host())

# GLSL data type
print(darr.name_view_type())

harr2 = np.array([6, 7, 8, 9, 10], dtype='int32')
darr2 = vki.device_vector_from_numpy(harr2)

# kernel with auto parameters, launched twice with different types
kernel = vki.Computer(['arr_in', 'arr_out', 'k'], '''
void main()
{
    uint id = gl_GlobalInvocationID.x;
    if (id >= get_size(arr_in)) return;
    set_value(arr_out, id, get_value(arr_in, id)*k);
}
''')

darr_out = vki.SVVector('float', 5)
kernel.launch(1, 128, [darr, darr_out, vki.SVFloat(10.0)])
print(darr_out.to_host())

darr_out = vki.SVVector('int', 5)
kernel.launch(1, 128, [darr2, darr_out, vki.SVInt32(5)])
print(darr_out.to_host())

# create a vector from python list with GLSL type specified
darr3 = vki.device_vector_from_list([3.0, 5.0, 7.0, 9.0, 11.0], 'float')
print(darr3.to_host())