Author Topic: Triangulated Geometry  (Read 3365 times)

Offline suraklyn

  • byte
  • *
  • Posts: 4
    • View Profile
Triangulated Geometry
« on: January 05, 2012, 11:36:02 pm »
I basically have my geometry defined in an XML file.  The geometry defined in the XML file is triangulated, so I'm creating my Object3Ds using addTriangle.  The only "issue" I'm running into has to do with shading -- triangles that form coplanar faces are being shaded independently, and it looks a bit wonky.

I'm really just in the tinkering phase with this project -- just trying to proof of concept displaying models exported from our application on an Android phone -- but it would help my demo on Monday if there was a means of improving this.

Maybe there's a way of blending the shading between adjacent faces or a way of creating coplanar faces from the triangulated geometry to reduce the face count?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Triangulated Geometry
« Reply #1 on: January 05, 2012, 11:54:46 pm »
Do you have some screen shot of this? I'm not 100% sure if you mean what i think you do...

Offline suraklyn

  • byte
  • *
  • Posts: 4
    • View Profile
Re: Triangulated Geometry
« Reply #2 on: January 06, 2012, 12:28:59 am »
Sure deal.



This sample is just a cube with a notch carved out of the corner.

Edit: If it makes a difference, to have the shading look more similar to our modeling application, I set the shading mode to SHADING_FAKED_FLAT on the Object3D.
« Last Edit: January 06, 2012, 12:40:56 am by suraklyn »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Triangulated Geometry
« Reply #3 on: January 06, 2012, 09:20:26 pm »
jPCT calculates vertex normals based on the averaged face normals of adjacent polygons. Depending on the structure of the object, this might create unexpected results if two polygons seem to be pretty similar, but the characteristics of their vertices' adjacent polygons are different...i'm not sure how to explain this...
The faked flat shading is faked in the way that it still uses the vertex normals and not the face normals, which makes the same fact apply here too.
However, i'm still not sure what the real problem is with this. Maybe a screen shot with normal shading and something that explains what you actually want to achieve would help...


Offline suraklyn

  • byte
  • *
  • Posts: 4
    • View Profile
Re: Triangulated Geometry
« Reply #4 on: January 06, 2012, 11:31:57 pm »
This image may help me explain a bit more.  I'm pretty new to the rendering world, scenegraphs, sceneviewers, opengl, etc., so please bear with me.

This is using the faked shading.


This is using the default shading. (I'll admit, this is the first time I've defaulted back to this shading since I moved away from using a cube as my test geometry, and it looks quite a bit better on this test.)


This is a screenshot of the building in our application that I'm trying to mimic.


All three of the images are of the same, simple building.  Originally I was aiming for shading more akin to what was discussed in this thread: http://www.jpct.net/forum2/index.php/topic,1444.msg10269.html#msg10269 (this is much closer to show the shading works in our application), but I'm pretty tempted to leave it with the default shading with the way it's looking now.


However, even if I leave it with the default, I'm still interested in my original thought.  In the first image with faked shading, you can see the left hand wall is made of two triangles, and its adjacent wall is made up of 4 triangles.  On both walls, shading is applied whole sale to each triangle with each being shaded at different levels (in some cases, very different). What I'm wondering is if there's a way to either smooth out this shading that gets applied, or maybe there's a way of reversing the triangulation by doing a union of adjacent, coplanar triangles that make up a given wall that would simplify the geometry and probably improve the faked shading as a side effect?

« Last Edit: January 07, 2012, 12:11:14 am by suraklyn »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Triangulated Geometry
« Reply #5 on: January 06, 2012, 11:46:17 pm »
You might to try what happens to FAKED_FLAT_SHADING if you call disableVertexSharing() on your Object3D before adding your polygons...

Offline suraklyn

  • byte
  • *
  • Posts: 4
    • View Profile
Re: Triangulated Geometry
« Reply #6 on: January 09, 2012, 08:12:00 pm »
I gave the faked shading a stab after calling disableVertexSharing(), and the results were mixed.  In some cases, the shading looked more appropriate while in other other cases not so much.  I do plan to play more with things to see if I can improve on this.

In the end, the demo went really well, and I suspect we'll be revisiting this in the coming year.

I definitely appreciated your input as I worked through this, and I was quite happy with the existing community and resources that were available as I was tinkering with jPCT -- I found that to be lacking when looking into other toolkits.

Thanks again, and I look forward to becoming more familiar and adept with this.