www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: Thomas. on June 13, 2012, 06:55:25 pm

Title: Load normals from file
Post by: Thomas. on June 13, 2012, 06:55:25 pm
Egon, please, could you add support for load normals from OBJ file? For compatibility you can add "Config.loadNormalsFromOBJ = false;" ... Thanks, in return I offer model for your game :) ... and it would be nice if you also add possibility for object without normals, maybe method "Object3D.build(boolean containsNormals);"
Title: Re: Load normals from file
Post by: EgonOlsen on June 13, 2012, 09:15:08 pm
Deal! Albeit i personally think that this normals-topic is highly overrated... ;) However, it will take some days to find the time to finish this. Can you provide me with a simple model that contains proper normals? A sphere might be useful for this.
Title: Re: Load normals from file
Post by: Thomas. on June 13, 2012, 09:40:56 pm
Perfect :) here you have sphere with normals...

http://dl.dropbox.com/u/26148874/sphere.zip (http://dl.dropbox.com/u/26148874/sphere.zip)
Title: Re: Load normals from file
Post by: Thomas. on June 14, 2012, 12:09:52 pm
I'm not sure, that help me loaded normals. It seems to be saved normals per face, not per vertex. What I want is well lighting box. But object without normals is still important for me...

In screenshots below is problem, which I have. I'm using per-pixel lighting. Any idea, how fix bad lighting polygons?

