shadows

ive been trying for about 4 hours to get shadows to work
with no luck. idk if its the type of light im using or something else. If i could get a reallly basic example of shadows or maybe some help with my code i woukd be grateful :smiley:

import direct.directbase.DirectStart
from pandac.PandaModules import *
from direct.gui.OnscreenText import OnscreenText
from pandac.PandaModules import WindowProperties 
import sys

class Main(object):
	def __init__(self):
		base.disableMouse() # disables the default mouse camera controls
		base.accept( "escape" , sys.exit) # quits when escape is pressed
		self.loadPlayer = Player() # Calls up the Player() class
		self.addWinProps()
		self.addlight() # load the light
	def addlight(self): #create the light
		#create a directional light to give a sense of 3d ness
		dlight = DirectionalLight('dlight')
		dlight.setColor(VBase4(0.8, 0.8, 0.8, 1))
		dlight.setShadowCaster(True)
		dlnp = render.attachNewNode(dlight)
		dlnp.setHpr(0, -60, 0)
		render.setLight(dlnp)
		render.setShaderAuto()
	def addWinProps(self):#defines the windows properties aka title and hide cursor etc
		props = WindowProperties()
		props.setCursorHidden(True)
		props.setTitle('Space Fighter')
		base.win.requestProperties(props)
class Player(object): # controls the Player
	speed = 250 # controls the speed of the ship
	FORWARD = Vec3(0, 2, 0) # sets direction and speed of forward direction
	STOP = Vec3(0, 0, 0)# sets the speed and direction of stop
	walk = STOP # makes walk = stop
	def __init__(self):
		self.loadShip() #calls up the function to load the ship
		self.loadWorld()
		self.createControls()
		self.setCamera()
		taskMgr.add(self.updatePos, 'update position')
		taskMgr.add(self.mouseUpdate, 'update mouse')
	def loadShip(self): # just loads the ship model
		self.ship = loader.loadModel('ship')
		self.ship.reparentTo(render)
		self.ship.setTwoSided(True)
		self.ship.setScale(.5)
	def loadWorld(self): # loads world
		self.world = loader.loadModel('level')
		self.world.reparentTo(render)
		self.world.setPos(-1, 30, 3)
		self.world.setScale(80)
	def setCamera(self): # sets the camera lense
		place = base.cam.node().getLens()
		place.setFov(70)
		base.cam.node().setLens(place)
		base.camera.reparentTo(self.ship)
		base.camera.setY(-30)
		base.camera.setZ(5)
	def mouseUpdate(self,task): # updates the mouse and changes ships P and H accordingly
		md = base.win.getPointer(0)
		x = md.getX()
		y = md.getY()
		if base.win.movePointer(0, base.win.getXSize()/2, base.win.getYSize()/2):
			self.ship.setP(self.ship.getP() -  (y - base.win.getYSize()/2)*0.1)
			self.ship.setH(self.ship.getH() - (x - base.win.getXSize()/2)*0.1)
		return task.cont
	def createControls(self): # changes the value of walk to either STOP or Forward depending on the keypress
		base.accept( "w" , self.__setattr__,["walk",self.FORWARD])
		base.accept( "w-up" , self.__setattr__,["walk",self.STOP] )

	def updatePos(self,task): # task to move the ship and camera
		self.ship.setPos(self.ship,self.walk*globalClock.getDt()*self.speed)
		return task.cont
Main()
run()

Try with spotlight, it’s easier.

Yes, the builtin shadows are only good with spotlights. But scenes that use spotlights arent much as well.

Youre gonna have to use a custom shader if you want shadows with other types of lights. But then you basically break the whole shader generator.

Proper shadows is something I think Panda3d is really lacking.

Thanks :slight_smile: I’ll try a spotlight and see what happens. If it doesnt turn out well looks like I’ll have to go with custom shaders :confused: