Exemplo n.º 1
0
    def render(self, cube, filename = None):        
        colorBuf = vki.Texture2D(self.width, self.height, VK_FORMAT_R8G8B8A8_SRGB)
        colorBuf4x = vki.Texture2D(self.width, self.height, VK_FORMAT_R8G8B8A8_SRGB, samples=4)
        depthBuf4x = vki.Texture2D(self.width, self.height, VK_FORMAT_D32_SFLOAT, isDepth=True, samples=4)       
        
        gpu_matrix = vki.SVMat4x4(self.matrix)
        gpu_map = vki.device_vector_from_numpy(cube.map)
        gpu_dirs = vki.device_vector_from_numpy(cube.dirs)
        self.rp.launch([6*9*6], [colorBuf4x], depthBuf4x, self.bg_color, self.bg_depth, [gpu_matrix, gpu_map, gpu_dirs], resolveBufs=[colorBuf], cubemaps = [self.skin])

        image_out = np.empty((self.height, self.width, 4), dtype=np.uint8)
        colorBuf.download(image_out)

        if not filename is None:
            Image.fromarray(image_out, 'RGBA').save(filename)       

        return image_out
Exemplo n.º 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
Exemplo n.º 3
0
    def render(self, cube, filename = None, up_face_only=False, up_face_id = 2, cross_mode = False):                
        colorBuf = vki.Texture2D(self.wh, self.wh, VK_FORMAT_R8G8B8A8_SRGB)             
        
        gpu_map = vki.device_vector_from_numpy(cube.map)
        gpu_colors = vki.device_vector_from_numpy(self.colors)

        if cross_mode:
            up_face_only = True

        if not up_face_only:
            up_face_id = -1

        gpu_up_face_id = vki.SVInt32(up_face_id)
        gpu_cross_mode = vki.SVInt32(cross_mode)
        self.rp.launch([(4*3+9)*6], [colorBuf], None, self.bg_color, 1.0, [gpu_map, gpu_colors, gpu_up_face_id, gpu_cross_mode])

        image_out = np.empty((self.wh, self.wh, 4), dtype=np.uint8)
        colorBuf.download(image_out)

        if not filename is None:
            Image.fromarray(image_out, 'RGBA').save(filename) 

        return image_out
Exemplo n.º 4
0
import VkInline as vki
import numpy as np
from PIL import Image

image_in = np.array(Image.open('fei.png').convert('RGBA'))

VK_FORMAT_R8G8B8A8_SRGB = 43

width = image_in.shape[1]
height = image_in.shape[0]

tex2d = vki.Texture2D(width, height, VK_FORMAT_R8G8B8A8_SRGB)
tex2d.upload(image_in)

colorBuf = vki.Texture2D(width, height, VK_FORMAT_R8G8B8A8_SRGB)

positions = np.array([[0.0, -0.5, 0.5], [0.5, 0.5, 0.5], [-0.5, 0.5, 0.5]],
                     dtype=np.float32)
gpuPos = vki.device_vector_from_numpy(positions)

colors = np.array([[0.0, 1.0, 0.0], [1.0, 0.0, 0.0], [0.0, 0.0, 1.0]],
                  dtype=np.float32)
gpuColors = vki.device_vector_from_numpy(colors)

rp = vki.Rasterizer(['pos', 'col'])

rp.add_draw_call(
    vki.DrawCall(
        '''
layout (location = 0) out vec2 vUV;
void main() 
Exemplo n.º 5
0
lst_normal_inds = []
for shape in shapes:
    for ind in shape.mesh.indices:
        lst_vertex_inds += [ind.vertex_index]
        lst_normal_inds += [ind.normal_index]

vertex_inds = np.array(lst_vertex_inds, dtype=np.int32)
normal_inds = np.array(lst_normal_inds, dtype=np.int32)

VK_FORMAT_R8G8B8A8_SRGB = 43
VK_FORMAT_D32_SFLOAT = 126

width = 640
height = 480

colorBuf = vki.Texture2D(width, height, VK_FORMAT_R8G8B8A8_SRGB)
depthBuf = vki.Texture2D(width, height, VK_FORMAT_D32_SFLOAT, isDepth=True)
gpuPos = vki.device_vector_from_numpy(positions)
gpuNormals = vki.device_vector_from_numpy(normals)
gpuInd_pos = vki.device_vector_from_numpy(vertex_inds)
gpuInd_norm = vki.device_vector_from_numpy(normal_inds)

rp = vki.Rasterizer(
    ['arr_pos', 'arr_norm', 'ind_pos', 'ind_norm', 'mat_pos', 'mat_norm'])

rp.add_draw_call(
    vki.DrawCall(
        '''
layout (location = 0) out vec3 vNorm;
void main() 
{