I can’t get shadows to work using display regions.
I am using the softshadow example to accomplish this.
Can someone help me out please.
You can download the file here:
megaupload.com/?d=KOCPQFGK
Filename: shadowsEdited.rar
Filesize: 487.78 KB
Or you can check the code here:
#!/usr/bin/env python
from pandac.PandaModules import loadPrcFileData
from pandac.PandaModules import *
loadPrcFileData("", “prefer-parasite-buffer #f”)
#loadPrcFileData("", “show-frame-rate-meter #t”)
from direct.directbase import DirectStart
Import whatever classes are necessary
from direct.interval.IntervalGlobal import Sequence
from sys import exit
import random, math
from math import pi, sin
from random import random
Import the Shadow Manager
from shadowManager import ShadowManager
class World(object):
def init(self):
# Make a way out of here!
base.accept("escape", exit)
################################################################
""" SETUP LIGHTS """
################################################################
# Light1 - Sunlight
self.Light1 = PointLight('light1')
self.Light1.setColor(VBase4(2.5, 2.5, 2.5, 1))
self.pointLight1 = render.attachNewNode(self.Light1)
self.pointLight1.setPos(0, 0, 300)
# Light2 - Shadow light (ambient)
self.Light2 = AmbientLight('light2')
self.Light2.setColor(VBase4(0.75, 0.75, 0.75, 1))
self.ambientLight1 = render.attachNewNode(self.Light2)
################################################################
""" SETUP SHADOW """
################################################################
# Initiate the shadows
self.sMgr = ShadowManager(render)
self.sMgr.setAmbient(0.2) # Most of these five are the default
self.sMgr.setHardness(30) # values so it was kinda unnecessary to
self.sMgr.setFov(30) # set them explicitly but I wanted to
self.sMgr.setNearFar(10, 1000) # show how to set them anyway.
################################################################
""" SETUP MODELS """
################################################################
#Create the dummy nodes
self.dummyNode = render.attachNewNode("renderAllModels")
# Uneven terrain
self.env = loader.loadModel("terrain002")
self.env.reparentTo(self.dummyNode)
self.env.setPos(0,0,-5)
self.env.setScale(0.5,0.5,0.5)
# Load the teapot
self.teapot = loader.loadModel("teapot")
self.teapot.setTwoSided(True)
self.teapot.reparentTo(self.dummyNode)
# The teapot has no texture, so you have to tell it to the ShadowManager
# Otherwise the model will turn up black.
self.sMgr.flagUntexturedObject(self.teapot)
# Set intervals to move the teapot
self.teapot.hprInterval(5.0, Vec3.zero(), Vec3(360, 0, 0)).loop()
Sequence(self.teapot.posInterval(2.0, Point3.zero(), Point3(2, 0, 1)), self.teapot.posInterval(2.0, Point3(2, 0, 1), Point3.zero())).loop()
################################################################
""" LIGHTS - CAMERAS - ACTION """
################################################################
# ***********************************************************************
## # Camera setup
## self.my_cam1 = Camera("cam1")
## self.my_camera1 = render.attachNewNode(self.my_cam1)
## self.my_camera1.setName("camera1")
## self.my_camera1.setPos(-10,-10,50)
## self.my_camera1.lookAt(self.teapot)
## self.my_camera1.node().getLens().setAspectRatio(4.0/2.0)
## self.camSpot = self.my_camera1.getPos()
## # Disable the default DisplayRegion, which covers the whole screen.
## self.dr = base.camNode.getDisplayRegion(0)
## self.dr.setActive(0) # disable ( use displayRegion 0 )
## # DisplayRegions.
## self.window = self.dr.getWindow()
## self.dr1 = self.window.makeDisplayRegion(0.026, 0.975, 0.02, 0.98)
## self.dr1.setSort(self.dr.getSort())
## # Setup the camera
## self.dr1.setCamera(self.my_camera1)
## base.disableMouse()
## camPivot = render.attachNewNode("cameraPivotPoint")
## self.my_camera1.reparentTo(camPivot)
## self.my_camera1.node().getLens().setNearFar(1,1000)
## self.my_camera1.node().getLens().setFov(45)
## ## self.my_camera1.setPos(self.teapot.getX()-10, self.teapot.getY()+10, 1.5)
## self.my_camera1.setPos(-30,-30,35)
## self.my_camera1.lookAt(self.teapot)
"""To use display region, uncomment the above commented code...
then comment the code under 'Setup the camera.'"""
# Setup the camera
base.disableMouse()
camPivot = render.attachNewNode("cameraPivotPoint")
base.cam.reparentTo(camPivot)
base.camLens.setNearFar(1,1000)
base.camLens.setFov(75)
base.cam.setPos(-10,-10,15)
base.cam.lookAt(self.teapot)
# ***********************************************************************
# Setup an interval to rotate the camera around camPivot
camPivot.hprInterval(15.0, Vec3.zero(), Vec3(360, 0, 0)).loop()
# Apply lights
self.dummyNode.setLight(self.pointLight1)
self.dummyNode.setLight(self.ambientLight1)
# Position the shadow camera
self.sMgr.light.setPos(0,20,80)
self.sMgr.light.lookAt(self.teapot)
self.sMgr.light.node().showFrustum() # Show the frustrum
Initiate the world class and run!
World();run()