def on_paint(self, event): w,h = W, H scale = 1 aakernel = None if self._technique == 'ssaa': scale = 3 # Make this 2, 3, 4 ... for 4x, 9x, 16x aa w, h = W*scale, H*scale # Set up FBO fb = FrameBuffer(w, h) tex = RenderTexture(2) tex.create_empty_texture(w, h) # Must match depth buffer! fb.attach_texture(tex) fb.add_depth_buffer() fb.check() # Draw scene off-screen fb.enable() gl.glClearColor(1,1,1,1); gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) self.setup_scene(0, 0, w, h) if self._preaa: render_scene(True, scale) else: render_scene(False, scale) fb.disable() # Pergorm aa if self._technique == 'ssaa': self._pass_ssaa(tex, w, h, scale) elif self._technique == 'smaa': self._pass_smaa(tex) else: self._pass_aa(tex) # Draw original to screen too self.setup_scene(W, 0, W, H) render_scene() # And original but smoothed self.setup_scene(2*W, 0, W, H) render_scene(smooth=True) # Now blit texture to backbuffer self._backend._vispy_swap_buffers() # todo: private attr!
def on_paint(self, event): w, h = W, H scale = 1 aakernel = None if self._technique == 'ssaa': scale = 3 # Make this 2, 3, 4 ... for 4x, 9x, 16x aa w, h = W * scale, H * scale # Set up FBO fb = FrameBuffer(w, h) tex = RenderTexture(2) tex.create_empty_texture(w, h) # Must match depth buffer! fb.attach_texture(tex) fb.add_depth_buffer() fb.check() # Draw scene off-screen fb.enable() gl.glClearColor(1, 1, 1, 1) gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) self.setup_scene(0, 0, w, h) if self._preaa: render_scene(True, scale) else: render_scene(False, scale) fb.disable() # Pergorm aa if self._technique == 'ssaa': self._pass_ssaa(tex, w, h, scale) elif self._technique == 'smaa': self._pass_smaa(tex) else: self._pass_aa(tex) # Draw original to screen too self.setup_scene(W, 0, W, H) render_scene() # And original but smoothed self.setup_scene(2 * W, 0, W, H) render_scene(smooth=True) # Now blit texture to backbuffer self._backend._vispy_swap_buffers() # todo: private attr!
def paintGL(self): # self._paint() # return W, H = self.width(), self.height() # Set up FBO fb = FrameBuffer(W, H) tex = RenderTexture(2) tex.create_empty_texture(W, H) # Must match depth buffer! fb.attach_texture(tex) fb.add_depth_buffer() fb.check() # Draw scene to off-screen buffer fb.enable() gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) self._setup_scene(0,0,W,H) self._paint() fb.disable() # Draw texture to screen gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) self._setup_scene(0,0,W,H) tex.Enable(0) self._aaShader.bind() #shader.uniformi('texture', tex._texId) self._aaShader.uniformf('shape', W, H) self._aaShader.uniformi('texture', 0) gl.glBegin(gl.GL_QUADS) gl.glTexCoord(0,0); gl.glVertex(0,0); gl.glTexCoord(0,1); gl.glVertex(0,1); gl.glTexCoord(1,1); gl.glVertex(1,1); gl.glTexCoord(1,0); gl.glVertex(1,0); gl.glEnd() self._aaShader.unbind() tex.Disable()
def on_paint(self, event): w,h = W, H scale = 1 aakernel = None if self._technique == 'ssaa': scale = 3 # Make this 2, 3, 4 ... for 4x, 9x, 16x aa w, h = W*scale, H*scale # Set up FBO if hasattr(self, '_fb'): fb = self._fb tex = self._tex else: fb = FrameBuffer(w, h) tex = RenderTexture(2) tex.create_empty_texture(w, h) # Must match depth buffer! fb.attach_texture(tex) fb.add_depth_buffer() fb.check() # self._fb = fb self._tex = tex # Draw scene off-screen fb.enable() gl.glClearColor(1,1,1,1); gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) self.setup_scene(0, 0, w, h) if self._preaa: self._draw_stars(True, scale) else: self._draw_stars(False, scale) fb.disable() # Pergorm aa if self._raw: # Prepare for drawing texture to screen gl.glClearColor(1,1,1,1); gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) self.setup_scene(0, 0, W, H) tex.Enable(0) # Draw texture to screen gl.glBegin(gl.GL_QUADS) gl.glTexCoord(0,0); gl.glVertex(0,0); gl.glTexCoord(0,1); gl.glVertex(0,1); gl.glTexCoord(1,1); gl.glVertex(1,1); gl.glTexCoord(1,0); gl.glVertex(1,0); gl.glEnd() tex.Disable() elif self._technique == 'ssaa': self._pass_ssaa(tex, w, h, scale) elif self._technique == 'smaa': self._pass_smaa(tex) else: self._pass_aa(tex) # Now blit texture to backbuffer self._backend._vispy_swap_buffers() # Prepare for next round self._a += 0.005 self.update()
def _pass_smaa(self, tex): # Get precomputed textures from smaa_tex import getSearchTex, getAreaTex searchTex = RenderTexture(2) searchTex.SetData(getSearchTex()) areaTex = RenderTexture(2) areaTex._interpolate = True # Enforce GL_LINEAR areaTex.SetData(getAreaTex()) # Compose shader code bigOne = self._shader_code[-1] edgeVertex = bigOne + self._shader_code[0] edgeFragment = bigOne + self._shader_code[1] blendVertex = bigOne + self._shader_code[2] blendFragment = bigOne + self._shader_code[3] neighborhoodVertex = bigOne + self._shader_code[4] neighborhoodFragment = bigOne + self._shader_code[5] if True: # Pass 1 fb = fb_edges = FrameBuffer(W, H) edgesTex = RenderTexture(2) edgesTex.create_empty_texture(W, H) # Must match depth buffer! fb.attach_texture(edgesTex) fb.add_depth_buffer() # fb.enable() gl.glClearColor(1,1,1,1); gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) self.setup_scene(0, 0, W, H); gl.glDisable(gl.GL_BLEND) # shader = Shader(edgeVertex, edgeFragment) shader.bind() tex.Enable(0) shader.uniformi('texture', 0) gl.glBegin(gl.GL_QUADS) gl.glTexCoord(0,0); gl.glVertex(0,0); gl.glTexCoord(0,1); gl.glVertex(0,1); gl.glTexCoord(1,1); gl.glVertex(1,1); gl.glTexCoord(1,0); gl.glVertex(1,0); gl.glEnd() fb.disable() tex.Disable() shader.unbind() if True: # Pass 2 fb = FrameBuffer(W, H) blendTex = RenderTexture(2) blendTex.create_empty_texture(W, H) # Must match depth buffer! fb.attach_texture(blendTex) fb.add_depth_buffer() # fb.enable() gl.glClearColor(1,1,1,1); gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) self.setup_scene(0, 0, W, H); gl.glDisable(gl.GL_BLEND) # shader = Shader(blendVertex, blendFragment) shader.bind() edgesTex.Enable(0) areaTex.Enable(1) searchTex.Enable(2) shader.uniformi('edge_tex', 0) shader.uniformi('area_tex', 1) shader.uniformi('search_tex', 2) # gl.glBegin(gl.GL_QUADS) gl.glTexCoord(0,0); gl.glVertex(0,0); gl.glTexCoord(0,1); gl.glVertex(0,1); gl.glTexCoord(1,1); gl.glVertex(1,1); gl.glTexCoord(1,0); gl.glVertex(1,0); gl.glEnd() fb.disable() edgesTex.Disable() areaTex.Disable() searchTex.Disable() shader.unbind() if True: # Pass 3 gl.glClearColor(1,1,1,1); gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) self.setup_scene(0, 0, W, H); gl.glDisable(gl.GL_BLEND) # shader = Shader(neighborhoodVertex, neighborhoodFragment) shader.bind() tex.Enable(0) blendTex.Enable(1) shader.uniformi('texture', 0) shader.uniformi('blend_tex', 1) # gl.glBegin(gl.GL_QUADS) gl.glTexCoord(0,0); gl.glVertex(0,0); gl.glTexCoord(0,1); gl.glVertex(0,1); gl.glTexCoord(1,1); gl.glVertex(1,1); gl.glTexCoord(1,0); gl.glVertex(1,0); gl.glEnd() tex.Disable() blendTex.Disable() shader.unbind()
def on_paint(self, event): w, h = W, H scale = 1 aakernel = None if self._technique == 'ssaa': scale = 3 # Make this 2, 3, 4 ... for 4x, 9x, 16x aa w, h = W * scale, H * scale # Set up FBO if hasattr(self, '_fb'): fb = self._fb tex = self._tex else: fb = FrameBuffer(w, h) tex = RenderTexture(2) tex.create_empty_texture(w, h) # Must match depth buffer! fb.attach_texture(tex) fb.add_depth_buffer() fb.check() # self._fb = fb self._tex = tex # Draw scene off-screen fb.enable() gl.glClearColor(1, 1, 1, 1) gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) self.setup_scene(0, 0, w, h) if self._preaa: self._draw_stars(True, scale) else: self._draw_stars(False, scale) fb.disable() # Pergorm aa if self._raw: # Prepare for drawing texture to screen gl.glClearColor(1, 1, 1, 1) gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) self.setup_scene(0, 0, W, H) tex.Enable(0) # Draw texture to screen gl.glBegin(gl.GL_QUADS) gl.glTexCoord(0, 0) gl.glVertex(0, 0) gl.glTexCoord(0, 1) gl.glVertex(0, 1) gl.glTexCoord(1, 1) gl.glVertex(1, 1) gl.glTexCoord(1, 0) gl.glVertex(1, 0) gl.glEnd() tex.Disable() elif self._technique == 'ssaa': self._pass_ssaa(tex, w, h, scale) elif self._technique == 'smaa': self._pass_smaa(tex) else: self._pass_aa(tex) # Now blit texture to backbuffer self._backend._vispy_swap_buffers() # Prepare for next round self._a += 0.005 self.update()
def _pass_smaa(self, tex): # Get precomputed textures from smaa_tex import getSearchTex, getAreaTex searchTex = RenderTexture(2) searchTex.SetData(getSearchTex()) areaTex = RenderTexture(2) areaTex._interpolate = True # Enforce GL_LINEAR areaTex.SetData(getAreaTex()) # Compose shader code bigOne = self._shader_code[-1] edgeVertex = bigOne + self._shader_code[0] edgeFragment = bigOne + self._shader_code[1] blendVertex = bigOne + self._shader_code[2] blendFragment = bigOne + self._shader_code[3] neighborhoodVertex = bigOne + self._shader_code[4] neighborhoodFragment = bigOne + self._shader_code[5] if True: # Pass 1 fb = fb_edges = FrameBuffer(W, H) edgesTex = RenderTexture(2) edgesTex.create_empty_texture(W, H) # Must match depth buffer! fb.attach_texture(edgesTex) fb.add_depth_buffer() # fb.enable() gl.glClearColor(1, 1, 1, 1) gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) self.setup_scene(0, 0, W, H) gl.glDisable(gl.GL_BLEND) # shader = Shader(edgeVertex, edgeFragment) shader.bind() tex.Enable(0) shader.uniformi('texture', 0) gl.glBegin(gl.GL_QUADS) gl.glTexCoord(0, 0) gl.glVertex(0, 0) gl.glTexCoord(0, 1) gl.glVertex(0, 1) gl.glTexCoord(1, 1) gl.glVertex(1, 1) gl.glTexCoord(1, 0) gl.glVertex(1, 0) gl.glEnd() fb.disable() tex.Disable() shader.unbind() if True: # Pass 2 fb = FrameBuffer(W, H) blendTex = RenderTexture(2) blendTex.create_empty_texture(W, H) # Must match depth buffer! fb.attach_texture(blendTex) fb.add_depth_buffer() # fb.enable() gl.glClearColor(1, 1, 1, 1) gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) self.setup_scene(0, 0, W, H) gl.glDisable(gl.GL_BLEND) # shader = Shader(blendVertex, blendFragment) shader.bind() edgesTex.Enable(0) areaTex.Enable(1) searchTex.Enable(2) shader.uniformi('edge_tex', 0) shader.uniformi('area_tex', 1) shader.uniformi('search_tex', 2) # gl.glBegin(gl.GL_QUADS) gl.glTexCoord(0, 0) gl.glVertex(0, 0) gl.glTexCoord(0, 1) gl.glVertex(0, 1) gl.glTexCoord(1, 1) gl.glVertex(1, 1) gl.glTexCoord(1, 0) gl.glVertex(1, 0) gl.glEnd() fb.disable() edgesTex.Disable() areaTex.Disable() searchTex.Disable() shader.unbind() if True: # Pass 3 gl.glClearColor(1, 1, 1, 1) gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) self.setup_scene(0, 0, W, H) gl.glDisable(gl.GL_BLEND) # shader = Shader(neighborhoodVertex, neighborhoodFragment) shader.bind() tex.Enable(0) blendTex.Enable(1) shader.uniformi('texture', 0) shader.uniformi('blend_tex', 1) # gl.glBegin(gl.GL_QUADS) gl.glTexCoord(0, 0) gl.glVertex(0, 0) gl.glTexCoord(0, 1) gl.glVertex(0, 1) gl.glTexCoord(1, 1) gl.glVertex(1, 1) gl.glTexCoord(1, 0) gl.glVertex(1, 0) gl.glEnd() tex.Disable() blendTex.Disable() shader.unbind()