def set_fov(self, fov): self.fov = fov # this is vertical fov P = perspective(self.fov, float(self.width) / float(self.height), 0.01, 100) self.P = np.ascontiguousarray(P, np.float32)
def __init__(self, width=512, height=512, vertical_fov=90, device_idx=0, use_fisheye=False, msaa=False): """ :param width: width of the renderer output :param height: width of the renderer output :param vertical_fov: vertical field of view for the renderer :param device_idx: which GPU to run the renderer on :param use_fisheye: use fisheye shader or not """ self.shaderProgram = None self.fbo = None self.color_tex_rgb, self.color_tex_normal, self.color_tex_semantics, self.color_tex_3d = None, None, None, None self.depth_tex = None self.VAOs = [] self.VBOs = [] self.textures = [] self.objects = [] self.visual_objects = [] self.vertex_data = [] self.shapes = [] self.texUnitUniform = None self.width = width self.height = height self.faces = [] self.instances = [] self.fisheye = use_fisheye # self.context = glcontext.Context() # self.context.create_opengl_context((self.width, self.height)) available_devices = get_available_devices() if device_idx < len(available_devices): device = available_devices[device_idx] logging.info("Using device {} for rendering".format(device)) else: logging.info( "Device index is larger than number of devices, falling back to use 0" ) device = 0 self.device_idx = device_idx self.device_minor = device self.msaa = msaa if platform.system() == 'Darwin': from gibson2.core.render.mesh_renderer import GLFWRendererContext self.r = GLFWRendererContext.GLFWRendererContext(width, height) else: self.r = MeshRendererContext.MeshRendererContext( width, height, device) self.r.init() self.glstring = self.r.getstring_meshrenderer() logging.debug('Rendering device and GL version') logging.debug(self.glstring) self.colors = [[1, 0, 0], [0, 1, 0], [0, 0, 1]] self.lightcolor = [1, 1, 1] logging.debug('Is using fisheye camera: {}'.format(self.fisheye)) if self.fisheye: [self.shaderProgram, self.texUnitUniform] = self.r.compile_shader_meshrenderer( "".join( open( os.path.join(os.path.dirname(mesh_renderer.__file__), 'shaders/fisheye_vert.shader')). readlines()).replace("FISHEYE_SIZE", str(self.width / 2)), "".join( open( os.path.join(os.path.dirname(mesh_renderer.__file__), 'shaders/fisheye_frag.shader')). readlines()).replace("FISHEYE_SIZE", str(self.width / 2))) else: [self.shaderProgram, self.texUnitUniform] = self.r.compile_shader_meshrenderer( "".join( open( os.path.join(os.path.dirname(mesh_renderer.__file__), 'shaders/vert.shader')).readlines()), "".join( open( os.path.join(os.path.dirname(mesh_renderer.__file__), 'shaders/frag.shader')).readlines())) self.lightpos = [0, 0, 0] self.setup_framebuffer() self.vertical_fov = vertical_fov self.camera = [1, 0, 0] self.target = [0, 0, 0] self.up = [0, 0, 1] P = perspective(self.vertical_fov, float(self.width) / float(self.height), 0.01, 100) V = lookat(self.camera, self.target, up=self.up) self.V = np.ascontiguousarray(V, np.float32) self.P = np.ascontiguousarray(P, np.float32) self.materials_mapping = {} self.mesh_materials = []
def __init__(self, width=512, height=512, fov=90, device_idx=0, use_fisheye=False): """ :param width: width of the renderer output :param height: width of the renderer output :param fov: vertical field of view for the renderer :param device_idx: which GPU to run the renderer on :param use_fisheye: use fisheye shader or not """ self.shaderProgram = None self.fbo = None self.color_tex_rgb, self.color_tex_normal, self.color_tex_semantics, self.color_tex_3d = None, None, None, None self.depth_tex = None self.VAOs = [] self.VBOs = [] self.textures = [] self.objects = [] self.visual_objects = [] self.texUnitUniform = None self.width = width self.height = height self.faces = [] self.instances = [] self.fisheye = use_fisheye # self.context = glcontext.Context() # self.context.create_opengl_context((self.width, self.height)) available_devices = get_available_devices() if device_idx < len(available_devices): device = available_devices[device_idx] print("using device {}".format(device)) else: print( "device index is larger than number of devices, falling back to use 0" ) device = 0 self.device_idx = device_idx self.device_minor = device self.r = MeshRendererContext.MeshRendererContext(width, height, device) self.r.init() self.glstring = GL.glGetString(GL.GL_VERSION) from OpenGL.GL import shaders self.shaders = shaders self.colors = colormap self.lightcolor = [1, 1, 1] print("fisheye", self.fisheye) if self.fisheye: vertexShader = self.shaders.compileShader( "".join( open( os.path.join(os.path.dirname(mesh_renderer.__file__), 'shaders/fisheye_vert.shader')).readlines( )).replace("FISHEYE_SIZE", str(self.width / 2)), GL.GL_VERTEX_SHADER) fragmentShader = self.shaders.compileShader( "".join( open( os.path.join(os.path.dirname(mesh_renderer.__file__), 'shaders/fisheye_frag.shader')).readlines( )).replace("FISHEYE_SIZE", str(self.width / 2)), GL.GL_FRAGMENT_SHADER) else: vertexShader = self.shaders.compileShader( "".join( open( os.path.join(os.path.dirname(mesh_renderer.__file__), 'shaders/vert.shader')).readlines()), GL.GL_VERTEX_SHADER) fragmentShader = self.shaders.compileShader( "".join( open( os.path.join(os.path.dirname(mesh_renderer.__file__), 'shaders/frag.shader')).readlines()), GL.GL_FRAGMENT_SHADER) self.shaderProgram = self.shaders.compileProgram( vertexShader, fragmentShader) self.texUnitUniform = GL.glGetUniformLocation(self.shaderProgram, 'texUnit') self.lightpos = [0, 0, 0] self.setup_framebuffer() self.fov = fov self.camera = [1, 0, 0] self.target = [0, 0, 0] self.up = [0, 0, 1] P = perspective(self.fov, float(self.width) / float(self.height), 0.01, 100) V = lookat(self.camera, self.target, up=self.up) self.V = np.ascontiguousarray(V, np.float32) self.P = np.ascontiguousarray(P, np.float32) self.materials_mapping = {} self.mesh_materials = []
def __init__(self, width=512, height=512, device_idx=0, use_fisheye=False): self.shaderProgram = None self.fbo = None self.color_tex_rgb, self.color_tex_normal, self.color_tex_semantics, self.color_tex_3d = None, None, None, None self.depth_tex = None self.VAOs = [] self.VBOs = [] self.textures = [] self.objects = [] self.visual_objects = [] self.texUnitUniform = None self.width = width self.height = height self.faces = [] self.instances = [] self.fisheye = use_fisheye # self.context = glcontext.Context() # self.context.create_opengl_context((self.width, self.height)) available_devices = get_available_devices() assert (device_idx < len(available_devices)) device = available_devices[device_idx] self.r = CppMeshRenderer.CppMeshRenderer(width, height, device) self.r.init() self.glstring = GL.glGetString(GL.GL_VERSION) from OpenGL.GL import shaders self.shaders = shaders self.colors = colormap self.lightcolor = [1, 1, 1] print("fisheye", self.fisheye) if self.fisheye: vertexShader = self.shaders.compileShader( "".join( open( os.path.join(os.path.dirname(mesh_renderer.__file__), 'shaders/fisheye_vert.shader')).readlines( )).replace("FISHEYE_SIZE", str(self.width / 2)), GL.GL_VERTEX_SHADER) fragmentShader = self.shaders.compileShader( "".join( open( os.path.join(os.path.dirname(mesh_renderer.__file__), 'shaders/fisheye_frag.shader')).readlines( )).replace("FISHEYE_SIZE", str(self.width / 2)), GL.GL_FRAGMENT_SHADER) else: vertexShader = self.shaders.compileShader( "".join( open( os.path.join(os.path.dirname(mesh_renderer.__file__), 'shaders/vert.shader')).readlines()), GL.GL_VERTEX_SHADER) fragmentShader = self.shaders.compileShader( "".join( open( os.path.join(os.path.dirname(mesh_renderer.__file__), 'shaders/frag.shader')).readlines()), GL.GL_FRAGMENT_SHADER) self.shaderProgram = self.shaders.compileProgram( vertexShader, fragmentShader) self.texUnitUniform = GL.glGetUniformLocation(self.shaderProgram, 'texUnit') self.lightpos = [0, 0, 0] self.setup_framebuffer() self.fov = 20 self.camera = [1, 0, 0] self.target = [0, 0, 0] self.up = [0, 0, 1] P = perspective(self.fov, float(self.width) / float(self.height), 0.01, 100) V = lookat(self.camera, self.target, up=self.up) self.V = np.ascontiguousarray(V, np.float32) self.P = np.ascontiguousarray(P, np.float32) self.materials_mapping = {} self.mesh_materials = []