Ejemplo n.º 1
0
def createEffect(values):
    p = ParticleEffect()
    loadValues(values, p)
    color_gradient=loader.loadTexture(values["color_gradient"])
    size_gradient=loader.loadTexture(values["size_gradient"])
    shape_gradient=loader.loadTexture(values["shape_gradient"])    
    blend_gradient=loader.loadTexture("data/blend.png", minfilter=Texture.FTNearest, magfilter=Texture.FTNearest)
    color_gradient.setWrapU(Texture.WMClamp)
    color_gradient.setWrapV(Texture.WMClamp)
    size_gradient.setWrapU(Texture.WMClamp)
    size_gradient.setWrapV(Texture.WMClamp)
    shape_gradient.setWrapU(Texture.WMClamp)
    shape_gradient.setWrapV(Texture.WMClamp)
    blend_gradient.setWrapU(Texture.WMClamp)
    blend_gradient.setWrapV(Texture.WMClamp)
    for geom in p.findAllMatches('**/+GeomNode'):       
        geom.setDepthWrite(False)
        geom.setBin("transparent", 31)
        #need to hide it from the water and shadow camera now... I don't know hot to get the geom later :(
        geom.hide(BitMask32.bit(1))
        geom.hide(BitMask32.bit(2))
        geom.setShader(Shader.load(Shader.SLGLSL, "shaders/vfx_v.glsl","shaders/vfx_f.glsl"), 1)
        geom.setShaderInput('distortion',0.9)
        #geom.setShaderInput("fog",  Vec4(0.4, 0.4, 0.4, 0.002))
        geom.setShaderInput("color_gradient", color_gradient)
        geom.setShaderInput("size_gradient",  size_gradient)
        geom.setShaderInput("shape_gradient", shape_gradient)
        geom.setShaderInput("blend_gradient", blend_gradient)
    #p.start(parent=self.root, renderParent = render) 
    return p  
Ejemplo n.º 2
0
def createEffectFromGradients(
        values, color_gradient, size_gradient, shape_gradient):
    p = ParticleEffect()
    loadValues(values, p)
    blend_gradient = loader.loadTexture(
        miscAssetPath + "/blend.png",
        minfilter=Texture.FTNearest, magfilter=Texture.FTNearest)
    color_gradient.setWrapU(Texture.WMClamp)
    color_gradient.setWrapV(Texture.WMClamp)
    size_gradient.setWrapU(Texture.WMClamp)
    size_gradient.setWrapV(Texture.WMClamp)
    shape_gradient.setWrapU(Texture.WMClamp)
    shape_gradient.setWrapV(Texture.WMClamp)
    blend_gradient.setWrapU(Texture.WMClamp)
    blend_gradient.setWrapV(Texture.WMClamp)
    for geom in p.findAllMatches('**/+GeomNode'):
        geom.setDepthWrite(False)
        geom.setBin("transparent", 31)
        geom.setShader(
            Shader.load(Shader.SLGLSL,
                shaderPath + "/vfx_v.glsl",
                shaderPath + "/vfx_f.glsl"), 1)
        geom.setShaderInput('distortion', 0.51)
        geom.setShaderInput("fog", Vec4(0.4, 0.4, 0.4, 0.002))
        geom.setShaderInput("color_gradient", color_gradient)
        geom.setShaderInput("size_gradient", size_gradient)
        geom.setShaderInput("shape_gradient", shape_gradient)
        geom.setShaderInput("blend_gradient", blend_gradient)
    return p
Ejemplo n.º 3
0
def createEffect(values):
    p = ParticleEffect()
    loadValues(values, p)
    color_gradient = loader.loadTexture(values["color_gradient"])
    size_gradient = loader.loadTexture(values["size_gradient"])
    shape_gradient = loader.loadTexture(values["shape_gradient"])
    blend_gradient = loader.loadTexture("data/blend.png",
                                        minfilter=Texture.FTNearest,
                                        magfilter=Texture.FTNearest)
    color_gradient.setWrapU(Texture.WMClamp)
    color_gradient.setWrapV(Texture.WMClamp)
    color_gradient.setFormat(Texture.F_srgb_alpha)
    size_gradient.setWrapU(Texture.WMClamp)
    size_gradient.setWrapV(Texture.WMClamp)
    shape_gradient.setWrapU(Texture.WMClamp)
    shape_gradient.setWrapV(Texture.WMClamp)
    blend_gradient.setWrapU(Texture.WMClamp)
    blend_gradient.setWrapV(Texture.WMClamp)
    for geom in p.findAllMatches('**/+GeomNode'):
        geom.setDepthWrite(False)
        #geom.setBin("transparent", 31)
        #need to hide it from the water and shadow camera now... I don't know hot to get the geom later :(
        geom.hide(BitMask32.bit(1))
        geom.hide(BitMask32.bit(2))
        geom.setShader(
            Shader.load(Shader.SLGLSL, "shaders/vfx_v.glsl",
                        "shaders/vfx_f.glsl"), 1)
        geom.setShaderInput('distortion', values['distortion'])
        #geom.setShaderInput("fog",  Vec4(0.4, 0.4, 0.4, 0.002))
        geom.setShaderInput("color_gradient", color_gradient)
        geom.setShaderInput("size_gradient", size_gradient)
        geom.setShaderInput("shape_gradient", shape_gradient)
        geom.setShaderInput("blend_gradient", blend_gradient)
    #p.start(parent=self.root, renderParent = render)
    return p
