Example #1
0
def glLibAccumFilter(scenebuffer,view2d,filter):
    glLibUseShader(None)
    glDisable(GL_LIGHTING)
    glLoadIdentity()

    view2d.set_view()
    size = view2d.rect[2:]
    filtersize = [len(filter[0]),len(filter)]
    total = float(sum([sum(row) for row in filter]))
    if total == 0.0: total = 1.0

    glClear(GL_ACCUM_BUFFER_BIT)
    glLibSelectTexture(scenebuffer)

    xindex = 0
    for xjitter in range((-filtersize[0]//2)+1,(filtersize[0]//2)+1,1):
        yindex = 0
        for yjitter in range((-filtersize[1]//2)+1,(filtersize[1]//2)+1,1):
            glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
            glBegin(GL_QUADS)
            glTexCoord2f(0,0);glVertex2f(xjitter,        yjitter       )
            glTexCoord2f(1,0);glVertex2f(xjitter+size[0],yjitter       )
            glTexCoord2f(1,1);glVertex2f(xjitter+size[0],yjitter+size[1])
            glTexCoord2f(0,1);glVertex2f(xjitter,        yjitter+size[1])
            glEnd()
            glAccum(GL_ACCUM,filter[yindex][xindex]/total)
            yindex += 1
        xindex += 1
    glAccum(GL_RETURN,1.0)
    glEnable(GL_LIGHTING)
Example #2
0
def glLibAccumFilter(scenebuffer,view2d,filter):
    glLibUseShader(None)
    glDisable(GL_LIGHTING)
    glLoadIdentity()

    view2d.set_view()
    size = view2d.rect[2:]
    filtersize = [len(filter[0]),len(filter)]
    total = float(sum([sum(row) for row in filter]))
    if total == 0: total = 1.0

    glClear(GL_ACCUM_BUFFER_BIT)
    glLibSelectTexture(scenebuffer)
    
    xindex = 0
    for xjitter in xrange((-filtersize[0]/2)+1,(filtersize[0]/2)+1,1):
        yindex = 0
        for yjitter in xrange((-filtersize[1]/2)+1,(filtersize[1]/2)+1,1):
            glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
            glBegin(GL_QUADS)
            glTexCoord2f(0,0);glVertex2f(xjitter,        yjitter       )
            glTexCoord2f(1,0);glVertex2f(xjitter+size[0],yjitter       )
            glTexCoord2f(1,1);glVertex2f(xjitter+size[0],yjitter+size[1])
            glTexCoord2f(0,1);glVertex2f(xjitter,        yjitter+size[1])
            glEnd()
            glAccum(GL_ACCUM,filter[yindex][xindex]/total)
            yindex += 1
        xindex += 1
    glAccum(GL_RETURN,1.0)
    glEnable(GL_LIGHTING)
    def draw(self):
        glLibUseShader(self.draw_shader)
        
        self.draw_shader.pass_texture(self.pos_time_texture,1)
        self.draw_shader.pass_texture(self.point_texture,2)
        self.draw_shader.pass_vec3("scale",map(lambda x:2.0*x,self.scale))
        self.draw_shader.pass_float("size",float(self.size[0]))
        self.draw_shader.pass_float("fade",self.fade)
        self.draw_shader.pass_float("point_size",self.psize)
        
        glDisable(GL_LIGHTING)

        glEnable(GL_POINT_SPRITE)
        glBlendFunc(GL_SRC_ALPHA,GL_ONE)
        glDisable(GL_DEPTH_TEST)
        glEnable(GL_VERTEX_PROGRAM_POINT_SIZE)
        
        self.particles.draw()
        
        glDisable(GL_VERTEX_PROGRAM_POINT_SIZE)
        glEnable(GL_DEPTH_TEST)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
        glDisable(GL_POINT_SPRITE)
        
        glLibUseShader(None)

##        glDisable(GL_BLEND)
##        self.view_2D.set_view()
##        glLibSelectTexture(self.pos_time_texture)
##        glLibTexFullScreenQuad()
##        glEnable(GL_BLEND)

        glEnable(GL_LIGHTING)
Example #4
0
def glLibInternal_CausticMap       (fbo, lightview,objpos,shader,causticgrid,causticgridscalar,particlesize,particlebrightness,eta,posmaps,normmaps,causticmap,     filtering      ):
    if fbo != None:
        fbo.enable([1])
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
    glLoadIdentity()
    View2D = glLibView2D(lightview.rect)
    View2D.set_view()
    glLibUseShader(shader)
    for index in xrange(2,2*len(posmaps)+2,2):
        shader.pass_texture(posmaps [index-2],index  )
        shader.pass_texture(normmaps[index-2],index+1)
    shader.pass_texture(GLLIB_CAUSTIC_POINT,1)
    shader.pass_float("eta",eta)
    shader.pass_float("brightness",particlebrightness)
    shader.pass_vec2("size",lightview.rect[2:])
    shader.pass_float("grid_sc",causticgridscalar)
    ptsize = glGetFloatv(GL_POINT_SIZE)
    glPointSize(particlesize)
    glEnable(GL_POINT_SPRITE)
    glBlendFunc(GL_SRC_ALPHA, GL_ONE)
    glDisable(GL_DEPTH_TEST)
    causticgrid.draw()
    glEnable(GL_DEPTH_TEST)
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
    glDisable(GL_POINT_SPRITE)
    glPointSize(ptsize)
    glLibUseShader(None)
    if fbo != None:
        fbo.disable()
        causticmap = fbo.get_texture(1)
    else:
        causticmap = glLibSceneToTexture(lightview.rect,causticmap,GLLIB_RGB,filtering)
##        glLibScreenshot("caustics.png",rect=GLLIB_AUTO,type=GLLIB_RGB,framebuffer=0,overwrite=True)
    return causticmap
Example #5
0
 def draw_as_sphere(self,size=0.05,detail=10):
     glLibUseShader(None)
     glDisable(GL_LIGHTING)
     glDisable(GL_TEXTURE_2D)
     glPushMatrix()
     glTranslatef(*self.pos)
     Sphere = gluNewQuadric()
     gluSphere(Sphere,size,detail,detail)
     glPopMatrix()
     glEnable(GL_TEXTURE_2D)
     glEnable(GL_LIGHTING)
Example #6
0
def glLibInternal_CausticPositionMap       (fbo1,fbo2,light,lightview,objpos,num,shader,draw_receivers_func,draw_refractors_func,draw_reflectors_func,posmaps,     normmaps,     filtering,      precision  ):
    global glLibInternal_depth_tex
    glLibUseShader(shader)
    lightpos = light.get_pos()
    shader.pass_vec3("lightpos",lightpos)
    shader.pass_vec2("size",lightview.rect[2:])
    outposmaps = []
    outnormmaps = []
    ping_pong = 1
    for render_pass in xrange(1,num+1,1):
        if fbo1 != None:
            if ping_pong == 1: fbo1.enable([1,2,3])
            else:              fbo2.enable([1,2,3])
        glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
        glLoadIdentity()
        lightview.set_view()
        gluLookAt(lightpos[0],lightpos[1],lightpos[2],objpos[0],objpos[1],objpos[2],0,1,0)
        shader.pass_int("render_pass",render_pass)
        if render_pass>1: shader.pass_texture(glLibInternal_depth_tex,1)
        if fbo1 == None:
            shader.pass_int("fbotype",1)
            shader.pass_bool("stage1",True)
            glLibInternal_CausticPositionMap_drawscene(shader,draw_receivers_func,draw_refractors_func,draw_reflectors_func)
            posmap = glLibSceneToTexture(lightview.rect,posmaps[render_pass-1],GLLIB_RGB)
##            glLibScreenshot("posmap"+str(render_pass)+".png",rect=GLLIB_AUTO,type=GLLIB_RGB,framebuffer=0,overwrite=True)
            glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
            shader.pass_bool("stage1",False)
            draw_reflectors_func(); draw_refractors_func()
            normmap = glLibSceneToTexture(lightview.rect,normmaps[render_pass-1],GLLIB_RGB)
##            glLibScreenshot("normmap"+str(render_pass)+".png",rect=GLLIB_AUTO,type=GLLIB_RGB,framebuffer=0,overwrite=True)
            glLibInternal_depth_tex = glLibSceneToTexture(lightview.rect,glLibInternal_depth_tex,GLLIB_DEPTH)
        else:
            shader.pass_int("fbotype",2)
            glLibInternal_CausticPositionMap_drawscene(shader,draw_receivers_func,draw_refractors_func,draw_reflectors_func)
##            glLibScreenshot("posmap"+str(render_pass)+".png",rect=GLLIB_AUTO,type=GLLIB_RGB,framebuffer=1,overwrite=True)
##            glLibScreenshot("normmap"+str(render_pass)+".png",rect=GLLIB_AUTO,type=GLLIB_RGB,framebuffer=2,overwrite=True)
##            glLibScreenshot("depth"+str(render_pass)+".png",rect=GLLIB_AUTO,type=GLLIB_DEPTH,framebuffer=3,overwrite=True)
            if ping_pong == 1:
                fbo1.disable()
                posmap = fbo1.get_texture(1); normmap = fbo1.get_texture(2)
                glLibInternal_depth_tex = fbo1.get_texture(3)
            else:
                fbo2.disable()
                posmap = fbo2.get_texture(1); normmap = fbo2.get_texture(2)
                glLibInternal_depth_tex = fbo2.get_texture(3)
            ping_pong = 3 - ping_pong
        outposmaps.append(posmap)
        outnormmaps.append(normmap)
    glLibUseShader(None)
    return [outposmaps,outnormmaps]
Example #7
0
def glLibInternal_CausticPositionNormalMap       (fbo1,fbo2,light,lightview,objpos,num,shader,draw_receivers_func,draw_refractors_func,draw_reflectors_func,posmaps,     normmaps,     filtering,      precision  ):
    global glLibInternal_depth_tex
    glLibUseShader(shader)
    lightpos = light.get_pos()
##    shader.pass_vec3("lightpos",lightpos)
    shader.pass_vec2("size",lightview.rect[2:])
    outposmaps = []
    outnormmaps = []
    ping_pong = 1
    for render_pass in range(1,num+1,1):
        if fbo1 != None:
            if ping_pong == 1: fbo1.enable([1,2])#,3])
            else:              fbo2.enable([1,2])#,3])
        glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
        glLoadIdentity()
        lightview.set_view()
        gluLookAt(lightpos[0],lightpos[1],lightpos[2],objpos[0],objpos[1],objpos[2],0,1,0)
        shader.pass_int("render_pass",render_pass)
        if render_pass>1: shader.pass_texture(glLibInternal_depth_tex,1)
        if fbo1 == None:
            shader.pass_int("fbotype",1)
            shader.pass_bool("stage1",True)
            glLibInternal_CausticPositionMap_drawscene(shader,draw_receivers_func,draw_refractors_func,draw_reflectors_func)
            posmap = glLibSceneToTexture(lightview.rect,posmaps[render_pass-1],GLLIB_RGB)
##            glLibScreenshot("posmap"+str(render_pass)+".png",rect=GLLIB_AUTO,type=GLLIB_RGB,framebuffer=0,overwrite=True)
            glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
            shader.pass_bool("stage1",False)
            draw_reflectors_func(); draw_refractors_func()
            normmap = glLibSceneToTexture(lightview.rect,normmaps[render_pass-1],GLLIB_RGB)
##            glLibScreenshot("normmap"+str(render_pass)+".png",rect=GLLIB_AUTO,type=GLLIB_RGB,framebuffer=0,overwrite=True)
            glLibInternal_depth_tex = glLibSceneToTexture(lightview.rect,glLibInternal_depth_tex,GLLIB_DEPTH)
        else:
            shader.pass_int("fbotype",2)
            glLibInternal_CausticPositionMap_drawscene(shader,draw_receivers_func,draw_refractors_func,draw_reflectors_func)
##            glLibScreenshot("posmap"+str(render_pass)+".png",rect=GLLIB_AUTO,type=GLLIB_RGB,framebuffer=1,overwrite=True)
##            glLibScreenshot("normmap"+str(render_pass)+".png",rect=GLLIB_AUTO,type=GLLIB_RGB,framebuffer=2,overwrite=True)
##            glLibScreenshot("depth"+str(render_pass)+".png",rect=GLLIB_AUTO,type=GLLIB_DEPTH,framebuffer=3,overwrite=True)
            if ping_pong == 1:
                fbo1.disable()
                posmap = fbo1.get_texture(1); normmap = fbo1.get_texture(2)
##                glLibInternal_depth_tex = fbo1.get_texture(3)
            else:
                fbo2.disable()
                posmap = fbo2.get_texture(1); normmap = fbo2.get_texture(2)
##                glLibInternal_depth_tex = fbo2.get_texture(3)
            ping_pong = 3 - ping_pong
        outposmaps.append(posmap)
        outnormmaps.append(normmap)
    glLibUseShader(None)
    return [outposmaps,outnormmaps]
Example #8
0
def glLibDrawWithShadowMaps(shadowmaps,index,ShadowShader,func): #for shadows
    glLibUseShader(ShadowShader)
    for shadowmap in shadowmaps:
        ShadowShader.pass_texture(shadowmap[0],index)
        glMatrixMode(GL_TEXTURE)
        glPushMatrix()
        glLoadMatrixf([[0.5,0.0,0.0,0.0],
                       [0.0,0.5,0.0,0.0],
                       [0.0,0.0,0.5,0.0],
                       [0.5,0.5,0.5,1.0]])
        glMultMatrixf(shadowmap[1])
        glMultMatrixf(shadowmap[2])
        func()
        ShadowShader.pass_mat4("matrix",glGetFloatv(GL_TEXTURE_MATRIX))
        glPopMatrix()
        glMatrixMode(GL_MODELVIEW)
        index += 1
    def update(self):
        glLibPushView()
        glDisable(GL_BLEND)
        
        if self.pingpong == 1:
            if self.get_new:
                self.pos_time_texture = self.framebuffer2.get_texture(1)
            self.velocity_texture = self.framebuffer2.get_texture(2)
            self.framebuffer1.enable([1,2])
        else:
            if self.get_new:
                self.pos_time_texture = self.framebuffer1.get_texture(1)
            self.velocity_texture = self.framebuffer1.get_texture(2)
            self.framebuffer2.enable([1,2])

        glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
        glLoadIdentity()
        self.view_2D.set_view()
        glLibUseShader(self.update_shader)
        self.update_shader.pass_texture(self.pos_time_texture,1)
        self.update_shader.pass_texture(self.velocity_texture,2)
        self.update_shader.pass_texture(self.rand_tex,3)
        self.update_shader.pass_vec3("initialpos",self.origin)
        self.update_shader.pass_vec3("initialspeed",self.initialspeed)
        self.update_shader.pass_vec3("forces",self.forces)
        self.update_shader.pass_vec3("scale",self.scale)
        self.update_shader.pass_vec3("trans",self.trans)
        self.update_shader.pass_vec3("jitter",self.jitter)
        self.update_shader.pass_float("size",float(self.size[0]))
        self.update_shader.pass_float("step",self.density_constant*self.density)
        self.update_shader.pass_vec2("xedge",[self.negx,self.posx])
        self.update_shader.pass_vec2("yedge",[self.negy,self.posy])
        self.update_shader.pass_vec2("zedge",[self.negz,self.posz])
        
        self.particles.draw()
        glLibUseShader(None)

        if self.pingpong == 1:
            self.framebuffer1.disable()
        else:
            self.framebuffer2.disable()

        self.pingpong = 3 - self.pingpong

        glEnable(GL_BLEND)
        glLibPopView()
Example #10
0
def glLibInternal_CausticMap       (fbo, light,lightview,objpos,objtransform,shader,causticgrid,causticgridscalar,particlesize,particlecolordata,posmaps,normmaps,causticmap,     filtering,      precision  ):
    lightpos = light.get_pos()
    if fbo != None:
        fbo.enable([1])
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
    glLoadIdentity()
    View2D = glLibView2D(lightview.rect)
    View2D.set_view()
    glLibUseShader(shader)
    shader.pass_vec2("size",lightview.rect[2:])
    shader.pass_float("grid_sc",causticgridscalar)

    glLibPushView()
    glLoadIdentity()
    lightview.set_view()
    gluLookAt(lightpos[0],lightpos[1],lightpos[2],objpos[0],objpos[1],objpos[2],0.0,1.0,0.0)
    objtransform()
    view_mat = glGetFloatv(GL_MODELVIEW_MATRIX)
    glLibPopView()
    shader.pass_mat4("modelmatrix",view_mat)

    for index in range(2,2*len(posmaps)+2,2):
        shader.pass_texture(posmaps [index-2],index  )
        shader.pass_texture(normmaps[index-2],index+1)
    shader.pass_texture(GLLIB_CAUSTIC_POINT,1)
    ptsize = glGetFloatv(GL_POINT_SIZE)
    glPointSize(particlesize)
    glEnable(GL_POINT_SPRITE)
    glBlendFunc(GL_SRC_ALPHA, GL_ONE)
    glDisable(GL_DEPTH_TEST)
    for colordata in particlecolordata:
        shader.pass_vec3("light_splat_color",colordata[0])
        shader.pass_float("eta",colordata[1])
        causticgrid.draw()
    glEnable(GL_DEPTH_TEST)
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
    glDisable(GL_POINT_SPRITE)
    glPointSize(ptsize)
    glLibUseShader(None)
    if fbo != None:
        fbo.disable()
        causticmap = fbo.get_texture(1)
    else:
        causticmap = glLibSceneToTexture(lightview.rect,causticmap,GLLIB_RGB,filtering,precision=precision)
##        glLibScreenshot("caustics.png",rect=GLLIB_AUTO,type=GLLIB_RGB,framebuffer=0,overwrite=True)
    return causticmap
    def update(self):
        glLibPushView()
        glDisable(GL_BLEND)

        if self.pingpong == 1:
            if self.get_new:
                self.pos_time_texture = self.framebuffer2.get_texture(1)
            self.velocity_texture = self.framebuffer2.get_texture(2)
            self.framebuffer1.enable([1, 2])
        else:
            if self.get_new:
                self.pos_time_texture = self.framebuffer1.get_texture(1)
            self.velocity_texture = self.framebuffer1.get_texture(2)
            self.framebuffer2.enable([1, 2])

        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
        glLoadIdentity()
        self.view_2D.set_view()
        glLibUseShader(self.update_shader)
        self.update_shader.pass_texture(self.pos_time_texture, 1)
        self.update_shader.pass_texture(self.velocity_texture, 2)
        self.update_shader.pass_texture(self.rand_tex, 3)
        self.update_shader.pass_vec3("initialpos", self.origin)
        self.update_shader.pass_vec3("initialspeed", self.initialspeed)
        self.update_shader.pass_vec3("forces", self.forces)
        self.update_shader.pass_vec3("jitter", self.jitter)
        self.update_shader.pass_float("size", float(self.size[0]))
        self.update_shader.pass_float("step",
                                      self.density_constant * self.density)
        self.update_shader.pass_vec2("xedge", [self.negx, self.posx])
        self.update_shader.pass_vec2("yedge", [self.negy, self.posy])
        self.update_shader.pass_vec2("zedge", [self.negz, self.posz])

        self.particles.draw()
        glLibUseShader(None)

        if self.pingpong == 1:
            self.framebuffer1.disable()
        else:
            self.framebuffer2.disable()

        self.pingpong = 3 - self.pingpong

        glEnable(GL_BLEND)
        glLibPopView()
Example #12
0
def glLibDrawWithDepthMaps(depthmaps,index,TransparencyShader,func): #for transparency
    glLibUseShader(TransparencyShader)
    for depthmap in depthmaps[0]:
        glLibActiveTexture(index)
        TransparencyShader.pass_texture(depthmap,index)
        index += 1
    glMatrixMode(GL_TEXTURE)
    glPushMatrix()
    glLoadMatrixf([[0.5,0.0,0.0,0.0],
                   [0.0,0.5,0.0,0.0],
                   [0.0,0.0,0.5,0.0],
                   [0.5,0.5,0.5,1.0]])
    glMultMatrixf(depthmaps[1])
    glMultMatrixf(depthmaps[2])
    func()
    TransparencyShader.pass_mat4("matrix",glGetFloatv(GL_TEXTURE_MATRIX))
    glPopMatrix()
    glMatrixMode(GL_MODELVIEW)
Example #13
0
 def draw_as_point(self,size=3):
     glLibUseShader(None)
     lighting = glGetBooleanv(GL_LIGHTING)
     texturing = glGetBooleanv(GL_TEXTURE_2D)
     r,g,b,a = glGetFloatv(GL_CURRENT_COLOR)
     ptsize = glGetFloatv(GL_POINT_SIZE)
     glDisable(GL_TEXTURE_2D)
     glDisable(GL_LIGHTING)
     glPointSize(size)
     glColor3f(*self.diffuse_color)
     glBegin(GL_POINTS)
     glVertex3f(*self.pos)
     glEnd()
     glPointSize(ptsize)
     glColor4f(r,g,b,a)
     if lighting: glEnable(GL_LIGHTING)
     if texturing: glEnable(GL_TEXTURE_2D)
     return self
Example #14
0
def glLibInternal_DepthPeel       (fbos,pos,view,objpos,num,shader,draw,textures,filtering=False):
    glLibUseShader(shader)
    shader.pass_vec2("size",view.rect[2:])
    shader.pass_bool("stage1",True)

    glLibPushView()

    projmat,viewmat = glLibInternal_set_proj_and_view_matrices(view,pos,objpos)

    out_textures = []
    out2_textures = []
    ping_pong = 1
    for render_pass in range(num):
        if fbos != None:
            fbos[render_pass].enable(GLLIB_ALL)
        glClear(GL_DEPTH_BUFFER_BIT)
        glLoadIdentity()
        view.set_view()
        gluLookAt(pos[0],pos[1],pos[2],objpos[0],objpos[1],objpos[2],0,1,0)
        glEnable(GL_POLYGON_OFFSET_FILL);glPolygonOffset(1.0,1.0)
        draw()
        glPolygonOffset(0,0);glDisable(GL_POLYGON_OFFSET_FILL)
        if fbos != None:
            fbos[render_pass].disable()
            returned_textures = fbos[render_pass].get_textures()
            out_textures.append(returned_textures[0])
            if len(returned_textures)>1:
                out2_textures.append(returned_textures[1:])
        else:
            out_textures.append(glLibSceneToTexture(view.rect,textures[render_pass],GLLIB_DEPTH,filtering,False))
        shader.pass_bool("stage1",False)
        shader.pass_texture(out_textures[-1],2)
        ping_pong = 3 - ping_pong

    glLibPopView()
    glLibUseShader(None)
    out3_textures = []
    for index in range(len(out_textures)):
        out3_textures.append(out_textures[index])
        try:
            for tex in out2_textures[index]:
                out3_textures.append(tex)
        except: pass
    return out3_textures,projmat,viewmat
    def draw(self):
        glLibUseShader(self.draw_shader)

        self.draw_shader.pass_texture(self.pos_time_texture, 1)
        self.draw_shader.pass_texture(self.point_texture, 2)
        self.draw_shader.pass_vec3("scale",
                                   list(map(lambda x: 2.0 * x, self.scale)))
        self.draw_shader.pass_float("size", float(self.size[0]))
        self.draw_shader.pass_float("fade", self.fade)
        self.draw_shader.pass_float("point_size", self.psize)

        old_lighting = glGetInteger(GL_LIGHTING)
        if old_lighting == GL_TRUE:
            glDisable(GL_LIGHTING)

        glEnable(GL_POINT_SPRITE)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE)
        glDisable(GL_DEPTH_TEST)
        glEnable(GL_VERTEX_PROGRAM_POINT_SIZE)

        glTranslatef(*self.trans)
        self.particles.draw()

        glDisable(GL_VERTEX_PROGRAM_POINT_SIZE)
        glEnable(GL_DEPTH_TEST)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
        glDisable(GL_POINT_SPRITE)

        glLibUseShader(None)

        ##        glDisable(GL_BLEND)
        ##        self.view_2D.set_view()
        ##        glLibSelectTexture(self.pos_time_texture)
        ##        glLibDrawScreenQuad(texture=True)
        ##        glEnable(GL_BLEND)

        if old_lighting == GL_TRUE:
            glEnable(GL_LIGHTING)
Example #16
0
def glLibInternal_DepthPeel       (fbo1,fbo2,pos,view,objpos,num,shader,draw,textures,filtering=False,precision=8):
    glLibUseShader(shader)
    shader.pass_vec2("size",view.rect[2:])
    shader.pass_float("near",view.near)
    shader.pass_float("far",view.far)
    shader.pass_bool("stage1",True)

    glPushMatrix()
    glLoadIdentity()
    view.set_view()
    projmat = glGetFloatv(GL_PROJECTION_MATRIX)
    gluLookAt(pos[0],pos[1],pos[2],objpos[0],objpos[1],objpos[2],0,1,0)
    viewmat = glGetFloatv(GL_MODELVIEW_MATRIX)
    out_textures = []
    ping_pong = 1
    for render_pass in xrange(num):
        if fbo1 != None:
            if ping_pong == 1: fbo1.enable([1])
            else:              fbo2.enable([1])
        glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
        glLoadIdentity()
        view.set_view()
        gluLookAt(pos[0],pos[1],pos[2],objpos[0],objpos[1],objpos[2],0,1,0)
        draw()
##        glLibScreenshot("depth"+str(render_pass)+".png",rect=GLLIB_AUTO,type=GLLIB_DEPTH,framebuffer=1,overwrite=True)
        if fbo1 != None:
            if ping_pong == 1: fbo1.disable(); out_textures.append(fbo1.get_texture(1))
            else:              fbo2.disable(); out_textures.append(fbo2.get_texture(1))
        else:
            out_textures.append(glLibSceneToTexture(view.rect,textures[render_pass],GLLIB_DEPTH,filtering,False,precision))
        shader.pass_bool("stage1",False)
        shader.pass_texture(out_textures[-1],1)
        ping_pong = 3 - ping_pong
    glPopMatrix()
    glLibUseShader(None)
    return out_textures,projmat,viewmat
Example #17
0
def glLibAccumSeparableFilter(scenebuffer,view2d,filter,filtersize):
    glLibUseShader(None)
    glDisable(GL_LIGHTING)
    glLoadIdentity()

    view2d.set_view()
    size = list(view2d.rect[2:])
    if filter == GLLIB_GAUSS:
        minx = (-filtersize[0]//2)+1
        maxx = (filtersize[0]//2)+1
        zmax = 2.9653100000109589
        filter = [(1.0/(2.0*pi))*(e**(-((float(2.0*x*zmax)/filtersize[0])**2)/2.0)) for x in range(minx,maxx,1)]
        filter = [filter,filter]
##    elif filter == GLLIB_BLOOM:
##        original_rect = list(view2d.rect)
##        texture_sizes = []
##        for texture_pass in range(filtersize[2]):
##            glLibAccumSeparableFilter(scenebuffer,view2d,GLLIB_GAUSS,filtersize[:2])
##            string_rect = str(view2d.rect)
##            if string_rect not in gllib_textures.keys():
##                gllib_textures[string_rect] = glLibSceneToTexture(view2d.rect,None,scenebuffer.format,scenebuffer.filtering,scenebuffer.mipmapping)
##            else:
##                gllib_textures[string_rect] = glLibSceneToTexture(view2d.rect,gllib_textures[string_rect])
##            texture_sizes.append(string_rect)
##            view2d.rect[2] = rndint(filtersize[3]*view2d.rect[2])
##            view2d.rect[3] = rndint(filtersize[3]*view2d.rect[3])
##        view2d.rect = list(original_rect)
##        view2d.set_view()
##        glClear(GL_ACCUM_BUFFER_BIT)
##        glDisable(GL_LIGHTING)
##        for texture_size in texture_sizes:
##            glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
##            glLibSelectTexture(gllib_textures[texture_size])
##            glBegin(GL_QUADS)
##            glTexCoord2f(0,0);glVertex2f(0,      0      )
##            glTexCoord2f(1,0);glVertex2f(size[0],0      )
##            glTexCoord2f(1,1);glVertex2f(size[0],size[1])
##            glTexCoord2f(0,1);glVertex2f(0,      size[1])
##            glEnd()
##            glAccum(GL_ACCUM,1.0/filtersize[2])
##        glAccum(GL_RETURN,1.0)
##        glEnable(GL_LIGHTING)
##        return
    totals = list(map(float,[sum(filter[0]),sum(filter[1])]))

    glClear(GL_ACCUM_BUFFER_BIT)
    glLibSelectTexture(scenebuffer)

    index = 0
    for xjitter in range((-filtersize[0]//2)+1,(filtersize[0]//2)+1,1):
        glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
        glBegin(GL_QUADS)
        glTexCoord2f(0,0);glVertex2f(xjitter,        0      )
        glTexCoord2f(1,0);glVertex2f(xjitter+size[0],0      )
        glTexCoord2f(1,1);glVertex2f(xjitter+size[0],size[1])
        glTexCoord2f(0,1);glVertex2f(xjitter,        size[1])
        glEnd()
        glAccum(GL_ACCUM,filter[0][index]/totals[0])
        index += 1
    glAccum(GL_RETURN,1.0)
    scenebuffer = glLibSceneToTexture(view2d.rect,scenebuffer)
    glLibSelectTexture(scenebuffer)
    glClear(GL_ACCUM_BUFFER_BIT)
    index = 0
    for yjitter in range((-filtersize[1]//2)+1,(filtersize[1]//2)+1,1):
        glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
        glBegin(GL_QUADS)
        glTexCoord2f(0,0);glVertex2f(0,      yjitter        )
        glTexCoord2f(1,0);glVertex2f(size[0],yjitter        )
        glTexCoord2f(1,1);glVertex2f(size[0],yjitter+size[1])
        glTexCoord2f(0,1);glVertex2f(0,      yjitter+size[1])
        glEnd()
        glAccum(GL_ACCUM,filter[1][index]/totals[1])
        index += 1
    glAccum(GL_RETURN,1.0)
    glEnable(GL_LIGHTING)
Example #18
0
def glLibAccumSeparableFilter(scenebuffer,view2d,filter,filtersize):
    glLibUseShader(None)
    glDisable(GL_LIGHTING)
    glLoadIdentity()

    view2d.set_view()
    size = list(view2d.rect[2:])
    if filter == GLLIB_GAUSS:
        minx = (-filtersize[0]/2)+1
        maxx = (filtersize[0]/2)+1
        zmax = 2.9653100000109589
        filter = [(1.0/(2.0*pi))*(e**(-((float(2.0*x*zmax)/filtersize[0])**2)/2.0)) for x in xrange(minx,maxx,1)]
        filter = [filter,filter]
##    elif filter == GLLIB_BLOOM:
##        original_rect = list(view2d.rect)
##        texture_sizes = []
##        for texture_pass in xrange(filtersize[2]):
##            glLibAccumSeparableFilter(scenebuffer,view2d,GLLIB_GAUSS,filtersize[:2])
##            string_rect = str(view2d.rect)
##            if string_rect not in gllib_textures.keys():
##                gllib_textures[string_rect] = glLibSceneToTexture(view2d.rect,None,scenebuffer.format,scenebuffer.filtering,scenebuffer.mipmapping)
##            else:
##                gllib_textures[string_rect] = glLibSceneToTexture(view2d.rect,gllib_textures[string_rect])
##            texture_sizes.append(string_rect)
##            view2d.rect[2] = rndint(filtersize[3]*view2d.rect[2])
##            view2d.rect[3] = rndint(filtersize[3]*view2d.rect[3])
##        view2d.rect = list(original_rect)
##        view2d.set_view()
##        glClear(GL_ACCUM_BUFFER_BIT)
##        glDisable(GL_LIGHTING)
##        for texture_size in texture_sizes:
##            glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
##            glLibSelectTexture(gllib_textures[texture_size])
##            glBegin(GL_QUADS)
##            glTexCoord2f(0,0);glVertex2f(0,      0      )
##            glTexCoord2f(1,0);glVertex2f(size[0],0      )
##            glTexCoord2f(1,1);glVertex2f(size[0],size[1])
##            glTexCoord2f(0,1);glVertex2f(0,      size[1])
##            glEnd()
##            glAccum(GL_ACCUM,1.0/filtersize[2])
##        glAccum(GL_RETURN,1.0)
##        glEnable(GL_LIGHTING)
##        return
    totals = map(float,[sum(filter[0]),sum(filter[1])])
    
    glClear(GL_ACCUM_BUFFER_BIT)
    glLibSelectTexture(scenebuffer)
    
    index = 0
    for xjitter in xrange((-filtersize[0]/2)+1,(filtersize[0]/2)+1,1):
        glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
        glBegin(GL_QUADS)
        glTexCoord2f(0,0);glVertex2f(xjitter,        0      )
        glTexCoord2f(1,0);glVertex2f(xjitter+size[0],0      )
        glTexCoord2f(1,1);glVertex2f(xjitter+size[0],size[1])
        glTexCoord2f(0,1);glVertex2f(xjitter,        size[1])
        glEnd()
        glAccum(GL_ACCUM,filter[0][index]/totals[0])
        index += 1
    glAccum(GL_RETURN,1.0)
    scenebuffer = glLibSceneToTexture(view2d.rect,scenebuffer)
    glLibSelectTexture(scenebuffer)
    glClear(GL_ACCUM_BUFFER_BIT)
    index = 0
    for yjitter in xrange((-filtersize[1]/2)+1,(filtersize[1]/2)+1,1):
        glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
        glBegin(GL_QUADS)
        glTexCoord2f(0,0);glVertex2f(0,      yjitter        )
        glTexCoord2f(1,0);glVertex2f(size[0],yjitter        )
        glTexCoord2f(1,1);glVertex2f(size[0],yjitter+size[1])
        glTexCoord2f(0,1);glVertex2f(0,      yjitter+size[1])
        glEnd()
        glAccum(GL_ACCUM,filter[1][index]/totals[1])
        index += 1
    glAccum(GL_RETURN,1.0)
    glEnable(GL_LIGHTING)