[SOLVED] grass and lightning...

So my grass is created like here: http.developer.nvidia.com/GPUGem … _ch07.html
There is a bit of problem, it is noticable especially in night scenes, like here: mediafire.com/?qnji2mywy1m
But it should be dark from all angles… Any ideas?

I didn’t actually try the code as I didn’t have time, but looking at your egg file, your normals aren’t pointing upward as the GPU Gems page says. The GPU gems chapter states that you should set the normal to 0 0 1 everywhere in the entries in the .egg file.

Hm, doesn’t even look like it can be set in Blender.
I’ll try asking in blenderartists.

It probably can’t.

Not sure this is your problem but if it’s a normal out issue:
In Blender, all your faces selected hit Ctl+n which will redraw all normal outside and Ctl+Shift+n will draw normals inside.
Sometimes, strange behaviour appears where that script don’t solve the problem --> delete your faces and recreate them if there is not too many.
Last solution, make double side faces.

I think this won’t solve it, unfortunately. In this case the normal vector has not to be orthogonal to the faces, but all normal vectors have to point in up-direction, no matter how the faces are oriented. If it can’t be done in Blender it would be possible to export to .egg file format, and then write a script which loads the .egg file and replaces all normals.

And so I did, but it seems this ‘technique’ should be used on a model that has per pixel lightning enabled (it did in my case).

Are you guys sure that having all normals as (0,0,1) will make the object have “per-object lightning”?

Its not really the case. Its alot better, but its still not it.

Here is the script for modifying the normals:

outlines = []

fileobj = open('tree.egg')

for line in fileobj:
	if "<Normal>" in line:
		line = "<Normal> { 0.000000 0.000000 -1.000000 }" + '\n'
	if "<Binormal>" in line:
		line = "<Binormal> { 0.000000 0.000000 1.000000 }" + '\n'
	outlines.append(line)

filename = fileobj.name
fileobj.close()
with open(filename,'w') as out:
	for line in outlines:
		out.write(line)

please try

so can someone please try this on their model and tell if its the same for them (warning: model file will be overwritten)

Code to disable textures is

base.textureOff()

But you don’t post the code that you’re using to run the model. Are you going to make me re-implement the GPU Gems algorithm?

Why are you setting the normal to 0 0 -1 instead of 0 0 1? And why are you messing with the binormal at all?

Note that 0 0 1 is only the correct value if your egg file indicates Z-up. If your egg file indicates Y-up, you should set the normal to 0 1 0 instead.

David

typo, sorry. Doesnt fix it though.
I thought binormal is for flat shading or something…

Chicken exports in Z-up

What algorithm?

from pandac.PandaModules import *
import direct.directbase.DirectStart

dlight = DirectionalLight('dlight')
dlight.setColor(VBase4(0.8, 0.8, 0.5, 1))
dlnp = render.attachNewNode(dlight)
render.setLight(dlnp)

alight = AmbientLight('alight')
alight.setColor(VBase4(0.2, 0.2, 0.2, 1))
alnp = render.attachNewNode(alight)
render.setLight(alnp)

tree = loader.loadModel('tree')
tree.reparentTo(render)
base.textureOff()

run()

So you’re just trying to get uniform shading across the polygon? Setting all the normals to the same value works perfectly for me, as long as you use a DirectionalLight. A PointLight or Spotlight will, of course, still produce different lighting values at different parts of the polygon, because that’s the way these kinds of lights work.

What’s the problem you’re seeing, exactly?

David

If “uniform shading” means single color for whole geom, then yes.

In the above image you see that the edges of the tree (from the camera view) are brighter than the middle.

Well, my polygons don’t look like that, so you need to provide more context.

David

OK, the problem is:

  1. when the branches are set as two sided, you get the above results

  2. when you dublicate the branches and flip normals instead, it is as expected.

Can I use the 1st option but still get the desired effect?

You can set two-sided lighting on your Material:

m = Material()
m.setTwoside(True)
model.setMaterial(m)

But, there are limitations:
(a) This works in OpenGL, but not in DirectX
(b) I don’t think it works when the auto-shader is enabled
© Not using two-sided lighting, and doubling the polygons, often renders faster anyway. It depends on your graphics card.

All this is only an issue if you make your polygons double-sided at runtime using the setTwoSided() call. If you use the bface flag in the egg file instead, the egg loader will automatically double the polygons instead of setting the two-sided flag.

David

I can also call setTwoSided(True) on the nodepath directly.

but its weird as I set twosided in Blender and export that with chicken exporter. I dont enable it in my app or pview. Actually, this is only an issue with per vertex lightning. I’m going to use per-pixel in the end, that and the fact that egg loader makes doubles anyway, makes me wanna dublicate it manually before export.
So its solved, thanks.

Ah, my apologies. Looking closer, I see that in fact the egg loader doesn’t double polygons by default; it does it only if you set “egg-emulate-bface 1” in your Config.prc file (and then blow away the model-cache or at least touch the egg file to force it to reload). So this is why you weren’t seeing the correct behavior when you set the flag in Blender.

That probably should be the default behavior, though. I’ll change it for the future.

David