def __init__(self, shader="post_base", mipmap=False, add_tex=None, scale=1.0, camera=None, divide=1): """ calls Texture.__init__ but doesn't need to set file name as texture generated from the framebuffer. Keyword Arguments: *shader* to use when drawing sprite, defaults to post_base, a simple 3x3 convolution that does basic edge detection. Can be copied to project directory and modified as required. *mipmap* can be set to True with slight cost to speed, or use fxaa shader *add_tex* list of textures. If additional textures can be used by the shader then they can be added here. *scale* will only render this proportion of the full screen which will then be mapped to the full uv of the Sprite. The camera object passed (below) will need to have the same scale set to avoid perspective distortion *camera* the camera to use for rendering to the offscreen texture *divide* allow the sprite to be created with intermediate vertices to allow interesting vertex shader effects """ super(PostProcess, self).__init__("postprocess") self.scale = scale # load shader self.shader = Shader(shader) if camera is None: self.viewcam = Camera.instance( ) # in case this is prior to one being created else: self.viewcam = camera self.camera = Camera(is_3d=False) self.sprite = LodSprite(z=20.0, w=self.ix, h=self.iy, n=divide) self.sprite.set_2d_size(w=self.ix, h=self.iy) for b in self.sprite.buf: b.unib[6] = self.scale # ufact b.unib[7] = self.scale # vfact b.unib[9] = (1.0 - self.scale) * 0.5 # uoffset b.unib[10] = (1.0 - self.scale) * 0.5 # voffset self.blend = True self.mipmap = mipmap self.tex_list = [ self ] # TODO check if this self reference causes graphics memory leaks if add_tex: self.tex_list.extend(add_tex)