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
Exemple #2
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 __init__(self, n, precision=8):
        #self.n differs from n by a maximum of sqrt(n)+1
        self.size = [int(round(n**0.5))] * 2
        self.n = self.size[0] * self.size[1]

        #Shader to update particles
        self.update_shader = glLibShader()
        self.update_shader.use_prebuilt(GLLIB_PARTICLE_UPDATE)
        ##        print self.update_shader.errors

        #Shader to draw particles
        self.draw_shader = glLibShader()
        self.draw_shader.use_prebuilt(GLLIB_PARTICLE_DRAW)
        ##        print self.draw_shader.errors

        #Particles as VBO
        self.particles = glLibGrid2D(self.size[0])

        #Parameters
        self.origin = [0.0, 0.0, 0.0]
        self.initialspeed = [0.0, 0.0, 0.0]
        self.forces = [0.0, 0.0, 0.0]
        self.scale = [1, 1, 1]
        self.density = 1.0
        self.step = 1.0 / (self.n - 1)
        self.density_constant = (1.0 / 64.0) * (4.0**log(self.size[0],
                                                         2.0)) * self.step
        self.trans = [0.0, 0.0, 0.0]
        self.fade = 1.0
        self.jitter = [0.0, 0.0, 0.0]
        self.psize = 100.0
        #   Edge handling
        self.negx = 1.0
        self.negy = 1.0
        self.negz = 1.0
        self.posx = 1.0
        self.posy = 1.0
        self.posz = 1.0

        #Data Textures
        self.pos_time_texture = None
        self.velocity_texture = None

        self.view_2D = glLibView2D((0, 0, self.size[0], self.size[1]))

        self.point_texture = glLibTexture2D("glLib/fireparticle.png",
                                            (0, 0, 8, 8), GLLIB_RGBA)
        self.point_texture.edge(GLLIB_CLAMP)

        self.precision = precision

        self.framebuffer1 = glLibFBO(self.size)
        self.framebuffer1.add_render_target(1,
                                            type=GLLIB_RGBA,
                                            precision=self.precision)
        self.framebuffer1.add_render_target(2,
                                            type=GLLIB_RGBA,
                                            precision=self.precision)

        self.framebuffer2 = glLibFBO(self.size)
        self.framebuffer2.add_render_target(1,
                                            type=GLLIB_RGBA,
                                            precision=self.precision)
        self.framebuffer2.add_render_target(2,
                                            type=GLLIB_RGBA,
                                            precision=self.precision)

        self.pingpong = 1

        xvalues = np.zeros(self.n) + 0.5
        yvalues = np.zeros(self.n) + 0.5
        zvalues = np.zeros(self.n) + 0.5
        tvalues = np.arange(0.0, 1.0 + (1.0 / self.n),
                            1.0 / (self.n - 1.0)).astype(float)
        zeros = np.zeros(self.n)
        texarray = np.concatenate([xvalues, yvalues, zvalues,
                                   tvalues]).reshape(4, -1).T
        texarray = texarray.reshape((self.size[0], self.size[1], 4))
        self.pos_time_texture = glLibTexture2D(
            texarray, (0, 0, self.size[0], self.size[1]), GLLIB_RGBA)

        vecs = np.random.standard_normal(size=(self.size[0], self.size[1], 3))
        magnitudes = np.sqrt((vecs * vecs).sum(axis=-1))
        uvecs = vecs / magnitudes[..., np.newaxis]
        randlen = np.random.random((self.size[0], self.size[1]))
        randvecs = uvecs * randlen[..., np.newaxis]
        rgb = (((randvecs + 1.0) / 2.0) * 255.0).astype(int)
        surface = pygame.surfarray.make_surface(rgb)
        self.rand_tex = glLibTexture2D(surface,
                                       (0, 0, self.size[0], self.size[1]),
                                       GLLIB_RGB)

        self.get_new = False
        self.update()
        self.get_new = True
    def __init__(self,n,precision=8):
        #self.n differs from n by a maximum of sqrt(n)+1
        self.size = [int(round(n**0.5))]*2
        self.n = self.size[0] * self.size[1]

        #Shader to update particles
        self.update_shader = glLibShader()
        self.update_shader.use_prebuilt(GLLIB_PARTICLE_UPDATE)
##        print self.update_shader.errors

        #Shader to draw particles
        self.draw_shader = glLibShader()
        self.draw_shader.use_prebuilt(GLLIB_PARTICLE_DRAW)
##        print self.draw_shader.errors

        #Particles as VBO
        self.particles = glLibGrid2D(self.size[0])

        #Parameters
        self.origin  = [0.0,0.0,0.0]
        self.initialspeed = [0.0,0.0,0.0]
        self.forces = [0.0,0.0,0.0]
        self.scale   = [1,1,1]
        self.density = 1.0
        self.step = 1.0/(self.n-1)
        self.density_constant = (1.0/64.0)*(4.0**log(self.size[0],2.0)) * self.step
        self.trans = [0.0,0.0,0.0]
        self.fade = 1.0
        self.jitter = [0.0,0.0,0.0]
        self.psize = 100.0
        #   Edge handling
        self.negx = 1.0
        self.negy = 1.0
        self.negz = 1.0
        self.posx = 1.0
        self.posy = 1.0
        self.posz = 1.0

        #Data Textures
        self.pos_time_texture = None
        self.velocity_texture = None

        self.view_2D = glLibView2D((0,0,self.size[0],self.size[1]))
        
        self.point_texture = glLibTexture2D(os.path.join("glLib","fireparticle.png"),(0,0,8,8),GLLIB_RGBA)
        self.point_texture.edge(GLLIB_CLAMP)

        self.precision = precision

        self.framebuffer1 = glLibFBO(self.size)
        self.framebuffer1.add_render_target(1,type=GLLIB_RGBA,precision=self.precision)
        self.framebuffer1.add_render_target(2,type=GLLIB_RGBA,precision=self.precision)

        self.framebuffer2 = glLibFBO(self.size)
        self.framebuffer2.add_render_target(1,type=GLLIB_RGBA,precision=self.precision)
        self.framebuffer2.add_render_target(2,type=GLLIB_RGBA,precision=self.precision)

        self.pingpong = 1

        xvalues = np.zeros(self.n)+0.5
        yvalues = np.zeros(self.n)+0.5
        zvalues = np.zeros(self.n)+0.5
        tvalues = np.arange(0.0, 1.0+(1.0/self.n), 1.0/(self.n-1.0)).astype(float)
        zeros = np.zeros(self.n)
        texarray = np.concatenate([xvalues,yvalues,zvalues,tvalues]).reshape(4,-1).T
        texarray = texarray.reshape((self.size[0],self.size[1],4))
        self.pos_time_texture = glLibTexture2D(texarray,(0,0,self.size[0],self.size[1]),GLLIB_RGBA)

        vecs = np.random.standard_normal(size=(self.size[0],self.size[1],3))
        magnitudes = np.sqrt((vecs*vecs).sum(axis=-1))
        uvecs = vecs / magnitudes[...,np.newaxis]
        randlen = np.random.random((self.size[0],self.size[1]))
        randvecs = uvecs*randlen[...,np.newaxis]
        rgb = ((randvecs+1.0)/2.0)*255.0
        surface = pygame.surfarray.make_surface(rgb)
        self.rand_tex = glLibTexture2D(surface,(0,0,self.size[0],self.size[1]),GLLIB_RGB)
        
        self.get_new = False
        self.update()
        self.get_new = True