Table of Contents

Lab 7 - Various Special Effects

Before You Start

Effect Room

In this exercise you'll start with an empty room and then add some “sparkly” special effects to make it more engaging.

  1. Creating and adding an animated texture
    Find the function create_lightbeam and add the following code to it:
            beammaterial = Material()
            beammaterial.setDiffuse(VBase4(1,1,1,1))     
            beammaterial.setEmission(VBase4(1,1,1,1))   
            beammodel = loader.loadModel("Models/Textures/wall_door_beams.egg")
            beam = self.parent.attachNewNode("beam")
            beam.setMaterial(beammaterial)
            beammodel.instanceTo(beam)
            beam.setPos(1.55,-0.75,0.5)         
            beam2 = self.parent.attachNewNode("beam2")
            beam2.setMaterial(beammaterial)
            beammodel.instanceTo(beam2)
            beam2.setPos(1.55,-0.65,0.5)
            beam2.setH(-10)

    But note that wall_door_beams.egg doe snot exist yet! You have to create this animation from a couple of still frames in your texture folder. Go into the texture folder and run the following command egg-texture-cards -fps 2 -o wall_door_beams.egg wall_tanned_door_beams3.tif wall_tanned_door_beams4.tif. This will create a card that switches between the two given textures at the rate of 2 frames per second. If this is successful, then you should see the animated beams in the room. Experiment with the frame rate.

  2. Creating projected light
    Now you want to create the lit up window pattern on the floor, as if it's light coming through the broken window panes. You can do this by setting up a texture projector that essentially projects a texture with a perspective projection from somewhere outside the window and onto the floor panel. Add the following code to the create_projectedlight function:
            projector = self.parent.attachNewNode(LensNode('projector'))
            lens = PerspectiveLens()
            projector.node().setLens(lens)
            projector.setPos(2.55,-0.5,1.55)
            projector.lookAt(1.5,-0.5,0)
            lightimage = loader.loadTexture("Models/Textures/wall_tanned_door_light.tif")
            lightimage.setWrapU(Texture.WMClamp)
            lightimage.setWrapV(Texture.WMClamp)
            lightts = TextureStage('lightts')
            self.floors[1].projectTexture(lightts,lightimage,projector)
    1. The projector is correctly set up here, but there are a few things you still need to do to make this work. First of all, you have to create the texture that you want to project on the floor. Here we call it wall_tanned_door_light.tif. What should this texture look like? Study the screen shot above and try to understand what kind of texture you need. Then start with a copy of wall_tanned_door.tif and change it into the right texture for the light pattern. Try it out.
    2. You may notice that the texture doesn't blend with the floor texture. You need to set the blending parameter for the texture stage for that to happen, using the method setMode(<blend mode>) method on the texture stage. Try figuring out what blend mode you need to use for this to come out right.
  3. Crating particles
    Add the following code to the create_particles funtion to get a particle generator installed:
            base.enableParticles()
            self.p = ParticleEffect()
            self.p.loadConfig(Filename("ar.ptf"))
            self.p.start(self.parent)
            self.p.setPos(1.6,-0.7,0.0)        
            self.p.setHpr(0,-45,0) 

    This already comes with a small particle system called “ar.ptf”, make sure you see those particles in your scene. Then see if you can create a new particle system using the Panda 3D Particle Panel (it's under Samples/Particles) and insert that system instead. Can you make something that looks and behaves like flies?

  4. Creating a bloom effect
    The following code may not work on all graphics cards, since they have to support programmable shaders. You should get warning messages on the console about this as well as not seeing the actual effect. Try adding the following code to the create_bloom function:
            render.setShaderAuto()
            self.filters = CommonFilters(base.win, base.cam)   
            self.filters.setBloom(size="large")

    You can play with the “size” value, which can also be “small” and “medium”. Experiment with other filters as well, such as blur. You can look up all the common filters on the Common Image Filters page in the manual.