diff -Nru mgltools-dejavu-1.5.6~rc2+cvs.20110926/debian/changelog mgltools-dejavu-1.5.6~rc2+cvs.20111222/debian/changelog --- mgltools-dejavu-1.5.6~rc2+cvs.20110926/debian/changelog 2011-09-27 09:00:52.000000000 +0000 +++ mgltools-dejavu-1.5.6~rc2+cvs.20111222/debian/changelog 2011-12-22 16:10:08.000000000 +0000 @@ -1,3 +1,9 @@ +mgltools-dejavu (1.5.6~rc2+cvs.20111222-1) unstable; urgency=low + + * New upstream version. + + -- Steffen Moeller Thu, 22 Dec 2011 17:10:08 +0100 + mgltools-dejavu (1.5.6~rc2+cvs.20110926-1) unstable; urgency=low * New upstream version (lp: #500453). diff -Nru mgltools-dejavu-1.5.6~rc2+cvs.20110926/debian/get-orig-source/rc-version mgltools-dejavu-1.5.6~rc2+cvs.20111222/debian/get-orig-source/rc-version --- mgltools-dejavu-1.5.6~rc2+cvs.20110926/debian/get-orig-source/rc-version 2011-06-21 16:37:58.000000000 +0000 +++ mgltools-dejavu-1.5.6~rc2+cvs.20111222/debian/get-orig-source/rc-version 2011-12-07 08:15:17.000000000 +0000 @@ -1 +1 @@ -~rc1 +~rc2 diff -Nru mgltools-dejavu-1.5.6~rc2+cvs.20110926/DejaVu/Camera.py mgltools-dejavu-1.5.6~rc2+cvs.20111222/DejaVu/Camera.py --- mgltools-dejavu-1.5.6~rc2+cvs.20110926/DejaVu/Camera.py 2011-06-15 22:13:03.000000000 +0000 +++ mgltools-dejavu-1.5.6~rc2+cvs.20111222/DejaVu/Camera.py 2011-12-06 23:10:10.000000000 +0000 @@ -16,9 +16,9 @@ # ######################################################################### # -# $Header: /opt/cvs/python/packages/share1.5/DejaVu/Camera.py,v 1.424 2011/06/15 22:13:03 sanner Exp $ +# $Header: /opt/cvs/python/packages/share1.5/DejaVu/Camera.py,v 1.434 2011/12/06 23:10:10 sanner Exp $ # -# $Id: Camera.py,v 1.424 2011/06/15 22:13:03 sanner Exp $ +# $Id: Camera.py,v 1.434 2011/12/06 23:10:10 sanner Exp $ # """Camera Module: @@ -60,6 +60,7 @@ from DejaVu.Cylinders import Cylinders from DejaVu import bitPatterns from DejaVu.cursors import cursorsDict +from DejaVu.Texture import Texture if hasattr(DejaVu, 'enableVertexArray') is False: DejaVu.enableVertexArray = False @@ -79,6 +80,8 @@ if hasattr( DejaVu, 'selectionPatternSize') is False: DejaVu.selectionPatternSize = 6 +if hasattr( DejaVu, 'enableSSAO') is False: + DejaVu.enableSSAO = True sndDeriv = [ -0.125, -0.125, -0.125, -0.125, 1.0, -0.125, @@ -136,6 +139,13 @@ import array matf = array.array('f', [0]*16) + +try: + from opengltk.extent._glextlib import * +except: + print "no glActiveTextue" + DejaVu.enableSSAO = False + class Fog: keywords = [ @@ -1055,7 +1065,8 @@ for l in self.dpyList: glCallList(l) glPopMatrix() - self.tk.call(self._w, 'swapbuffers') + if self.swap: + self.tk.call(self._w, 'swapbuffers') @@ -1107,6 +1118,8 @@ 'rooty', 'side', 'stereoflag', + 'ssao', + 'SSAO_OPTIONS' ] setKeywords = [ @@ -1144,6 +1157,8 @@ 'sideBySideTranslation', 'suspendRedraw', 'drawThumbnail', + 'ssao', + 'SSAO_OPTIONS' ] PERSPECTIVE = 0 @@ -1169,7 +1184,7 @@ """return a dictionary describing this object's state This dictionary can be passed to the Set method to restore the object's state """ - return { + states = { 'height':self.height, 'width':self.width, 'rootx':self.rootx, @@ -1207,8 +1222,14 @@ 'd2off': self.d2off, 'd2cutL': self.d2cutL, 'd2cutH': self.d2cutH, + 'ssao':self.ssao, } - + if self.ssao: + d = {} +# for k in self.SSAO_OPTIONS: +# d[k] = self.SSAO_OPTIONS[k][0] + states['SSAO_OPTIONS'] = self.SSAO_OPTIONS + return states def lift(self): if __debug__: @@ -1302,12 +1323,17 @@ self.viewer.redrawLock.acquire() self.tk.call(self._w, 'makecurrent') glPixelStorei(GL.GL_PACK_ALIGNMENT, 1) - glReadBuffer(buffer) + + current_buffer = int(GL.glGetIntegerv(GL.GL_DRAW_BUFFER)[0]) + # tell OpenGL we want to read pixels from front buffer + glReadBuffer(buffer) glFinish() #was glFlush() gllib.glReadPixels( 0, 0, width, height, GL.GL_RGB, GL.GL_UNSIGNED_BYTE, nar) glFinish() + # restore buffer from on which we operate + glReadBuffer(current_buffer) if lock: self.viewer.redrawLock.release() return nar @@ -1318,6 +1344,7 @@ if hasattr(DejaVu, 'functionName'): DejaVu.functionName() """Grabs the detph buffer and returns it as PIL P image""" nar = self.GrabFrontBufferAsArray(lock, buffer) + import Image image = Image.fromstring('RGB', (self.width, self.height), nar.tostring()) @@ -1939,6 +1966,9 @@ self.addButtonDownCB(self.suspendNPR) self.addButtonUpCB(self.restoreNPR) + self.addButtonDownCB(self.reduceSSAOQuality) + self.addButtonUpCB(self.restoreSSAOQuality) + self.addButtonUpCB(self.capClippedGeoms) # these are used in bindPickingToMouseButton to bind picking to a @@ -2190,8 +2220,28 @@ #glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND) # to protect our texture, we bind the default texture while we don't use it - _gllib.glBindTexture(GL_TEXTURE_2D, 0 ) + + + self.dsT = 0 + # to protect our texture, we bind the default texture while we don't use it + self.ssao_method = 0 + self.copy_depth_ssao = True + if 'ssao' not in kw: + kw['ssao'] = False + self.ssao = False + self.use_mask_depth = 0 + else : + self.ssao = kw['ssao'] + + if 'SSAO_OPTIONS' in kw : + self.SSAO_OPTIONS = kw['SSAO_OPTIONS'] + else : + self.use_mask_depth = 0 + self.setDefaultSSAO_OPTIONS() + + self.setShaderSSAO() + _gllib.glBindTexture(GL_TEXTURE_2D, 0 ) self.setShaderSelectionContour() self.cursorStack = [] @@ -2232,7 +2282,24 @@ else: if not silent: print 'WARNING: delButtonUpCB: function not found', func - + + def reduceSSAOQuality(self, event): + if self.ssao: + self._oldSSAOSamples = self.SSAO_OPTIONS['samples'][0] + if len(self.SSAO_OPTIONS['samples']) == 5 : + self.SSAO_OPTIONS['samples'][-1].set(2) + else: + self.SSAO_OPTIONS['samples'][0] = 2 + + def restoreSSAOQuality(self, event): + if self.ssao: + if len(self.SSAO_OPTIONS['samples']) == 5 : + self.SSAO_OPTIONS['samples'][-1].set(self._oldSSAOSamples) + else: + self.SSAO_OPTIONS['samples'][0] = self._oldSSAOSamples + del self._oldSSAOSamples + + def suspendAA(self, event): if __debug__: if hasattr(DejaVu, 'functionName'): DejaVu.functionName() @@ -2326,8 +2393,9 @@ def popCursor(self): - self.currentCursor = cursorName = self.cursorStack.pop(-1) - self.configure(cursor=cursorsDict[cursorName]) + if len(self.cursorStack): + self.currentCursor = cursorName = self.cursorStack.pop(-1) + self.configure(cursor=cursorsDict[cursorName]) def setCursor(self, buttonNum): @@ -2847,6 +2915,13 @@ self.sideBySideTranslation = val if self.viewer: self.viewer.Redraw() + + val = kw.get( 'ssao') + if not val is None: + self.ssao = kw["ssao"] + val = kw.get( 'SSAO_OPTIONS') + if not val is None: + self.SSAO_OPTIONS = kw['SSAO_OPTIONS'] val = kw.get( 'stereoMode') if val is not None: @@ -2906,7 +2981,7 @@ def SwapBuffers(self): if __debug__: - if hasattr(DejaVu, 'functionName'): DejaVu.functionName() + if hasattr(DejaVu, 'functionName'): DejaVu.functionName() self.tk.call(self._w, 'swapbuffers') def Activate(self): @@ -4182,6 +4257,8 @@ if (lIsInstancetransformable and obj.drawBB != viewerConst.ONLY) \ or isinstance(obj, Insert2d): if lIsInstancetransformable and obj.texture: + glActiveTexture(GL_TEXTURE0) + _gllib.glBindTexture(GL_TEXTURE_2D, 0) obj.texture.Setup() if lIsInstancetransformable and obj.invertNormals is True \ @@ -4220,6 +4297,8 @@ #print obj.name, self.glError() if lIsInstancetransformable and obj.texture: + glActiveTexture(GL_TEXTURE0); + _gllib.glBindTexture(GL_TEXTURE_2D, 0) glDisable(obj.texture.dim) if lIsInstancetransformable: @@ -4873,7 +4952,7 @@ self.outline = Numeric.fabs(self.outline-255) self.outline = self.outline.astype('B') - +# glActiveTexture(GL_TEXTURE0); GL.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1) _gllib.glDrawPixels(self.width, self.height, GL_LUMINANCE, GL_UNSIGNED_BYTE, @@ -4900,7 +4979,6 @@ glEnable ( GL_STENCIL_TEST ) ; if self.antiAliased and self.renderMode==GL_RENDER: - dist = math.sqrt(Numeric.add.reduce(self.direction*self.direction)) # jitter loop if self.antiAliased>0: @@ -4933,6 +5011,9 @@ self._RedrawCamera() glPopMatrix() + if i == 0 and self.ssao : + self.copyDepth() + # we accumulate the back buffer glReadBuffer(GL_BACK) if i==0: @@ -4948,17 +5029,18 @@ accumContour *= sca else: accumContour += sca*self.outline - glAccum (GL_RETURN, 1.0) if self.contours and self._suspendNPR is False: self.outline = accumContour else: # plain drawing + if self.ssao : self.copy_depth_ssao = True self._RedrawCamera() + + if self.contours and self._suspendNPR is False: + self.drawNPR() - if self.contours and self._suspendNPR is False: - self.drawNPR() if self.contours and self._suspendNPR is False: glViewport(0, 0, self.width, self.height) @@ -4968,15 +5050,16 @@ and self.stereoMode != 'STEREO_BUFFERS': self.drawHighlight() - glDisable(GL_STENCIL_TEST) + + if self.ssao : + self.drawSSAO() + glDisable(GL_STENCIL_TEST) if self.drawThumbnailFlag: self.drawThumbnail() if self.swap: - self.tk.call(self._w, 'swapbuffers') - self.tk.call(self._w, 'makecurrent') - #glPopAttrib() + self.tk.call(self._w, 'swapbuffers') def setShaderSelectionContour(self): @@ -5134,7 +5217,7 @@ -1, 1) glDisable(GL_DEPTH_TEST) glDisable(GL_LIGHTING) - +# glActiveTexture(GL_TEXTURE0); ## here we apply the patterned highlight if DejaVu.selectionPatternSize >= 3: #glEnable(GL_COLOR_LOGIC_OP) @@ -5249,6 +5332,364 @@ glStencilMask(1) glStencilFunc ( GL_ALWAYS, 0, 1 ) +#=============================================================================== +# SSAO Shader +#=============================================================================== + def setTextureSSAO(self): + self.depthtextureName = int(glGenTextures(1)[0]) + glPrioritizeTextures(numpy.array([self.depthtextureName]), + numpy.array([1.])) + _gllib.glBindTexture (GL_TEXTURE_2D, self.depthtextureName); + glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + glTexParameteri (GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_LUMINANCE); + glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE ) + _gllib.glTexImage2D (GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32, self.width, + self.height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, None); + #SSAO depthexture + self.illumtextureName = int(glGenTextures(1)[0]) + glPrioritizeTextures(numpy.array([self.illumtextureName]), + numpy.array([1.])) + _gllib.glBindTexture (GL_TEXTURE_2D, self.illumtextureName); + glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + glTexParameteri (GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_LUMINANCE); + glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE ) + _gllib.glTexImage2D (GL_TEXTURE_2D, 0, GL_LUMINANCE, self.width, + self.height, 0, GL_LUMINANCE, GL_UNSIGNED_INT, None); + + #SSAO depthexture + self.rendertextureName = int(glGenTextures(1)[0]) + glPrioritizeTextures(numpy.array([self.rendertextureName]), + numpy.array([1.])) + _gllib.glBindTexture (GL_TEXTURE_2D, self.rendertextureName); + glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE ) + _gllib.glTexImage2D (GL_TEXTURE_2D, 0, GL_RGB, self.width, + self.height, 0, GL_RGB, GL_UNSIGNED_INT, None); + #depth mask texture + self.depthmasktextureName = int(glGenTextures(1)[0]) + glPrioritizeTextures(numpy.array([self.depthmasktextureName]), + numpy.array([1.])) + _gllib.glBindTexture (GL_TEXTURE_2D, self.depthmasktextureName); + glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); + glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); + glTexParameteri (GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_LUMINANCE); + glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE ) + _gllib.glTexImage2D (GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32, self.width, + self.height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, None); + #SSAO randomtexture +# +# self.randomTexture = Texture() +# import Image +# img = Image.open(DejaVu.__path__[0]+os.sep+"textures"+os.sep+"random_normals.png") +# self.randomTexture.Set(enable=1, image=img) + self.randomtextureName = int(glGenTextures(1)[0]) + glPrioritizeTextures(numpy.array([self.randomtextureName]), + numpy.array([1.])) +# _gllib.glBindTexture (GL_TEXTURE_2D, self.randomtextureName); +# glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); +# glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); +# glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); +# glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); +# glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE ) +# _gllib.glTexImage2D (GL_TEXTURE_2D, 0, self.randomTexture.format, +# self.randomTexture.width, self.randomTexture.height, +# 0, self.randomTexture.format, GL_UNSIGNED_INT, +# self.randomTexture.image); + _gllib.glBindTexture (GL_TEXTURE_2D,0) + + def setShaderSSAO(self): + if __debug__: + if hasattr(DejaVu, 'functionName'): DejaVu.functionName() + if not DejaVu.enableSSAO : + return + try: + ## do not try to import this before creating the opengl context, it would fail. + from opengltk.extent import _glextlib + DejaVu.enableSSAO = True + except ImportError: + DejaVu.enableSSAO = False + print "could not import _glextlib" + #import pdb;pdb.set_trace() + if DejaVu.enableSSAO is True: + self.setTextureSSAO() + extensionsList = glGetString(GL_EXTENSIONS) + if extensionsList.find('GL_EXT_packed_depth_stencil') < 0: + DejaVu.enableSSAO = False + print "opengl extension GL_EXT_packed_depth_stencil is not present" + + if DejaVu.enableSSAO is True: +# self.setDefaultSSAO_OPTIONS() + f = _glextlib.glCreateShader(_glextlib.GL_FRAGMENT_SHADER) + sfile = open(DejaVu.__path__[0]+os.sep+"shaders"+os.sep+"fragSSAO","r") + lines = sfile.readlines() + sfile.close() + self.fragmentSSAOShaderCode="" + for l in lines : + self.fragmentSSAOShaderCode+=l + v = _glextlib.glCreateShader(_glextlib.GL_VERTEX_SHADER) + sfile = open(DejaVu.__path__[0]+os.sep+"shaders"+os.sep+"vertSSAO","r") + lines = sfile.readlines() + sfile.close() + self.vertexSSAOShaderCode="" + for l in lines : + self.vertexSSAOShaderCode+=l + lStatus = 0x7FFFFFFF + _glextlib.glShaderSource(v, 1, self.vertexSSAOShaderCode, lStatus) + _glextlib.glCompileShader(v) + _glextlib.glShaderSource(f, 1, self.fragmentSSAOShaderCode, lStatus) + _glextlib.glCompileShader(f) + + lStatus1 = _glextlib.glGetShaderiv(f, _glextlib.GL_COMPILE_STATUS, lStatus ) + #print "SSAO compile status frag: %s"%lStatus, + lStatus2 = _glextlib.glGetShaderiv(v, _glextlib.GL_COMPILE_STATUS, lStatus ) + #print " vertex: %s"%lStatus + if lStatus1 == 0 or lStatus2 == 0: +# print "compile status", lStatus + charsWritten = 0 + shaderInfoLog = '\0' * 2048 + charsWritten, infoLog = _glextlib.glGetShaderInfoLog(f, len(shaderInfoLog), + charsWritten, shaderInfoLog) + print "shaderInfoLog", shaderInfoLog + DejaVu.enableSSAO = False + print "SSAO shader didn't compile" + else: + self.shaderSSAOProgram = _glextlib.glCreateProgram() + _glextlib.glAttachShader(self.shaderSSAOProgram,v) + _glextlib.glAttachShader(self.shaderSSAOProgram,f) + _glextlib.glLinkProgram(self.shaderSSAOProgram) + lStatus = 0x7FFFFFFF + lStatus = _glextlib.glGetProgramiv(self.shaderSSAOProgram, + _glextlib.GL_LINK_STATUS, + lStatus ) + if lStatus == 0: +# print "link status", lStatus + log = "" + charsWritten = 0 + progInfoLog = '\0' * 2048 + charsWritten, infoLog = _glextlib.glGetProgramInfoLog(self.shaderSSAOProgram, len(progInfoLog), + charsWritten, progInfoLog) + DejaVu.enableSSAO = False + print "SSAO shader didn't link" + print "log ",progInfoLog + + else: + _glextlib.glValidateProgram(self.shaderSSAOProgram) + lStatus = 0x7FFFFFFF + lStatus = _glextlib.glGetProgramiv(self.shaderSSAOProgram, + _glextlib.GL_VALIDATE_STATUS, + lStatus ) + if lStatus == 0: + print "SSAO shader did not validate, status:", lStatus + DejaVu.enableSSAO = False + print "enableSSAO not validated" + else: + # Get location + self.SSAO_LOCATIONS = { + 'RandomTexture': _glextlib.glGetUniformLocation( self.shaderSSAOProgram, 'RandomTexture' ), + 'DepthTexture': _glextlib.glGetUniformLocation( self.shaderSSAOProgram, 'DepthTexture' ), + 'RenderedTexture': _glextlib.glGetUniformLocation( self.shaderSSAOProgram, 'RenderedTexture' ), + 'LuminanceTexture': _glextlib.glGetUniformLocation( self.shaderSSAOProgram, 'LuminanceTexture' ), + 'DepthMaskTexture': _glextlib.glGetUniformLocation( self.shaderSSAOProgram, 'DepthMaskTexture' ), + 'RenderedTextureWidth': _glextlib.glGetUniformLocation( self.shaderSSAOProgram, 'RenderedTextureWidth' ), + 'RenderedTextureHeight': _glextlib.glGetUniformLocation( self.shaderSSAOProgram, 'RenderedTextureHeight' ), + 'realfar': _glextlib.glGetUniformLocation( self.shaderSSAOProgram, 'realfar' ), + #'realnear': _glextlib.glGetUniformLocation( self.shaderSSAOProgram, 'realnear' ), +# 'fogS': _glextlib.glGetUniformLocation( self.shaderSSAOProgram, 'fogS' ), +# 'fogE': _glextlib.glGetUniformLocation( self.shaderSSAOProgram, 'fogE' ), + } + + for k in self.SSAO_OPTIONS : + self.SSAO_LOCATIONS[k] = _glextlib.glGetUniformLocation( self.shaderSSAOProgram, k ) + + + def setDefaultSSAO_OPTIONS(self): + from opengltk.extent import _glextlib + #can be Intel, NVIDIA + + self.SSAO_OPTIONS={'far': [300.0,0.,1000.,"float"], + 'near': [self.near,0.,100.,"float"], + 'method':[self.ssao_method,0,1,"int"], + 'do_noise':[0,0,1,"int"], + 'fog':[0,0,1,"int"], + 'use_fog':[1,0,1,"int"], + 'use_mask_depth':[self.use_mask_depth,0,1,"int"], + 'only_depth':[0,0,1,"int"], + 'mix_depth':[0,0,1,"int"], + 'only_ssao':[0,0,1,"int"], + 'show_mask_depth':[0,0,1,"int"], + 'scale':[1.0,1.0,100.0,"float"], + 'samples': [6,1,8,"int"], + 'rings': [6,1,8,"int"], + 'aoCap': [1.2,0.0,10.0,"float"], + 'aoMultiplier': [100.0,1.,500.,"float"], + 'depthTolerance': [0.0,0.0,1.0,"float"], + 'aorange':[60.0,1.0,500.0,"float"], + 'negative':[0,0,1,"int"], + 'correction':[6.0,0.0,1000.0,"float"], + #'force_real_far':[0,0,1,"int"], + } + vendor = GL.glGetString(GL.GL_VENDOR) + #if vendor.find("ATI"): + self.SSAO_OPTIONS["near"][0] = 2.0 + self.Set(near = 2.0) + self.SSAO_OPTIONS_ORDER = ['use_fog','only_ssao','only_depth','mix_depth', + 'negative','do_noise','near','scale','rings','samples','aoCap','aoMultiplier', + 'aorange','depthTolerance','use_mask_depth']#'far','correction', + + + def copyDepth(self): + _gllib.glBindTexture (GL_TEXTURE_2D, self.depthtextureName); + glCopyTexImage2D(GL_TEXTURE_2D, 0,GL_DEPTH_COMPONENT, 0, 0, self.width, + self.height, 0); + self.copy_depth_ssao = False + + + def copyBuffer(self, depthmask=False): + if depthmask : + _gllib.glBindTexture (GL_TEXTURE_2D, self.depthmasktextureName); + glCopyTexImage2D(GL_TEXTURE_2D, 0,GL_DEPTH_COMPONENT, 0, 0, self.width, + self.height, 0); + return + if self.copy_depth_ssao : + _gllib.glBindTexture (GL_TEXTURE_2D, self.depthtextureName); + glCopyTexImage2D(GL_TEXTURE_2D, 0,GL_DEPTH_COMPONENT, 0, 0, self.width, + self.height, 0); + + _gllib.glBindTexture (GL_TEXTURE_2D, self.illumtextureName); + glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 0, 0, self.width, + self.height, 0); + + _gllib.glBindTexture (GL_TEXTURE_2D, self.rendertextureName); + glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, self.width, + self.height, 0); + + _gllib.glBindTexture (GL_TEXTURE_2D, 0); + + def drawSSAO(self,combine=0): + if __debug__: + if hasattr(DejaVu, 'functionName'): DejaVu.functionName() + + if DejaVu.enableSSAO is True and self.ssao: + #if not self.AR.use_mask: + self.copyBuffer() + from opengltk.extent import _glextlib + + import numpy + _glextlib.glBindFramebufferEXT(_glextlib.GL_FRAMEBUFFER_EXT, 0 ) + + _glextlib.glUseProgram( self.shaderSSAOProgram ) + + glActiveTexture(GL_TEXTURE3); + _gllib.glBindTexture (GL_TEXTURE_2D, self.depthtextureName); + _glextlib.glUniform1i(self.SSAO_LOCATIONS['DepthTexture'],3) + + glActiveTexture(GL_TEXTURE4); + _gllib.glBindTexture (GL_TEXTURE_2D, self.rendertextureName); + _glextlib.glUniform1i(self.SSAO_LOCATIONS['RenderedTexture'],4) + + glActiveTexture(GL_TEXTURE5); + _gllib.glBindTexture (GL_TEXTURE_2D, self.illumtextureName); + _glextlib.glUniform1i(self.SSAO_LOCATIONS['LuminanceTexture'],5) + + glActiveTexture(GL_TEXTURE6); + _gllib.glBindTexture (GL_TEXTURE_2D, self.randomtextureName); + _glextlib.glUniform1i(self.SSAO_LOCATIONS['RandomTexture'],6) + + glActiveTexture(GL_TEXTURE7); + _gllib.glBindTexture (GL_TEXTURE_2D, self.depthmasktextureName); + _glextlib.glUniform1i(self.SSAO_LOCATIONS['DepthMaskTexture'],7) + + _glextlib.glUniform1f(self.SSAO_LOCATIONS['RenderedTextureWidth'],self.width) + _glextlib.glUniform1f(self.SSAO_LOCATIONS['RenderedTextureHeight'],self.height) + + _glextlib.glUniform1f(self.SSAO_LOCATIONS['realfar'],self.far) + #_glextlib.glUniform1f(self.SSAO_LOCATIONS['realnear'],self.near) + + for k in self.SSAO_OPTIONS: + if len(self.SSAO_OPTIONS[k]) == 5 : + self.SSAO_OPTIONS[k][0] = self.SSAO_OPTIONS[k][-1].get() + val = self.SSAO_OPTIONS[k][0] + if k == "correction" : + #val = self.SSAO_OPTIONS[k][0] + self.SSAO_OPTIONS[k][0] = val = self.far / 10.0 + if len(self.SSAO_OPTIONS[k]) == 5 : + val = self.SSAO_OPTIONS[k][-1].get() + if k == "far" : + #val = self.SSAO_OPTIONS[k][0] + val = self.far + 230. + if len(self.SSAO_OPTIONS[k]) == 5 : + val = self.SSAO_OPTIONS[k][-1].get() + if k == "fog" : + self.SSAO_OPTIONS[k][0] = val = int(self.fog.enabled) + if len(self.SSAO_OPTIONS[k]) == 5 : + self.SSAO_OPTIONS[k][-1].set(val) + if self.SSAO_OPTIONS[k][3] == "float": + _glextlib.glUniform1f(self.SSAO_LOCATIONS[k],val) + else : + _glextlib.glUniform1i(self.SSAO_LOCATIONS[k],val) + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | + GL_STENCIL_BUFFER_BIT) + self.drawTexturePolygon() + self.endSSAO() + + def endSSAO(self): + if DejaVu.enableSSAO is True : + from opengltk.extent import _glextlib + _glextlib.glUseProgram(0) + glActiveTexture(GL_TEXTURE0); + _gllib.glBindTexture (GL_TEXTURE_2D, 0); +# _gllib.glBindTexture (GL_TEXTURE_2D,GL_TEXTURE0) + + + + def drawTexturePolygon(self): + glPushMatrix() + glLoadIdentity() + glMatrixMode(GL_PROJECTION) + glPushMatrix() + glLoadIdentity() + lViewport = glGetIntegerv(GL_VIEWPORT) + glOrtho(float(lViewport[0]), + float(lViewport[0]+lViewport[2]), + float(lViewport[1]), + float(lViewport[1]+lViewport[3]), + -1, 1) + glEnable(GL_BLEND) + +# glEnable(GL_TEXTURE_2D) +# if self.dsT == 0 : +# _gllib.glBindTexture (GL_TEXTURE_2D, self.depthtextureName); +# elif self.dsT == 1 : +# _gllib.glBindTexture (GL_TEXTURE_2D, self.illumtextureName); +# else : +# _gllib.glBindTexture (GL_TEXTURE_2D, self.rendertextureName); + glBegin(GL_POLYGON) + glTexCoord2i(0, 0) + glVertex2i(0, 0) + glTexCoord2i(1, 0) + glVertex2i(self.width, 0) + glTexCoord2i(1, 1) + glVertex2i(self.width, self.height) + glTexCoord2i(0, 1) + glVertex2i(0, self.height) + glEnd() + glDisable(GL_BLEND) + _gllib.glBindTexture (GL_TEXTURE_2D, 0); + glPopMatrix() + glMatrixMode(GL_MODELVIEW) + glPopMatrix() ## def DrawImage(self, imarray, mode='RGB', format=GL.GL_UNSIGNED_BYTE, ## filter=None, swap=False): @@ -5512,7 +5953,7 @@ # when recording resumes self.videoRecorder = None self.nbRecordedframes = 0 - + self.vidimage = None def setVideoOutputFile(self, filename='out.mpg'): if __debug__: @@ -5523,7 +5964,7 @@ def setVideoParameters(self, width=None, height=None, pauseLength=0, - autoPauseDelay=1, outCodec = 'mpeg2video'): + autoPauseDelay=1, outCodec = 'mpeg1video'): if __debug__: if hasattr(DejaVu, 'functionName'): DejaVu.functionName() # make sure image is dimensions are even @@ -5570,7 +6011,7 @@ self.viewer.master.after(1, self.recordFrame) - def recordFrame(self, force=False, imageFile=None): + def recordFrame(self, force=False): if __debug__: if hasattr(DejaVu, 'functionName'): DejaVu.functionName() @@ -5601,8 +6042,11 @@ print 'auto pause id', self.pendingAutoPauseID root.after_cancel(self.pendingAutoPauseID) self.pendingAutoPauseID = None +# if DejaVu.enableSSAO is True and self.ssao :#and self.vidimage is not None: +# image = self.GrabFrontBuffer(lock=False) +# else : image = self.GrabFrontBuffer(lock=False) - # FIXME this resizing can be avoided if camera size is locked + # FIXME this resizing can be avoided if camera size is locked image = image.resize((self.videoFrameWidth, self.videoFrameHeight)) self.lastFrame = image @@ -5613,8 +6057,6 @@ self.videoOutputFile.write(self.encoder.encode(yuvFrame).data) #self.pendingAutoPauseID = root.after(self.autoPauseDelay*1000, # self.autoPause) - if imageFile != None: - image.save(imageFile) self.viewer.hasRedrawn = False self.pendingRecordFrameID = root.after(1, self.recordFrame) @@ -5627,6 +6069,7 @@ self.viewer.hasRedrawn = True self.recordFrame() + def autoPause(self): if __debug__: if hasattr(DejaVu, 'functionName'): DejaVu.functionName() diff -Nru mgltools-dejavu-1.5.6~rc2+cvs.20110926/DejaVu/Geom.py mgltools-dejavu-1.5.6~rc2+cvs.20111222/DejaVu/Geom.py --- mgltools-dejavu-1.5.6~rc2+cvs.20110926/DejaVu/Geom.py 2011-06-07 23:12:46.000000000 +0000 +++ mgltools-dejavu-1.5.6~rc2+cvs.20111222/DejaVu/Geom.py 2011-10-10 22:08:37.000000000 +0000 @@ -11,9 +11,9 @@ ############################################################################# # -# $Header: /opt/cvs/python/packages/share1.5/DejaVu/Geom.py,v 1.265 2011/06/07 23:12:46 annao Exp $ +# $Header: /opt/cvs/python/packages/share1.5/DejaVu/Geom.py,v 1.266 2011/10/10 22:08:37 sanner Exp $ # -# $Id: Geom.py,v 1.265 2011/06/07 23:12:46 annao Exp $ +# $Id: Geom.py,v 1.266 2011/10/10 22:08:37 sanner Exp $ # import numpy @@ -424,6 +424,9 @@ lines.append(indent+" clip = %s.viewer.clipP[%d]\n"%( geomName, i)) lines.append(indent+" %s.AddClipPlane(clip, %s.clipSide[clip.num], True)\n"%(geomName,geomName)) + if self.capMesh: + lines.append(indent+" clip.ClipCapMesh(obj, 1)\n") + lines.append(indent+" pass ## needed in case there no modif\n") lines.append(indent+"## End Clipping Planes for %s\n\n"%self.name) diff -Nru mgltools-dejavu-1.5.6~rc2+cvs.20110926/DejaVu/shaders/fragNormal mgltools-dejavu-1.5.6~rc2+cvs.20111222/DejaVu/shaders/fragNormal --- mgltools-dejavu-1.5.6~rc2+cvs.20110926/DejaVu/shaders/fragNormal 1970-01-01 00:00:00.000000000 +0000 +++ mgltools-dejavu-1.5.6~rc2+cvs.20111222/DejaVu/shaders/fragNormal 2011-10-10 21:56:36.000000000 +0000 @@ -0,0 +1,6 @@ +varying vec3 vertex_color; +void main (void) +{ + gl_FragColor = vec4(vertex_color,1.0); + //gl_FragColor = vec4(1.0,0.0,0.0,1.0); +} \ No newline at end of file diff -Nru mgltools-dejavu-1.5.6~rc2+cvs.20110926/DejaVu/shaders/fragSSAO mgltools-dejavu-1.5.6~rc2+cvs.20111222/DejaVu/shaders/fragSSAO --- mgltools-dejavu-1.5.6~rc2+cvs.20110926/DejaVu/shaders/fragSSAO 1970-01-01 00:00:00.000000000 +0000 +++ mgltools-dejavu-1.5.6~rc2+cvs.20111222/DejaVu/shaders/fragSSAO 2011-10-20 22:22:59.000000000 +0000 @@ -0,0 +1,344 @@ +uniform sampler2D DepthTexture; +uniform sampler2D RenderedTexture;//RGB...Should try RGBA ie fog, transparancy +uniform sampler2D LuminanceTexture; +uniform sampler2D RandomTexture; // for method 2 +uniform sampler2D DepthMaskTexture; // for method 2 + +uniform float RenderedTextureWidth; +uniform float RenderedTextureHeight; +uniform float near; +uniform float far; +uniform float realfar; +//uniform float fogE; +//uniform float fogS; +uniform int method; +//OPTIONS TO EXPLORE +uniform int do_noise; +uniform int only_ssao; +uniform int only_depth; +uniform int mix_depth; +uniform int use_mask_depth; +uniform int show_mask_depth; +uniform int negative; +uniform float scale; +uniform int samples;// = 3; //samples on the each ring (3-7) +uniform int rings;// = 3; //ring count (2-8) +uniform float aoCap;// = 1.0; +uniform float aoMultiplier;// = 100.0; +uniform float depthTolerance;// = 0.0000; +uniform float aorange;// = 160.0;//60 units in space the AO effect extends to (this gets divided by the camera far range +//FOG options +uniform int fog; +uniform int use_fog; +uniform float correction; + +//need to handle transparancy and depthcuing/fog +#define PI 3.14159265 + +//method2 TO BE DONE +//uniform float zFar; +//uniform float SampleRad; +//uniform float Intensity; +//uniform float Scale; +//uniform float Bias; +float SampleRad=3.0; +float Intensity=1.0; +float Scale=1.0; +float Bias=0.1; + +//varying var for method 1 +varying vec2 texCoords; +varying vec3 vCoords; +varying vec2 vTexCoord; + +varying vec4 test; + +//varying var for method 2 +varying vec3 normal; +//varying vec4 pos; + +float textureSize =RenderedTextureWidth; //size of the texture +float texelSize = 1.0 / textureSize; //size of one texel +float width = RenderedTextureWidth; //texture width +float height = RenderedTextureHeight; //texture height + + +//int samples = 3; //samples on the each ring (3-7) +//int rings = 3; //ring count (2-8) + +float random_size = 64.0; // size of random texture + +//vec2 texCoord = gl_TexCoord[0].xy;//st; + + +vec2 getRandom(in vec2 uv){ + float u = (fract(uv.x * (width/2.0))*0.25); + float v = (fract(uv.y * (height/2.0))*0.75); + return vec2(u,v); + } + +vec2 rand(in vec2 coord) { + //generating random noise + float noiseX = (fract(sin(dot(coord ,vec2(12.9898,78.233))) * 43758.5453)); + float noiseY = (fract(sin(dot(coord ,vec2(12.9898,78.233)*2.0)) * 43758.5453)); + return vec2(noiseX,noiseY)*0.004; + } + +vec4 texture2DBilinear(in sampler2D textureSampler, in vec2 uv ){ + // in vertex shaders you should use texture2DLod instead of texture2D + vec4 tl = texture2D(textureSampler, uv); + vec4 tr = texture2D(textureSampler, uv + vec2(texelSize, 0)); + vec4 bl = texture2D(textureSampler, uv + vec2(0, texelSize)); + vec4 br = texture2D(textureSampler, uv + vec2(texelSize , texelSize)); + vec2 f = fract( uv.xy * textureSize ); // get the decimal part + vec4 tA = mix( tl, tr, f.x ); // will interpolate the red dot in the image + vec4 tB = mix( bl, br, f.x ); // will interpolate the blue dot in the image + return mix( tA, tB, f.y ); // will interpolate the green dot in the image + } + + +float scaleNearFar(in float val, in float near, in float far){ + float res = 0.0; + //res = 1.0 / (far + near -val*(far-near)); + //if (val > 1.0){return 1.0;} + //if (val < 0.0){return 0.0;} + res = (2.0*near) / (far + near - val* (far-near)); + return res; +} + +float readDepth(in vec2 coord){ + //linearisation of depth but already done + vec4 val = texture2D(DepthTexture, coord ); + return scaleNearFar(val.x,near,far);//(2.0*near) / (far + near - val.x* (far-near)); + } + +float readMaskDepth(in vec2 coord){ + //linearisation of depth but already done + vec4 val = texture2D(DepthMaskTexture, coord ); + return scaleNearFar(val.x,near,far); + } + + +float compareDepths( in float depth1, in float depth2 ){ + float diff = sqrt(clamp(1.0-(depth1-depth2) / (aorange/(far-near)),0.0,1.0)); + float ao = min(aoCap,max(0.0,depth1-depth2-depthTolerance) * aoMultiplier) * diff; + return ao; + } + +float computeAO(in vec2 scrCoord){ + float depth = readDepth(scrCoord); + float d; + float aspect = RenderedTextureWidth/RenderedTextureHeight; + vec2 noise = rand(scrCoord);//getRandom(srcCoord);// + float w; + float h; + if (do_noise == 1) { + w = (1.0 / RenderedTextureWidth)/clamp(depth,0.05,1.0)+(noise.x*(1.0-noise.x))*scale; + h = (1.0 / RenderedTextureHeight)/clamp(depth,0.05,1.0)+(noise.y*(1.0-noise.y))*scale; + } + else { + w = (1.0 / RenderedTextureWidth)/clamp(depth,0.05,1.0)+0.001*scale;//+(noise.x*(1.0-noise.x)); + h = (1.0 / RenderedTextureHeight)/clamp(depth,0.05,1.0)+0.001*scale;//+(noise.y*(1.0-noise.y)); + } + float pw; + float ph; + + float ao; + float s; + + int ringsamples; + for (int i = 1; i <= rings; i += 1){ + ringsamples = i * samples; + for (int j = 0 ; j < ringsamples ; j += 1) { + float step = PI*2.0 / float(ringsamples); + pw = (cos(float(j)*step)*float(i)); + ph = (sin(float(j)*step)*float(i))*aspect; + d = readDepth( vec2(scrCoord.s+pw*w,scrCoord.t+ph*h)); + ao += compareDepths(depth,d); + s += 1.0; + } + } + ao /= s; + ao = 1.0-ao; + return ao; + } + +float compareFog( in float depth1, in float depth2 ){ + float diff = sqrt(clamp(1.0-(depth1-depth2) / (1.0/(far-near)),0.0,1.0)); + //float ao = min(aoCap,max(0.0,depth1-depth2-depthTolerance) * aoMultiplier) * diff; + return diff; + } + + +float getfog(in vec2 scrCoord) { + vec4 val = texture2D(DepthTexture, scrCoord ); + float fogFactor = 1.0; + float f; + const float LOG2 = 1.442695; + float d0 = scaleNearFar(0.,near,realfar);//(2.0 * near) / (realfar + near); + float d1 = scaleNearFar(1.,near,realfar);//(2.0 * near) / (realfar + near - (realfar-near)); + float d = scaleNearFar(val.x,near,realfar);//(2.0 * near) / (realfar + near - val.x* (realfar-near));//readDepth(scrCoord);//val.x;//need real far + vec3 coord = vec3(scrCoord.x,scrCoord.y,val.x); + float fogc = length(coord); //val.x;//val.x;//length(coord); //distance from the camera ? + //GL_LINEAR + //float correction = 6.0;//scaleNearFar(60.0,near,realfar); + float st = d0 + ((gl_Fog.start + correction) / (realfar-near))*(d1-d0); + float en = d0 + ((gl_Fog.end + correction) / (realfar-near))*(d1-d0); + if (den) { + f = 0.0;//was 0.0, avoid overlay of bg color + } else { + f = (en-d) /(en-st); + } + if (val.x >= 1.0) {f = 1.0;} + fogFactor = clamp(f, 0.0, 1.0); + return fogFactor; +} + +vec4 combineAO(in float ao,in vec2 scrCoord){ + vec4 result = vec4(1.0,1.0,1.0,1.0); + vec3 white = vec3(1.0,1.0,1.0); + vec3 black = vec3(0.0,0.0,0.0); + vec3 treshold = vec3(0.2,0.2,0.2); + float d = 0.; + float md = 0.; + float fogf = 0.; + vec3 luminance = texture2D(LuminanceTexture, scrCoord).rgb; + luminance = clamp(max(black,luminance-treshold)+max(black,luminance-treshold)+max(black,luminance-treshold),0.0,1.0); + /*if (fog == 1) { + if (use_fog == 1) { + fogf = getfog(scrCoord);//0 no fog, 1 fog + ao = 1. - ((1. - ao) * fogf); + ao = fogf;//clamp(ao, 0.0, 1.0); + } + } */ + if (use_mask_depth == 1){ + md = texture2D(DepthMaskTexture, scrCoord ).x;//readMaskDepth(scrCoord); + if (d < 1.0) { + d = texture2D(DepthTexture, scrCoord ).x; + if (d == md ){ + ao = 1.0;//no ao white + } + } + } + result = vec4(mix(vec3(ao,ao,ao),luminance,black),1.0); + if (fog == 1) { + if (use_fog == 1) { + fogf = getfog(scrCoord); // 1 no fog, 0 fog + //result = mix(gl_Fog.color, result, fogf ); + // we use sin(fogf*PI*.5)) to attenuate the AO slower when we are close to fog start + // and faster toward fog end + result = vec4(mix(gl_Fog.color.rgb,result.rgb,sin(fogf*PI*.5)),1.0); + } + } + return result; + } + +float calcAO(in vec2 uv, in vec2 coord, in float depth, in vec3 norm){ + //vec3 diff = texture2D(DepthTexture, uv + coord).xyz - pos; + float diff = readDepth(uv + coord) - depth; + //vec3 v = normalize(diff); + vec3 v = normalize(vec3(diff,diff,diff)); + //float d = diff * Scale; + float d = length(vec3(diff,diff,diff)) * Scale; + //return max(0.0, dot(norm, v) - Bias) * (1.0 / (1.0 + d)) * Intensity; + return max(0.0, dot(norm, v) - Bias) * (1.0 / (1.0 + d)) * Intensity; + } + +/*float computeAONormal(in vec2 uv){ + vec2 rand; + vec3 n; + + vec2 vec[4]; + vec[0] = vec2(1, 0); + vec[1] = vec2(-1, 0); + vec[2] = vec2(0, 1); + vec[3] = vec2(0, -1); + + vec2 randomMap = texture2D(RandomTexture, vec2(64,64) * uv / random_size).xy; + vec3 normalMap = normal.xyz; + //vec3 pos = texture2D(DepthTexture, uv).xyz;//depth + float depth = readDepth(uv); + n = normalize(normalMap * 2.0 - 1.0); + rand = normalize(randomMap * 2.0 - 1.0); + + float ao = 0.0; + float rad = SampleRad / depth; + + int iterations = int(mix(4.0, 1.0, - depth/far)); + for (int i = 0; i < iterations; ++i) { + vec2 coord1 = reflect(vec[i], rand) * rad; + vec2 coord2 = vec2(coord1.x * 0.707 - coord1.y * 0.707, coord1.x * 0.707 + coord1.y * 0.707); + + ao += calcAO(uv, coord1 * 0.25, depth, n); + ao += calcAO(uv, coord2 * 0.5,depth, n); + ao += calcAO(uv, coord1 * 0.75, depth, n); + ao += calcAO(uv, coord2, depth, n); + } + ao /= float(iterations) * 4.0; + return ao; + } +*/ + + +vec4 Posterization(in vec3 color){ + float gamma = 0.5; + float numColors = 10.0; + vec3 c = pow(color, vec3(gamma, gamma, gamma)); + c = c * numColors; + + c = floor(c); + + c = c / numColors; + + c = pow(c, vec3(1.0/gamma)); + + return vec4(c, 1.0); + +} + + + +void main() { + vec4 result = vec4(0.0); + //vec2 coord=(test.xy/test.w+1.0)*0.5; + vec2 scrCoord = vec2 (1.0 / width, 1.0 / height) * gl_FragCoord.xy; + vec4 color = texture2D(RenderedTexture, scrCoord); + float d = readDepth(scrCoord); + float ao; + float fogf = 0.; + result = color ; + + if (method == 0){ + ao = computeAO(scrCoord); + ao = clamp(ao,0.0,1.0); + if ( ao > 1.0 ) {ao = 1.0 ;} + if ( ao < 0.0 ) {ao = 0.0 ;} + if (d > 1.0 ) {ao = 1.0 ;} + if (d < 0.0 ) {ao = 0.0 ;} + } + + vec4 mixed = combineAO(ao,scrCoord); + + if (only_ssao == 1) { + result = mixed; + } + else { + result = vec4(color.rgb*mixed.rgb,1.0);//color.a + } + if (show_mask_depth == 1){ + float d = readMaskDepth(scrCoord);//texture2D(DepthMaskTexture, scrCoord ).x;//readMaskDepth(scrCoord); + result = vec4(d,d,d,1.0);//texture2D(DepthMaskTexture, scrCoord ); + } + else if ( (only_depth == 1) || (mix_depth == 1) ){ + float d = readDepth(scrCoord); + if (negative == 1) {d = 1.0 - d;} + result = vec4(d,d,d,1.0); + if (mix_depth == 1) { + result = vec4(color.rgb*result.rgb,1.0); + } + } + + gl_FragColor = result;//result;//result; +} diff -Nru mgltools-dejavu-1.5.6~rc2+cvs.20110926/DejaVu/shaders/vertNormal mgltools-dejavu-1.5.6~rc2+cvs.20111222/DejaVu/shaders/vertNormal --- mgltools-dejavu-1.5.6~rc2+cvs.20110926/DejaVu/shaders/vertNormal 1970-01-01 00:00:00.000000000 +0000 +++ mgltools-dejavu-1.5.6~rc2+cvs.20111222/DejaVu/shaders/vertNormal 2011-10-10 21:56:36.000000000 +0000 @@ -0,0 +1,10 @@ +//varying vec2 texCoord; +varying vec3 vertex_color; +void main (void) +{ + //TexCoord = gl_MultiTexCoord0; + //texCoord = gl_MultiTexCoord0; + //gl_Position = ftransform(); + gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; + vertex_color = gl_Normal.xyz; +} \ No newline at end of file diff -Nru mgltools-dejavu-1.5.6~rc2+cvs.20110926/DejaVu/shaders/vertSSAO mgltools-dejavu-1.5.6~rc2+cvs.20111222/DejaVu/shaders/vertSSAO --- mgltools-dejavu-1.5.6~rc2+cvs.20110926/DejaVu/shaders/vertSSAO 1970-01-01 00:00:00.000000000 +0000 +++ mgltools-dejavu-1.5.6~rc2+cvs.20111222/DejaVu/shaders/vertSSAO 2011-10-20 22:22:59.000000000 +0000 @@ -0,0 +1,24 @@ +varying vec2 texCoords; +varying vec3 vCoords; +//varying vec4 test; +varying vec2 vTexCoord; +varying vec3 normal; +//varying vec4 pos; + +void main (void) +{ + gl_FrontColor = gl_Color;//gl_Normal for normal map + gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; + //gl_TexCoord[0] = gl_MultiTexCoord0; + //vTexCoord = (gl_ModelViewProjectionMatrix * gl_Vertex).xy;//(gl_TextureMatrix[0] * gl_Vertex).xy; + //vCoords = (gl_ModelViewProjectionMatrix * gl_Vertex).xyz; + //vec4 t = gl ModelViewMatrix * gl_Vertex; + //test = gl_ModelViewProjectionMatrix * gl_Vertex;// gl_Position.w; + //test = test / test.w; + //test = test / test.w ; + //viweport transformation ? + //normal = normalize(gl_NormalMatrix * gl_Normal.xyz); + normal = vec3(gl_ModelViewMatrix * vec4(gl_Normal,0.0)); + //pos = gl_Vertex; + +} diff -Nru mgltools-dejavu-1.5.6~rc2+cvs.20110926/DejaVu/Tests/test_Camera.py mgltools-dejavu-1.5.6~rc2+cvs.20111222/DejaVu/Tests/test_Camera.py --- mgltools-dejavu-1.5.6~rc2+cvs.20110926/DejaVu/Tests/test_Camera.py 2011-09-02 18:32:12.000000000 +0000 +++ mgltools-dejavu-1.5.6~rc2+cvs.20111222/DejaVu/Tests/test_Camera.py 2011-11-07 23:58:26.000000000 +0000 @@ -2,7 +2,7 @@ # # -# $Id: test_Camera.py,v 1.57 2011/09/02 18:32:12 annao Exp $ +# $Id: test_Camera.py,v 1.58 2011/11/07 23:58:26 annao Exp $ # # @@ -712,7 +712,7 @@ lSumList = [180897624, #rapa 175905763, #austral - 180898721, #jacob + 180877592, #jacob 180898731, #mslaptop4 175912068, #mslaptop1 ] diff -Nru mgltools-dejavu-1.5.6~rc2+cvs.20110926/DejaVu/ViewerGUI.py mgltools-dejavu-1.5.6~rc2+cvs.20111222/DejaVu/ViewerGUI.py --- mgltools-dejavu-1.5.6~rc2+cvs.20110926/DejaVu/ViewerGUI.py 2011-06-15 22:40:12.000000000 +0000 +++ mgltools-dejavu-1.5.6~rc2+cvs.20111222/DejaVu/ViewerGUI.py 2011-10-13 15:53:53.000000000 +0000 @@ -10,9 +10,9 @@ # ############################################################################# # -# $Header: /opt/cvs/python/packages/share1.5/DejaVu/ViewerGUI.py,v 1.235 2011/06/15 22:40:12 sanner Exp $ +# $Header: /opt/cvs/python/packages/share1.5/DejaVu/ViewerGUI.py,v 1.237 2011/10/13 15:53:53 autin Exp $ # -# $Id: ViewerGUI.py,v 1.235 2011/06/15 22:40:12 sanner Exp $ +# $Id: ViewerGUI.py,v 1.237 2011/10/13 15:53:53 autin Exp $ # import types, numpy @@ -1232,6 +1232,31 @@ self.d1scalewheel.set(self.viewer.currentCamera.d1scale) self.d1scalewheel.callbacks.AddCallback(self.setNPR_cb) + +#=============================================================================== +# Screen Space Ambient Occlusion +#=============================================================================== + Checkbutton_button = Menubutton(self.CameraProp, + text='Screen Space Ambient Occlusion', + underline=0, relief='raised') + Checkbutton_button.bind('', toggleMenu, '+') + Checkbutton_button.pack(fill=X, padx=5) + + self.ssaoTk = BooleanVar() + self.ssaoTk.set(self.viewer.currentCamera.ssao) + Checkbutton_button.menu=Menu(Checkbutton_button) + + # TOGGLE + Checkbutton_button.menu.add_checkbutton(label='On', + var = self.ssaoTk, + command=self.toggleSSAO) + #SET SSAO PARAMETERS + Checkbutton_button.menu.add_command( + label='Edit Parameters', + command=self.showSSAOTool) + Checkbutton_button['menu'] = Checkbutton_button.menu + + # occlusion cam GUI b = Button(self.CameraProp, text='Ambient Occlusion', @@ -2854,6 +2879,56 @@ if self.GraphToolpanel.winfo_ismapped()==0: self.GraphToolpanel.deiconify() self.GraphToolpanel.lift() + + def showSSAOTool(self,event=None): + #should show some windowswith ssa optio...and pass the option + #pass + camera = self.viewer.currentCamera + if not hasattr(self,"ssao_options_w"): + self.ssao_options_w = Toplevel(self.root) + self.ssao_options_w.title("SSAO") + #should put here preset, quality ? scale ? + #pull-down menu with preset + #need an advanced button that will show the advance oiption -> collapsable ? + self.ssao_options_w_widget ={} + Label(self.ssao_options_w, text="Screen Space Ambient Occlusion").grid(row=0, column=0, columnspan = 2,sticky='w') + r=1 + #order? + for k in camera.SSAO_OPTIONS_ORDER: + elem = camera.SSAO_OPTIONS[k] + Label(self.ssao_options_w, text=k).grid(row=r, column=0, sticky='w') + def updateSSAO_OPTIONS_cb(*args,**kw): + self.viewer.Redraw() + if k in ["do_noise","only_ssao","use_mask_depth","show_mask_depth", + "fog","use_fog","only_depth","mix_depth","negative"]: + pw = Tkinter.IntVar() + w = Tkinter.Checkbutton(self.ssao_options_w, + var=pw,command=updateSSAO_OPTIONS_cb) + w.grid(row=r, column=1, columnspan=3) + pw.set(camera.SSAO_OPTIONS[k][0]) + else : + pw = ThumbWheel(self.ssao_options_w, + showLabel=1, width=60, height=16, type=elem[3], value=elem[0], + callback=updateSSAO_OPTIONS_cb, continuous=True, oneTurn=10.,min=elem[1], + wheelPad=2, #labCfg = {'text':'fog end:', 'side':'left'} + ) + pw.grid(row=r, column=1, columnspan=3) + camera.SSAO_OPTIONS[k].append(pw) + self.ssao_options_w_widget[k] = pw + r+=1 + self.ssao_options_w.protocol('WM_DELETE_WINDOW', self.ssao_options_w.withdraw) + else : + for k in camera.SSAO_OPTIONS: + elem = camera.SSAO_OPTIONS[k] + self.ssao_options_w_widget[k].set(elem[0]) + if len(elem) < 5 : + camera.SSAO_OPTIONS[k].append(self.ssao_options_w_widget[k]) + self.ssao_options_w.deiconify() + + def toggleSSAO(self, event=None): + camera = self.viewer.currentCamera + camera.ssao = self.ssaoTk.get() + self.viewer.Redraw() def showHistogram(self): camera = self.viewer.currentCamera diff -Nru mgltools-dejavu-1.5.6~rc2+cvs.20110926/DejaVu/Viewer.py mgltools-dejavu-1.5.6~rc2+cvs.20111222/DejaVu/Viewer.py --- mgltools-dejavu-1.5.6~rc2+cvs.20110926/DejaVu/Viewer.py 2011-08-31 22:10:26.000000000 +0000 +++ mgltools-dejavu-1.5.6~rc2+cvs.20111222/DejaVu/Viewer.py 2011-10-14 19:13:34.000000000 +0000 @@ -17,9 +17,9 @@ # ######################################################################### # -# $Header: /opt/cvs/python/packages/share1.5/DejaVu/Viewer.py,v 1.359 2011/08/31 22:10:26 sanner Exp $ +# $Header: /opt/cvs/python/packages/share1.5/DejaVu/Viewer.py,v 1.361 2011/10/14 19:13:34 sanner Exp $ # -# $Id: Viewer.py,v 1.359 2011/08/31 22:10:26 sanner Exp $ +# $Id: Viewer.py,v 1.361 2011/10/14 19:13:34 sanner Exp $ # import warnings @@ -298,6 +298,8 @@ c.eventManager.AddCallback('t', self.toggleTransformRootOnly) c.eventManager.AddCallback('L', self.toggleOpenglLighting) c.eventManager.AddCallback('l', self.toggleOpenglLighting) + c.eventManager.AddCallback('O', self.SSAO_cb_arg) + c.eventManager.AddCallback('o', self.SSAO_cb_arg) c.ownMaster = cameraOwnsMaster if self.GUI is not None: @@ -1424,6 +1426,11 @@ self.GUI.depthcued.set( not self.GUI.depthcued.get() ) self.GUI.ToggleDepth() + def SSAO_cb_arg(self,event): + self.currentCamera.ssao = not self.currentCamera.ssao + if self.GUI is not None: + self.GUI.ssaoTk.set(self.currentCamera.ssao) + self.Redraw() def CurrentCameraBackgroundColor(self, col): """Method to be bound to a GUI widget""" @@ -1906,6 +1913,16 @@ c.exposeEvent = False if self.tileRender: + ## SSAO does not work with tile rendering so we turn it off + ## do the tile rendering, then render the AO mask in a single + ## tile, scale and blur it and composite it with the large + ## image + ssaoWasOn = False # use to restore SSAO mode + if c.ssao: + c.ssao = False # turn SSAO off + ssaoWasOn = True # remember it was on + + # do regular tile rendering c.lift() tr = self.tileRenderCtx print 'tile size', c.width, c.height, self.tileRenderBorder @@ -2019,9 +2036,34 @@ imageFinal = Image.new('RGB', (w, self.tileRenderFinalHeight) ) imageFinal.paste( im[0], (0 , 0) ) imageFinal.paste( im[1], (self.tileRenderFinalWidth , 0) ) - imageFinal.save(self.tileRenderOutput) + tileRenderedImage = imageFinal else: - im[0].save(self.tileRenderOutput) + tileRenderedImage = im[0] + + # if SSAO was on we will now do an additional redraw with + # SSAO on only_ssao mode to create the mask + if ssaoWasOn: + self.tileRender = False + c.ssao = True + old = c.SSAO_OPTIONS['only_ssao'][0] + c.SSAO_OPTIONS['only_ssao'][0] = True + c.Redraw() + # get the mask + aoim = c.GrabFrontBuffer(lock=False) + # scale it to cover match the large image + scale = self.tileRenderFinalWidth/float(c.width) + w, h = aoim.size + aoims = aoim.resize( (int(w*scale), int(h*scale)) ) + # blur the mask + import ImageFilter, ImageChops + aoimsb = aoims.filter(ImageFilter.BLUR) + # multiply the large iamge and the mask + result = ImageChops.multiply(tileRenderedImage, aoimsb) + result.save(self.tileRenderOutput) + # restore SSAO mode + c.SSAO_OPTIONS['only_ssao'][0] = old + else: + tileRenderedImage.save(self.tileRenderOutput) except KeyError, e: print "saving failed: unknown extension", e @@ -2041,14 +2083,14 @@ def ReallyRedraw(self): """Redraw the scene""" - if not self.needsRedraw: - self.master.after(10, self.postNextRedrawCheck) + if self.suspendRedraw: + self.master.after(100, self.postNextRedrawCheck) return - if self.suspendRedraw: + if not self.needsRedraw: self.master.after(10, self.postNextRedrawCheck) return - + if len(self.cameras)==0: return True if threading.currentThread().getName()!='MainThread':