예제 #1
0
    def generate_texture(self):
        logger.info("Generate VectorFieldTexture3D.")

        core_manager = CoreManager.getInstance()
        resource_manager = core_manager.resource_manager
        renderer = core_manager.renderer

        texture = CreateTexture(
            name=self.texture_name,
            texture_type=Texture3D,
            width=self.texture_width,
            height=self.texture_height,
            depth=self.texture_depth,
            internal_format=GL_RGBA16F,
            texture_format=GL_RGBA,
            min_filter=GL_LINEAR,
            mag_filter=GL_LINEAR,
            data_type=GL_FLOAT,
            wrap=GL_CLAMP,
        )

        resource = resource_manager.texture_loader.get_resource(
            self.texture_name)
        if resource is None:
            resource = resource_manager.texture_loader.create_resource(
                self.texture_name, texture)
        else:
            old_texture = resource.get_data()
            if old_texture is not None:
                old_texture.delete()
            resource.set_data(texture)

        glPolygonMode(GL_FRONT_AND_BACK, renderer.view_mode)
        glDepthFunc(GL_LEQUAL)
        glEnable(GL_CULL_FACE)
        glFrontFace(GL_CCW)
        glEnable(GL_DEPTH_TEST)
        glDepthMask(True)
        glClearColor(0.0, 0.0, 0.0, 1.0)
        glClearDepth(1.0)

        renderer.set_blend_state(False)

        renderer.framebuffer_manager.bind_framebuffer(texture)
        glClear(GL_COLOR_BUFFER_BIT)

        material_instance = resource_manager.get_material_instance(
            'procedural.vector_field_3d')
        material_instance.use_program()

        for i in range(texture.depth):
            material_instance.bind_uniform_data('depth', i / texture.depth)
            renderer.framebuffer_manager.bind_framebuffer(texture,
                                                          target_layer=i)
            renderer.postprocess.draw_elements()

        renderer.restore_blend_state_prev()

        # save
        resource_manager.texture_loader.save_resource(resource.name)
예제 #2
0
    def generate_texture(self):
        logger.info("Generate CloudTexture3D.")

        core_manager = CoreManager.getInstance()
        resource_manager = core_manager.resource_manager
        renderer = core_manager.renderer

        texture = CreateTexture(
            name=self.texture_name,
            texture_type=Texture3D,
            width=self.width,
            height=self.height,
            depth=self.depth,
            internal_format=GL_R16F,
            texture_format=GL_RED,
            min_filter=GL_LINEAR,
            mag_filter=GL_LINEAR,
            data_type=GL_FLOAT,
            wrap=GL_REPEAT,
        )

        resource = resource_manager.texture_loader.get_resource(
            self.texture_name)
        if resource is None:
            resource = resource_manager.texture_loader.create_resource(
                self.texture_name, texture)
            resource_manager.texture_loader.save_resource(resource.name)
        else:
            old_texture = resource.get_data()
            old_texture.delete()
            resource.set_data(texture)

        glPolygonMode(GL_FRONT_AND_BACK, renderer.view_mode)
        glDepthFunc(GL_LEQUAL)
        glEnable(GL_CULL_FACE)
        glFrontFace(GL_CCW)
        glEnable(GL_DEPTH_TEST)
        glDepthMask(True)
        glClearColor(0.0, 0.0, 0.0, 1.0)
        glClearDepth(1.0)

        renderer.set_blend_state(False)

        renderer.framebuffer_manager.bind_framebuffer(texture)
        glClear(GL_COLOR_BUFFER_BIT)

        mat = resource_manager.get_material_instance(
            'procedural.cloud_noise_3d')
        mat.use_program()
        mat.bind_uniform_data('texture_random',
                              resource_manager.get_texture("common.random"))
        mat.bind_uniform_data('random_seed', random.random())
        mat.bind_uniform_data('sphere_count', self.sphere_count)
        mat.bind_uniform_data('sphere_scale', self.sphere_scale)
        mat.bind_uniform_data('noise_persistance', self.noise_persistance)
        mat.bind_uniform_data('noise_scale', self.noise_scale)

        for i in range(texture.depth):
            mat.bind_uniform_data('depth', i / texture.depth)
            renderer.framebuffer_manager.bind_framebuffer(texture,
                                                          target_layer=i)
            renderer.postprocess.draw_elements()

        renderer.restore_blend_state_prev()