Author Topic: Load normals from file  (Read 4195 times)

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Load normals from file
« 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);"

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11744
    • View Profile
    • http://www.jpct.net
Re: Load normals from file
« Reply #1 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.
« Last Edit: June 13, 2012, 09:47:58 pm by EgonOlsen »

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Load normals from file
« Reply #2 on: June 13, 2012, 09:40:56 pm »
Perfect :) here you have sphere with normals...

http://dl.dropbox.com/u/26148874/sphere.zip

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Load normals from file
« Reply #3 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?








Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11744
    • View Profile
    • http://www.jpct.net
Re: Load normals from file
« Reply #4 on: June 14, 2012, 08:59:15 pm »
This doesn't really look like per-pixel to me... ???

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Load normals from file
« Reply #5 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...


Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11744
    • View Profile
    • http://www.jpct.net

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Load normals from file
« Reply #7 on: June 14, 2012, 09:38:46 pm »
I removed specular color, but problem is still same...


Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11744
    • View Profile
    • http://www.jpct.net
Re: Load normals from file
« Reply #8 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... :)

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Load normals from file
« Reply #9 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...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11744
    • View Profile
    • http://www.jpct.net
Re: Load normals from file
« Reply #10 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?

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Load normals from file
« Reply #11 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...



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...
« Last Edit: June 14, 2012, 10:47:53 pm by Thomas. »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11744
    • View Profile
    • http://www.jpct.net
Re: Load normals from file
« Reply #12 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.


Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Load normals from file
« Reply #13 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 :)
« Last Edit: June 15, 2012, 01:24:48 am by Thomas. »

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Load normals from file
« Reply #14 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...



this file contains normals and for testing will be probably better than sphere
http://dl.dropbox.com/u/26148874/obejct.zip
« Last Edit: June 18, 2012, 12:19:01 am by Thomas. »