Ejemplo n.º 4
0
def createEffect(values):
    p = ParticleEffect()
    loadValues(values, p)
    color_gradient = loader.loadTexture(values["color_gradient"])
    size_gradient = loader.loadTexture(values["size_gradient"])
    shape_gradient = loader.loadTexture(values["shape_gradient"])
    blend_gradient = loader.loadTexture("data/vfx/blend.png",
                                        minfilter=Texture.FTNearest,
                                        magfilter=Texture.FTNearest)
    color_gradient.setWrapU(Texture.WMClamp)
    color_gradient.setWrapV(Texture.WMClamp)
    #color_gradient.setFormat(Texture.F_srgb_alpha)
    size_gradient.setWrapU(Texture.WMClamp)
    size_gradient.setWrapV(Texture.WMClamp)
    shape_gradient.setWrapU(Texture.WMClamp)
    shape_gradient.setWrapV(Texture.WMClamp)
    blend_gradient.setWrapU(Texture.WMClamp)
    blend_gradient.setWrapV(Texture.WMClamp)
    for geom in p.findAllMatches('**/+GeomNode'):
        geom.setDepthWrite(False)
        geom.hide(BitMask32.bit(1))
        geom.hide(BitMask32.bit(2))
        geom.setShader(
            Shader.load(Shader.SLGLSL, "data/shaders/vfx_v.glsl",
                        "data/shaders/vfx_f.glsl"), 1)
        geom.setShaderInput('distortion', values['distortion'])
        geom.setShaderInput("fog", Vec4(0.4, 0.4, 0.4, 0.002))
        geom.setShaderInput("color_gradient", color_gradient)
        geom.setShaderInput("size_gradient", size_gradient)
        geom.setShaderInput("shape_gradient", shape_gradient)
        geom.setShaderInput("blend_gradient", blend_gradient)
    p.start(parent=render, renderParent=render)
    return p