(http://dl.dropbox.com/u/26148874/device-2012-06-14-115914.png)

(http://dl.dropbox.com/u/26148874/device-2012-06-14-115942.png)

(http://dl.dropbox.com/u/26148874/device-2012-06-14-120005.png)

(http://dl.dropbox.com/u/26148874/device-2012-06-14-120119.png)
Title: Re: Load normals from file
Post by: EgonOlsen on June 14, 2012, 08:59:15 pm
This doesn't really look like per-pixel to me... ???
Title: Re: Load normals from file
Post by: Thomas. on June 14, 2012, 09:08:31 pm
It's should be per-pixel... Have you any per-pixel shader, which you can share? All objects have same shader...

 (http://2i.cz/2i/t/4aeb85af7c.jpg)  (http://2i.cz/4aeb85af7c)
Title: Re: Load normals from file
Post by: EgonOlsen on June 14, 2012, 09:13:25 pm
Try this one: http://www.jpct.net/forum2/index.php/topic,2723.msg20330.html#msg20330 (http://www.jpct.net/forum2/index.php/topic,2723.msg20330.html#msg20330)
Title: Re: Load normals from file
Post by: Thomas. on June 14, 2012, 09:38:46 pm
I removed specular color, but problem is still same...

(http://dl.dropbox.com/u/26148874/device-2012-06-14-213639.png)
Title: Re: Load normals from file
Post by: EgonOlsen on June 14, 2012, 09:46:52 pm
I see...the polygons are pretty large and because the normals on sharp edges are much different from those on flatter surfaces, it'll look this way despite of per pixel lighting. Increasing the geometries tessellation level should help, but it'll slow down the whole thing and uses more memory, so maybe that's not an option. I doubt that loading the normals from the file will help much, but we'll see. However, i still think that this is totally acceptable once you apply textures to the surfaces...but then again, i somehow like this vertex lit look of things like others like pixel art... :)
Title: Re: Load normals from file
Post by: Thomas. on June 14, 2012, 10:16:54 pm
Whole problem is in normals in vertices. I need same normal in vertex and same in face... I also tried divide one polygon to many small, but every small polygon is visible and result is not much better...
Title: Re: Load normals from file
Post by: EgonOlsen on June 14, 2012, 10:35:16 pm
If your vertex normals are equal to your face normals, you'll get flat shading. Or did i misunderstood that part?
Title: Re: Load normals from file
Post by: Thomas. on June 14, 2012, 10:39:56 pm
Yes, flat shading, but just in some part of object... I think, that this is called smooth groups and OBJ has support for this...

(http://www.kxcad.net/autodesk/3ds_max/autodesk_3ds_max_9_reference/graphics/il_smoothing_groups.jpg)

I don't know how engine working, but GenericVertexControler is working with for ex. 8 vertices in box, so I can't affect all 32 vertices, that are sent to GPU, so I expect that normal is saved per one together vertex and is impossible to implement something else...
Title: Re: Load normals from file
Post by: EgonOlsen on June 14, 2012, 11:18:43 pm
I don't get that picture...if the highlighted part is supposed to illustrate a smoothing group, it's simple the opposite of vertex-normals=face-normals and if you feed such a model in your game, you should get smooth lighting. If you don't, you don't have per pixel lighting enabled for whatever reason....anyway, we'll see what we'll get when reading the normals from the file.

The engine shares normals just like it shares vertices. You can disable this behaviour at load time if you tell the Loader so and the model is build that way, but depending on the mesh, this will largely increase vertex count.

Title: Re: Load normals from file
Post by: Thomas. on June 14, 2012, 11:32:45 pm
Can I somehow get the lighting similar to medial bucket? I think, that this will need smoothing group and two way to calculate normals, because now engine every calculate normals like smooth...

edit: but it's not so hard, next boolean array to triangles (enable by parameter in constructor), if is smooth or flat. And calculate normal by old method, or just copy flat normal to vertex :)
Title: Re: Load normals from file
Post by: Thomas. on June 18, 2012, 12:16:52 am
Sorry, I had confusion in smoothing groups, they are probably unnecessary. I did a little test with normals. Whatever are saved normals to OBJ file or not, results are same when I open the model in Deep Exploration, so it seem, that this program is using some more complicated calculation of normals...

(http://dl.dropbox.com/u/26148874/object.png)

this file contains normals and for testing will be probably better than sphere
http://dl.dropbox.com/u/26148874/obejct.zip
Title: Re: Load normals from file
Post by: Thomas. on June 24, 2012, 04:26:38 pm
Any news about normals?
Title: Re: Load normals from file
Post by: EgonOlsen on June 24, 2012, 07:53:21 pm
No, not yet...
Title: Re: Load normals from file
Post by: EgonOlsen on July 02, 2012, 08:42:16 pm
Give it a try:

http://jpct.de/download/beta/jpct.jar (http://jpct.de/download/beta/jpct.jar)
http://jpct.de/download/beta/jpct_ae.jar (http://jpct.de/download/beta/jpct_ae.jar)

Both have a new switch in Config (Config.useNormalsFromOBJ). Setting this to true will make jPCT load the normals from the file and don't calculate new ones during build(). At least that's what's supposed to happen.... ;)
Title: Re: Load normals from file
Post by: Thomas. on July 03, 2012, 02:05:25 pm
I created test project, so you can see how it works (back button for load/calculate normals, menu button for switch between many objects). Any idea why is lighting bad??

http://dl.dropbox.com/u/26148874/TestProject.zip (http://dl.dropbox.com/u/26148874/TestProject.zip)

edit: in 3ds max and deep exploration seems these models correctly...
Title: Re: Load normals from file
Post by: EgonOlsen on July 03, 2012, 02:23:28 pm
Can't run that ATM. Any screen shots?
Title: Re: Load normals from file
Post by: Thomas. on July 03, 2012, 02:35:05 pm
Here are screenshots

http://dl.dropbox.com/u/26148874/screenshots.zip (http://dl.dropbox.com/u/26148874/screenshots.zip)
Title: Re: Load normals from file
Post by: EgonOlsen on July 03, 2012, 09:42:40 pm
I found the problem. Whoever invented the OBJ-format has to suffer endlessly...i'll try to fix it, but it will require some internal changes to the object compiler as well...
Title: Re: Load normals from file
Post by: EgonOlsen on July 03, 2012, 10:13:03 pm
I've uploaded new versions that might work better. However, this comes at the cost of additional compile time (might not be significant, i haven't benchmarked this) and slightly higher memory usage of objects with "file normals".
Title: Re: Load normals from file
Post by: Thomas. on July 03, 2012, 10:24:52 pm
YES, nice, everything seems fine :)
Title: Re: Load normals from file
Post by: zammbi on July 04, 2012, 02:51:24 am
Quote
Whoever invented the OBJ-format has to suffer endlessly

Well the closest names responsible I could come up with is the founders of Wavefront.  :P
Quote
It was founded in 1984, in Santa Barbara, California, by Bill Kovacs, Larry Barels, Mark Sylvester.
http://en.wikipedia.org/wiki/Wavefront_Technologies