示例#1
0
    def __init__(self, antialiasing):
        Shader.__init__(self)

        self.antialiasing = antialiasing

        if self.program is None:
            flags = []
            if self.antialiasing > 0:
                flags += ["#define AA_SAMPLES %u" % antialiasing]

            code = map(lambda path: open(self.dir + path, "rb").read(), ["merge.vert", "merge.frag"])
            code = map(lambda text: text.split("\n"), code)
            code = map(lambda text: [text[0]] + flags + text[1:], code)
            vert, frag = map("\n".join, code)
            self.create(vert, frag)

        self.projectionLoc = glGetUniformLocation(self.program, "projectionMatrix")
        self.modelViewLoc = glGetUniformLocation(self.program, "modelViewMatrix")

        camera = numpy.matrix([[0.], [0.], [1.], [0.]])
        axis = numpy.matrix([[0.], [1.], [0.], [0.]])
        pov = numpy.matrix([[0.], [0.], [0.], [1.]])

        self.projectionMatrix = model.createOrthographicMatrix((1.0, 1.0), (0.001, 1000.0))
        self.modelViewMatrix = model.createModelViewMatrix(camera, pov, axis)

        mode = GL_TEXTURE_2D_MULTISAMPLE if self.antialiasing > 0 else GL_TEXTURE_2D
        self.colorTexture = Texture(mode, glGetUniformLocation(self.program, "colorTexture"))
示例#2
0
    def __init__(self, masked):
        Shader.__init__(self)

        self.masked = masked

        if self.program is None:
            flags = []
            if self.masked:
                flags += ["#define MASKED"]

            code = map(lambda path: open(self.dir + path, "rb").read(), ["blur.vert", "blur.frag"])
            code = map(lambda text: text.split("\n"), code)
            code = map(lambda text: [text[0]] + flags + text[1:], code)
            vert, frag = map("\n".join, code)
            self.create(vert, frag)

        self.projectionLoc = glGetUniformLocation(self.program, "projectionMatrix")
        self.modelViewLoc = glGetUniformLocation(self.program, "modelViewMatrix")

        camera = numpy.matrix([[0.], [0.], [1.], [0.]])
        axis = numpy.matrix([[0.], [1.], [0.], [0.]])
        pov = numpy.matrix([[0.], [0.], [0.], [1.]])

        self.projectionMatrix = model.createOrthographicMatrix((1.0, 1.0), (0.001, 1000.0))
        self.modelViewMatrix = model.createModelViewMatrix(camera, pov, axis)

        self.colorTexture = Texture(mode=GL_TEXTURE_2D, location=glGetUniformLocation(self.program, "colorTexture"))
        self.directionLoc = glGetUniformLocation(self.program, "direction")

        if self.masked:
            self.maskTexture = Texture(mode=GL_TEXTURE_2D, location=glGetUniformLocation(self.program, "maskTexture"),
                    filtering=(GL_NEAREST, GL_NEAREST))
            self.sourceTexture = Texture(mode=GL_TEXTURE_2D, location=glGetUniformLocation(self.program,
                    "sourceTexture"))
示例#3
0
    def updateMatrix(self, viewport):
        aspect = float(viewport[0]) / float(viewport[1])
        if self.ortho:
            distance = numpy.linalg.norm(self.camera.camera - self.camera.pov)
            width = 1.0 / math.tan(self.camera.fov / 2.0) * distance
            area = (width, width / aspect)
            self.projectionMatrix = model.createOrthographicMatrix(area, self.depth)
        else:
            self.projectionMatrix = model.createPerspectiveMatrix(aspect, self.camera.fov, self.depth)

        self.modelViewMatrix = model.createModelViewMatrix(self.camera.camera[0:3], self.camera.pov[0:3],
                self.camera.axis[0:3])
示例#4
0
    def __init__(self):
        Shader.__init__(self)

        if self.program is None:
            vert, frag = map(lambda path: open(self.dir + path, "rb").read(),
                    ["background.vert", "background.frag"])
            self.create(vert, frag)

        self.projectionLoc = glGetUniformLocation(self.program, "projectionMatrix")
        self.modelViewLoc = glGetUniformLocation(self.program, "modelViewMatrix")

        camera = numpy.matrix([[0.], [0.], [1.], [0.]])
        axis = numpy.matrix([[0.], [1.], [0.], [0.]])
        pov = numpy.matrix([[0.], [0.], [0.], [1.]])

        self.projectionMatrix = model.createOrthographicMatrix((1.0, 1.0), (0.001, 1000.0))
        self.modelViewMatrix = model.createModelViewMatrix(camera, pov, axis)
示例#5
0
    def __init__(self, prefix='', flags=[]):
        super().__init__()

        if self.program is None and prefix != '':
            def loadShaderFile(path, flags):
                source = open(os.path.join(self.dir, path), 'rb').read().decode('utf-8').split('\n')
                source = [source[0]] + flags + source[1:]
                return '\n'.join(source)

            self.create(loadShaderFile(prefix + '.vert', flags), loadShaderFile(prefix + '.frag', flags))

        self.projectionLoc = glGetUniformLocation(self.program, 'projectionMatrix')
        self.modelViewLoc = glGetUniformLocation(self.program, 'modelViewMatrix')

        self.projectionMatrix = model.createOrthographicMatrix(
                area=(1.0, 1.0),
                distance=(0.001, 1000.0))
        self.modelViewMatrix = model.createModelViewMatrix(
                eye=numpy.array([0.0, 0.0, 1.0]),
                center=numpy.zeros(3),
                up=numpy.array([0.0, 1.0, 0.0]))