Ejemplo n.º 5
0
class ParticleVfx():
    """
    Wrapper class for ParticleEffect
    """
    def __init__(self, name='particles-1'):
        self.node = ParticleEffect()
        self.p0 = Particles.Particles(name)
        self.p0.setFactory('PointParticleFactory')
        self.p0.setRenderer('PointParticleRenderer')
        self.p0.setLocalVelocityFlag(1)
        self.p0.setSystemGrowsOlderFlag(0)
        self.f0 = ForceGroup.ForceGroup('default')
        self.birth_set = False
        self.emitter_set = False
        self.force = {}

    def setHpr(self, node=render, hpr=Vec3(0, 0, 0), r=None):
        if not r is None:
            hpr = Vec3(node, hpr, r)
            node = render
        elif type(node).__name__ != 'NodePath':
            hpr = node
            node = render
        self.node.setHpr(node, hpr)

    def setPos(self, node=render, pos=Point3(0, 0, 0), z=None):
        if not z is None:
            pos = Vec3(node, pos, z)
            node = render
        elif type(node).__name__ != 'NodePath':
            pos = node
            node = render
        self.node.setPos(node, pos)

    def hide(self):
        #self.node.disable() #  ParticleEffect.disable() would detach the node and the info on pos/hpr will be lost
        for f in self.node.forceGroupDict.values():
            f.disable()
        for p in self.node.particlesDict.values():
            p.setRenderParent(p.node)
            p.disable()

    def show(self):
        self.node.enable()

    def setBirth(self,
                 pool=300,
                 rate=0.1,
                 number=10,
                 spread=5,
                 life=1.0,
                 life_spread=0.1,
                 mass=10.0,
                 mass_spread=5.0):
        if mass_spread >= mass:
            mass_spread = mass * 0.95
        self.p0.setPoolSize(pool)
        self.p0.setBirthRate(rate)
        self.p0.setLitterSize(number)
        self.p0.setLitterSpread(spread)
        self.p0.factory.setLifespanBase(life)
        self.p0.factory.setLifespanSpread(life_spread)
        self.p0.factory.setMassBase(mass)
        self.p0.factory.setMassSpread(mass_spread)
        self.birth_set = True

    def setEmiter(self,
                  emmiter_type='PointEmitter',
                  force=Vec3(0, 0, 0),
                  emmision_type=EXPLICIT,
                  **kwargs):
        self.p0.setEmitter(emmiter_type)
        self.p0.emitter.setEmissionType(emmision_type)
        self.p0.emitter.setOffsetForce(force)
        self.p0.emitter.setExplicitLaunchVector(Vec3(0, 0, 0))
        self.p0.emitter.setRadiateOrigin(Point3(0, 0, 0))
        self.emitter_set = True

        if emmiter_type == 'BoxEmitter':
            self.p0.emitter.setMaxBound(kwargs['max_bound'])
            self.p0.emitter.setMinBound(kwargs['min_bound'])
        elif emmiter_type == 'DiscEmitter':
            self.p0.emitter.setRadius(kwargs['radius'])
            self.p0.emitter.setInnerAngle(kwargs['inner_angle'])
            self.p0.emitter.setInnerMagnitude(kwargs['inner_mag'])
            self.p0.emitter.setOuterAngle(kwargs['outer_angle'])
            self.p0.emitter.setOuterMagnitude(kwargs['outer_mag'])
        elif emmiter_type == 'LineEmitter':
            self.p0.emitter.setEndpoint1(kwargs['endpoint1'])
            self.p0.emitter.setEndpoint2(kwargs['endpoint2'])
        #elif emmiter_type == 'PointEmitter':
        #    pass #no options here
        elif emmiter_type == 'RectangleEmitter':
            self.p0.emitter.setMaxBound(kwargs['max_bound'])
            self.p0.emitter.setMinBound(kwargs['min_bound'])
        elif emmiter_type == 'RingEmitter':
            self.p0.emitter.setAngle(kwargs['angle'])
            self.p0.emitter.setRadius(kwargs['radius'])
            self.p0.emitter.setRadiusSpread(kwargs['spread'])
        elif emmiter_type == 'SphereSurfaceEmitter':
            self.p0.emitter.setRadius(kwargs['radius'])
        elif emmiter_type == 'SphereVolumeEmitter':
            self.p0.emitter.setRadius(kwargs['radius'])
        elif emmiter_type == 'TangentRingEmitter':
            self.p0.emitter.setRadius(kwargs['radius'])
            self.p0.emitter.setRadiusSpread(kwargs['spread'])

        self.node.addParticles(self.p0)

    def setColor(self, color):
        self.p0.renderer.setStartColor(color)
        self.p0.renderer.setEndColor(color)

    def setAdditiveBlend(self):
        color_attrib = ColorBlendAttrib.make(ColorBlendAttrib.MAdd,
                                             ColorBlendAttrib.OIncomingAlpha,
                                             ColorBlendAttrib.OOne)
        for geom in self.node.findAllMatches('**/+GeomNode'):
            geom.setAttrib(color_attrib)
            geom.setDepthWrite(False)
            geom.setDepthTest(False)

    def setShader(self, v_shader, f_shader, inputs={}):
        shader_attrib = ShaderAttrib.make(
            Shader.load(Shader.SLGLSL, v_shader, f_shader))
        shader_attrib = shader_attrib.setFlag(ShaderAttrib.F_shader_point_size,
                                              True)

        for geom in self.node.findAllMatches('**/+GeomNode'):
            geom.setAttrib(shader_attrib)
            for name, value in inputs.items():
                geom.setShaderInput(name, value)

    def addForce(self, force, name):
        force.setVectorMasks(1, 1, 1)
        force.setActive(1)
        self.f0.addForce(force)
        self.force[name] = force

    def setForce(self, name, active=1):
        if name in self.force:
            self.force[name].setVectorMasks(active, active, active)
            #self.force[name].setActive(active) #somehow this fails (?)

    def start(self, parent=render, renderParent=render):
        if not self.emitter_set:
            self.setEmiter()
        if not self.birth_set:
            self.setBirth()
        self.node.addForceGroup(self.f0)
        self.node.start(parent=parent, renderParent=renderParent)