Cannot get Lighting to work.

Return to General Discussion

Cannot get Lighting to work.

Postby Timaman » Tue Feb 14, 2012 2:22 pm

Ok so I'm pretty new to Panda3d and Python, I've been using them for about 3-4 days now and I have hit (another) wall blocking my progress.

This wall is that I cannot get any lighting to work. At all. I'm stuck with the default flat lighting and my project needs light and shadows and such to make it look good.

This is the code I am using to attempt to light my stuff at the moment:

def PointLight():
# Apply a plight.
plight = PointLight('plight')
plight.setColor(VBase4(0.2, 0.2, 0.2, 1))
plight.node.setAttenuation(Vec3( .1, 0.04, 0.0))
plnp = render.attachNewNode(plight)
plnp.setPos(0, 0, 0)
render.setLight(plnp)


I realize I might need to import something or... dunno. I don't know enough about Panda3d and Python to know if there is something I have missed. If you have any suspicions at all please say so I can try them. Or I might have missed something really basic. Either way, I need some help please.

Thanks.
Eat ALL the cheese!!!
Timaman
 
Posts: 4
Joined: Tue Feb 14, 2012 2:16 pm

Postby red15 » Tue Feb 14, 2012 3:17 pm

It seems you called your function PointLight, I would strongly suggest against this because if it would not cause Python to get confused about whether to call your function or the Panda PointLight class you will at some point in the future be confused about it and mess up.

Other option that I suggest is you try with and without the shader autogeneration.

Look at the last section on this page closely : http://www.panda3d.org/manual/index.php/Lighting
red15
 
Posts: 8
Joined: Thu Dec 22, 2011 7:13 am

Postby Timaman » Tue Feb 14, 2012 3:51 pm

Ok I've tried both these things and I'm still getting nothing.

Here is my current code:

def APointlight():
# Apply a plight.
plight = APointlight('plight')
plight.setColor(VBase4(0.2, 0.2, 0.2, 1))
plight.node.setAttenuation(Vec3( .1, 0.04, 0.0))
plnp = render.attachNewNode(plight)
plnp.setPos(0, 0, 0)
render.setLight(plnp)

# Use a 512x512 resolution shadow map
light.setShadowCaster(True, 512, 512)
# Enable the shader generator for the receiving nodes
render.setShaderAuto()


Do I need to import anything to get lighting/shadows to work perhaps?[/quote]
Eat ALL the cheese!!!
Timaman
 
Posts: 4
Joined: Tue Feb 14, 2012 2:16 pm

Postby red15 » Wed Feb 15, 2012 4:55 am

Timaman wrote:
def APointlight():
# Apply a plight.
plight = APointlight('plight')
plight.setColor(VBase4(0.2, 0.2, 0.2, 1))
plight.node.setAttenuation(Vec3( .1, 0.04, 0.0))
plnp = render.attachNewNode(plight)
plnp.setPos(0, 0, 0)
render.setLight(plnp)

# Use a 512x512 resolution shadow map
light.setShadowCaster(True, 512, 512)
# Enable the shader generator for the receiving nodes
render.setShaderAuto()



Seems you have are already being confused by your duplicate usage of the name PointLight. The assignment of plight should be PointLight not APointLight.

The PointLight itself will be defined when you imported it like so:
Code: Select all
from panda3d.core import PointLight


Furthermore you then pasted code from the page I linked without properly adjusting it and thus the variable "light" will never be defined.

Are you not getting plenty of runtime errors ? Usually those can help us a long way to help you with the exact problem you're having.

To me it seems your lack of knowledge in python and general programming is the first hurdle you're already having trouble with.

I'm not saying you should stop asking questions but reading some more python examples and more experimenting with panda samples would prevent you from getting confused.
red15
 
Posts: 8
Joined: Thu Dec 22, 2011 7:13 am

Postby Timaman » Wed Feb 15, 2012 12:22 pm

Well I've got the import code in, and I have had for a while, without success.

If I have understood what you said correctly, you said that the PointLight is already defined by the said code, so I removed it and the indents so it fits into the "def __init__".

I get a runtime error now that looks like this:

Traceback (most recent call last):
File "glock.py", line 71, in <module>
app = MyApp()
File "glock.py", line 29, in __init__
plight.setColor(VBase4(0.2, 0.2, 0.2, 1))
NameError: global name 'VBase4' is not defined


The VBase4 is from the lights lines of code, but I do not have a clue what to do. Assuming I've got this all right that is.

I have done programming in the past, I did JavaScript for a year procedural, and I'm now doing Java in Netbeans and have been since September. Python is new to me and quite a large jump.
Eat ALL the cheese!!!
Timaman
 
Posts: 4
Joined: Tue Feb 14, 2012 2:16 pm

Postby rdb » Wed Feb 15, 2012 1:30 pm

Code: Select all
from panda3d.core import VBase4
rdb
 
Posts: 9748
Joined: Mon Dec 04, 2006 5:58 am
Location: Netherlands

Postby Timaman » Wed Feb 15, 2012 2:13 pm

I tried that in the following format earlier without success:

from panda3d.core import PointLight, VBase4


Either way by itself it works.

Now I get this error:

Traceback (most recent call last):
File "glock.py", line 72, in <module>
app = MyApp()
File "glock.py", line 31, in __init__
plight.node.setAttenuation(Vec3( .1, 0.04, 0.0))
AttributeError: 'libpanda.PointLight' object has no attribute 'node'


Not a clue what libpanda is.
Eat ALL the cheese!!!
Timaman
 
Posts: 4
Joined: Tue Feb 14, 2012 2:16 pm

Postby rdb » Wed Feb 15, 2012 2:54 pm

It's plight.setAttenuation, not plight.node.setAttenuation.


I would suggest familiarising yourself with Python programming before you get into Panda3D programming.
rdb
 
Posts: 9748
Joined: Mon Dec 04, 2006 5:58 am
Location: Netherlands


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 2 guests