PDA

View Full Version : lighting and on-the-fly objects


michaelrepucci
08-19-2008, 01:53 PM
I'm not understanding how to get the correct lighting effects for my on-the-fly objects.

First of all, there are only three types of lights - directional, point, and spot - none of which seem to have an ambient light component. So is ambient light only specified by the material property <node3d>.ambient as set for each on-the-fly object?

Secondly, I can't seem to shut off all lights. If I have the code:

viz.startlayer(viz.QUADS)
viz.vertexcolor(0.7,0.5,0.5)
viz.vertex([x,y,0])
viz.vertex([-x,y,0])
viz.vertex([-x,-y,0])
viz.vertex([x,-y,0])
square = viz.endlayer()
square.enable(viz.LIGHTING)

headLight = viz.MainView.getHeadLight()
headLight.disable()

I can still see my square, albeit darker than without lighting enabled.

Finally, if I check the various lighting properties of the node:

print 'square.getAmbient() =', square.getAmbient()
print 'square.getColor() =', square.getColor()
print 'square.getEmissive() =', square.getEmissive()
print 'square.getShininess() =', square.getShininess()
print 'square.getSpecular() =', square.getSpecular()

they're all the same as the vertexcolor I originally set. And if I set any one of these properties (square.ambient, square.color, square.emissive, square.shininess, or square.specular) to something else, it changes them all to the new value. This doesn't make sense to me. Please can somebody explain this?

farshizzo
08-21-2008, 10:36 AM
This is a bug in the current version. As a workaround you can add the On-The-Fly object to a group node and apply all your material settings to the group node. Either way, you still need to specify normal vectors for your OTF objects in order for the lighting calculations to work correctly. I'm not sure if you are already doing this, but the sample code you provided above does not specify normals.

michaelrepucci
08-21-2008, 01:49 PM
Okay. One annoying undocumented bug down. I'm getting other strange effects too.

Firstly, based on my initial tests, the setting viz.lightModel.twoSided (default=0) seems to imply 0="make the back look just like the front" and 1="make the back respond realistically to light". Consider the following code:

headLight = viz.MainView.getHeadLight()
headLight.disable()
myLight = viz.addLight()
myLight.enable()
myLight.position(0,1,0,0) #make a "sun"
myLight.spread(180)
myLight.intensity(1)
myLight.color(viz.WHITE)

viz.startlayer(viz.QUADS)
viz.vertexcolor(0.8,0.4,0.4)
viz.normal(0,0,-1)
viz.vertex([1,1,0])
viz.vertex([-1,1,0])
viz.vertex([-1,-1,0])
viz.vertex([1,-1,0])
obj = viz.endlayer() #make square in the XY plane at Z=0
obj.setEuler(0,30,0)
obj.setPosition(0,0,1)
obj.enable(viz.LIGHTING)


With viz.lightModel.twoSided=0 both sides look pink, but with viz.lightModel.twoSided=1 the top side looks pink, while the bottom side is darker. What is really odd is that if I draw a disc with:

viz.startlayer(viz.POLYGON)
viz.vertexcolor(0.8,0.4,0.4)
viz.normal(0,0,-1)
for i in range(32):
radians = 2*math.pi*i/32
viz.vertex([0.1*math.sin(radians),0.1*math.cos(radians),0])
viz.vertex([0.1*math.sin(radians),0.1*math.cos(radians),0])
obj = viz.endlayer()


and do the same thing as above, the bright and dark faces seem to get swapped. Both the square and the disk are drawn counter-clockwise, and have the same normals, so what gives?

When I start grouping these objects together, and setting the color for the group, then the dark sides get even darker. I now think I understand that this is because the bug described above. Please correct me if I'm wrong.

farshizzo
08-22-2008, 04:16 PM
The code you have draws the disc clock-wise to the normal, so that is why the coloring is inverted. Try negating the x value when specifying the disc vertex and the lighting should appear correct. Also, your code for drawing the disc is specifying the same vertex twice, which is unnecessary.

michaelrepucci
08-23-2008, 08:14 AM
That was what I suspected, since I do know a little OpenGL, but the documentation doesn't talk about that at all. Is it fair to assume that everything in Vizard simply reflects the analogous call in OpenGL?

BTW, I realized I'd made a basic trigonometry error: cos should be paired with the x value, and sin paired with the y. That would wind counter-clockwise, and was what I had intended. I don't know how that vertex line got doubled, but thanks for pointing it out.

tobin
08-27-2008, 09:45 AM
Vizard is built upon OpenSceneGraph, which in turn is based on OpenGL. The behavior of some Vizard primitives can be predicted through knowlege of OpenGL, but we're not always strict in this relationship.

jrajsic
07-04-2009, 08:34 AM
I'm wondering something similar with regards to ambient lighting, and I'm just looking for a confirmation or disconfirmation of whether ambient lighting of objects in the environment (with the headlight turned off) is determined just by their ambient properties, or if there is an ambient light that can be disabled?

Thank you

michaelrepucci
07-04-2009, 02:26 PM
There is a default head-lamp that you can shut off if you don't want. See the documentation for "head-lamp" under "light basics". Otherwise, from my understanding, the light calculations follow the same rules as those in OpenGL (or OpenSceneGraph).

jrajsic
07-08-2009, 11:01 AM
Sorry if my last post wasn't clear, what I'm wondering is basically the answer to the first of your questions in your initial post: "is ambient light only specified by the material property <node3d>.ambient as set for each on-the-fly object?"

It doesn't seem like that question was directly addressed, which I assume means you were right, but I'd just like to know for sure.

With the headlamp turned off, objects are still semi-visible, and I'd like them to be completely dark. I have gotten this to work by setting the ambient values of the objects to (0,0,0) - I'm just wondering if there's another way to get total darkness?

Thanks again.

michaelrepucci
07-08-2009, 11:16 AM
Sorry, I don't think I read your question, or my previous posts very carefully. I do remember this strange effect, and I'm not sure I ever solved it, though I suspect I did given that I didn't ask again. Unfortunately, I am no longer using Vizard (new and different job), so I can't play around with this any more.

But perhaps in your setup the <node3d>.emissive property is not zero. This will make objects give off their own light. With the on-the-fly objects I was using that bug mentioned above prevented me from setting this property appropriately the obvious way, so keep that in mind.

Beyond that shot in the dark (pun intended) I'm afraid I can't be of further help. Perhaps one of the Vizard gurus will shed some light on the topic (another bad pun).

renama
02-09-2011, 06:57 PM
This thread is discussing the exact issue we need in our project. But after many tries, I still could not make the 3D effect on the on-the-fly objects. The cylinder and cone do not have the same lighting effect with the imported 3D ball. I changed the value of obj.shininess, obj.emissive,obj.specular, and etc. but it does not work. I believe Vizard does support this function, I just could not figure out how to make it happen. Can anybody help. I apprecate it....

farshizzo
02-10-2011, 09:11 AM
How are you creating the cone/cylinder objects? Are you using the vizshape module?

I just tried it out, and the cylinder object created by the vizshape module is affected by light.

If you could provide some sample code, that might help us debug your issue.

renama
02-11-2011, 08:26 AM
We use on-the-fly object by using viz.startlayer(), viz.endlayer(). I did not know the vizshape module. That works better. Thank you!