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.uint32) normal_inds = np.array(lst_normal_inds, dtype=np.uint32) VK_FORMAT_R8G8B8A8_SRGB = 43 width = 900 height = 600 scene = fri.Scene() sky_cube = np.array(Image.open('cubemap.png').convert('RGBA')) gpu_sky_cube = vki.Cubemap(512, 512, VK_FORMAT_R8G8B8A8_SRGB) gpu_sky_cube.upload(sky_cube) ''' sky = fri.TexturedSky(scene.add_cubemap(gpu_sky_cube)) scene.set_sky(sky) ''' sky = fri.GradientSky((0.0, 0.0, 0.0), (0.0, 0.0, 0.0)) scene.set_sky(sky) ''' point_light0 = fri.PointLight((-5.0, 20.0, -5.0), (0.5, 1.0, 0.5), 1000.0) scene.add_object(point_light0) point_light1 = fri.PointLight((5.0, 20.0, 5.0), (1.0, 0.5, 0.5), 1000.0) scene.add_object(point_light1) '''
def __init__(self, fn_skin = "skin_default.png", backface = False): self.width = 640 self.height = 480 proj_mat = glm.perspective(glm.radians(45.0), self.width/self.height, 0.1, 1000.0) view_mat = glm.lookAt(glm.vec3(10.0,10.0,10.0), glm.vec3(0.0,0.0,0.0), glm.vec3(0.0, 1.0, 0.0)) self.matrix = proj_mat*view_mat self.bg_color = [1.0, 1.0, 1.0, 1.0] self.bg_depth = 1.0 options = {} if backface: self.bg_depth = 0.0 options['depth_compare_op'] = VK_COMPARE_OP_GREATER skin_in = np.array(Image.open(fn_skin).convert('RGBA')) self.skin = vki.Cubemap(skin_in.shape[1], skin_in.shape[0]//6, VK_FORMAT_R8G8B8A8_SRGB) self.skin.upload(skin_in) self.rp = vki.Rasterizer(["matrix", "map", "dirs"], type_locked=True) self.rp.add_draw_call(vki.DrawCall( ''' const vec3 positions[18] = { vec3(3.0, 3.0, 3.0), vec3(3.0, 3.0, -3.0), vec3(3.0, -3.0, 3.0), vec3(-3.0, 3.0, -3.0), vec3(-3.0, 3.0, 3.0), vec3(-3.0, -3.0, -3.0), vec3(-3.0, 3.0, -3.0), vec3(3.0, 3.0, -3.0), vec3(-3.0, 3.0, 3.0), vec3(-3.0, -3.0, 3.0), vec3(3.0, -3.0, 3.0), vec3(-3.0, -3.0, -3.0), vec3(-3.0, 3.0, 3.0), vec3(3.0, 3.0, 3.0), vec3(-3.0, -3.0, 3.0), vec3(3.0, 3.0, -3.0), vec3(-3.0, 3.0, -3.0), vec3(3.0, -3.0, -3.0) }; const vec2 indices[24] = { vec2(0.0,0.0), vec2(0.0,1.0), vec2(1.0,1.0), vec2(1.0,1.0), vec2(1.0,0.0), vec2(0.0,0.0), vec2(1.0,0.0), vec2(0.0,0.0), vec2(0.0,1.0), vec2(0.0,1.0), vec2(1.0,1.0), vec2(1.0,0.0), vec2(1.0,1.0), vec2(1.0,0.0), vec2(0.0,0.0), vec2(0.0,0.0), vec2(0.0,1.0), vec2(1.0,1.0), vec2(0.0,1.0), vec2(1.0,1.0), vec2(1.0,0.0), vec2(1.0,0.0), vec2(0.0,0.0), vec2(0.0,1.0) }; layout (location = 0) out vec3 pos; void main() { uint id_vert = gl_VertexIndex % 6; uint id_sq_out = gl_VertexIndex / 6; uint id_in_face_out = id_sq_out % 9; uint id_face_out = id_sq_out / 9; uint id_x_out = id_in_face_out % 3; uint id_y_out = id_in_face_out / 3; vec3 o_out = positions[id_face_out*3]; vec3 ox_out = positions[id_face_out*3+1] - o_out; vec3 oy_out = positions[id_face_out*3+2] - o_out; vec2 idv_out = indices[id_vert]; vec3 pos_out = o_out + ox_out *(float(id_x_out)+idv_out.x)/3.0 + oy_out *(float(id_y_out)+idv_out.y)/3.0; vec4 wpos = vec4(pos_out, 1.0); vec4 ppos = matrix * wpos; ppos.y = -ppos.y; ppos.z = (ppos.z + ppos.w) / 2.0; gl_Position = ppos; uint id_sq_in = get_value(map, id_sq_out); uint id_in_face_in = id_sq_in % 9; uint id_face_in = id_sq_in / 9; uint id_x_in = id_in_face_in % 3; uint id_y_in = id_in_face_in / 3; uint dir_in = get_value(dirs, id_sq_out); vec3 o_in = positions[id_face_in*3]; vec3 ox_in = positions[id_face_in*3+1] - o_in; vec3 oy_in = positions[id_face_in*3+2] - o_in; vec2 idv_in = indices[6*dir_in + id_vert]; vec3 pos_in = o_in + ox_in *(float(id_x_in)+idv_in.x)/3.0 + oy_in *(float(id_y_in)+idv_in.y)/3.0; pos = pos_in; } ''', ''' layout (location = 0) in vec3 pos; layout (location = 0) out vec4 outColor; void main() { vec3 dir = normalize(pos); outColor = texture(arr_cubemap[0], dir); } ''', options=options))