Manupulating Spotlights

Hello,

I’m trying to undeerstand how does Spotlight work and specillay trying to enlarge the area being lighted. I tried to adjust the field of view, near / far and filmSize but still not able to get the result I’m aming.

One solution is to put the Spotlight very far from the scene but the effect I would have to obtain is a Spotlight ligthing a room from near but a large area!

Here’s my test:

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

class Start(DirectObject):
	def __init__(self):
		self.accept("escape", sys.exit)
		self.accept('p',self.addFov)
		self.accept('o',self.remFov)
		self.accept('k',self.addFSize)
		self.accept('l',self.remFSize)
		instruction1= OnscreenText(text='o:add FOV   p: rem FOV',scale=.07,pos=(-1,.9))
		instruction2= OnscreenText(text='k:add FSize   l: rem FSize',scale=.07,pos=(-1,.8))
		self.fov= OnscreenText(text='FOV',scale=.07,pos=(-1,.4))
		self.fSize=OnscreenText(text='Film Size',scale=.07,pos=(-1,.1))
		
		self.bSmiley= loader.loadModel('smiley.egg')
		self.bSmiley.reparentTo(render)
		self.bSmiley.setScale(3)
		
		self.light = Spotlight('light')
		self.light.setColor(Vec4(2, 2, 2, 1))
		self.plnp = render.attachNewNode(self.light)
		self.plnp.setPos(0,-4.5,0)
		self.plnp.lookAt(self.bSmiley)
		render.setLight(self.plnp)
		
		self.sSmiley= loader.loadModel('smiley.egg')
		self.sSmiley.reparentTo(self.plnp)
		self.sSmiley.setScale(.05)
		
		base.disableMouse()
		base.camera.setPos(3,-8,10)
		base.camera.lookAt(self.sSmiley)
		
		
	def addFov(self):
		tmpFov= self.light.getLens().getFov()
		self.light.getLens().setFov(tmpFov +10)
		self.fov['text']= str(self.light.getLens().getFov())
	def remFov(self):
		tmpFov= self.light.getLens().getFov()
		self.light.getLens().setFov(tmpFov -10)
		self.fov['text']= str(self.light.getLens().getFov())
		
	def addFSize(self):
		tmpFSize= self.light.getLens().getFilmSize()
		self.light.getLens().setFilmSize(tmpFSize+ (10,10))
		self.fSize['text']= str(self.light.getLens().getFilmSize())
	def remFSize(self):
		tmpFSize= self.light.getLens().getFilmSize()
		self.light.getLens().setFilmSize(tmpFSize- (10,10))
		self.fSize['text']= str(self.light.getLens().getFilmSize())
Start()
run()

If you try this code :pressing ‘p’ is supposed to enlarge the FOV. I do understand that a lamp is somehow a camera and that FOV need to be between 0 and 180 but I do not understand why the bigger smiley is not lighted anymore when the value 50 is bypassed.
Is the max FVO value of a lamp smaller than max FOV of a camera ?
Originally, I tried this on a room… So that’s not linked to the fact that smiley is a sphere.

The Spotlight doesn’t necessarily illuminate the entire region within its FOV; that’s determined by the exponent. The larger the exponent, the smaller the spot of light within the FOV.

Try setting the exponent to 1 to get the effect you’re looking for.

Also, try adding self.light.showFrustum() to visualize the frustum you’re creating.

David

Thanks David :slight_smile:
setExponent() is the right method.