Sketchfab Forum

Flat Shading for OBJ Files


(fabian) #1

Dear friends,

we are currently working on an game-like design app in VR.
The shapes get exported as OBJ Ascii format. We write the OBJ File directly from our Code.

the content of the obj file looks like this:
v 4.931 -0.000 0.000
v 4.664 1.601 0.000
v 3.891 3.029 0.000
v 2.697 4.128 0.000
v 1.210 4.780 0.000
v -0.407 4.915 0.000
v -1.981 4.516 0.000
v -3.340 3.628 0.000
v -4.337 2.347 0.000
v -4.864 0.812 0.000
v -4.864 -0.812 0.000
v -4.337 -2.347 0.000
v -3.340 -3.628 0.000
v -1.981 -4.516 0.000
v -0.407 -4.915 0.000
v 1.210 -4.780 0.000
v 2.697 -4.128 0.000
v 3.891 -3.029 0.000
v 4.664 -1.601 0.000
v 4.931 -0.000 0.000
v 5.205 -0.736 2.231
v 5.162 0.994 2.231
v 4.559 2.616 2.231
v 3.463 3.955 2.231
v 1.991 4.865 2.231
v 0.304 5.248 2.231
v -1.417 5.062 2.231
v -2.983 4.328 2.231
v -4.227 3.124 2.231
v -5.012 1.583 2.231
v -5.255 -0.131 2.231
v -4.928 -1.830 2.231
v -4.067 -3.331 2.231
v -2.765 -4.471 2.231
v -1.163 -5.127 2.231
v 0.564 -5.226 2.231
v 2.230 -4.760 2.231
v 3.655 -3.778 2.231
v 4.684 -2.386 2.231
v 5.205 -0.736 2.231
v 5.528 -1.596 4.191
v 5.747 0.286 4.191
v 5.342 2.136 4.191
v 4.359 3.755 4.191
v 2.904 4.967 4.191
v 1.134 5.642 4.191
v -0.759 5.703 4.191
v -2.570 5.148 4.191
v -4.102 4.034 4.191
v -5.190 2.484 4.191
v -5.715 0.664 4.191
v -5.621 -1.228 4.191
v -4.918 -2.987 4.191
v -3.682 -4.422 4.191
v -2.047 -5.378 4.191
v -0.190 -5.751 4.191
v 1.688 -5.501 4.191
v 3.382 -4.655 4.191
v 4.710 -3.304 4.191
v 5.528 -1.596 4.191
f 1/1 2/2 21/21
f 2/2 22/22 21/21
f 2/2 3/3 22/22
f 3/3 23/23 22/22
f 3/3 4/4 23/23
f 4/4 24/24 23/23
f 4/4 5/5 24/24
f 5/5 25/25 24/24
f 5/5 6/6 25/25
f 6/6 26/26 25/25
f 6/6 7/7 26/26
f 7/7 27/27 26/26
f 7/7 8/8 27/27
f 8/8 28/28 27/27
f 8/8 9/9 28/28
f 9/9 29/29 28/28
f 9/9 10/10 29/29
f 10/10 30/30 29/29
f 10/10 11/11 30/30
f 11/11 31/31 30/30
f 11/11 12/12 31/31
f 12/12 32/32 31/31
f 12/12 13/13 32/32
f 13/13 33/33 32/32
f 13/13 14/14 33/33
f 14/14 34/34 33/33
f 14/14 15/15 34/34
f 15/15 35/35 34/34
f 15/15 16/16 35/35
f 16/16 36/36 35/35
f 16/16 17/17 36/36
f 17/17 37/37 36/36
f 17/17 18/18 37/37
f 18/18 38/38 37/37
f 18/18 19/19 38/38
f 19/19 39/39 38/38
f 19/19 20/20 39/39
f 20/20 40/40 39/39
f 20/20 1/1 40/40
f 1/1 21/21 40/40
f 21/21 22/22 41/41
f 22/22 42/42 41/41
f 22/22 23/23 42/42
f 23/23 43/43 42/42
f 23/23 24/24 43/43
f 24/24 44/44 43/43
f 24/24 25/25 44/44
f 25/25 45/45 44/44
f 25/25 26/26 45/45
f 26/26 46/46 45/45
f 26/26 27/27 46/46
f 27/27 47/47 46/46
f 27/27 28/28 47/47
f 28/28 48/48 47/47
f 28/28 29/29 48/48
f 29/29 49/49 48/48
f 29/29 30/30 49/49
f 30/30 50/50 49/49
f 30/30 31/31 50/50
f 31/31 51/51 50/50

when I upload them to sketchfab, we get results like this:

as you see, the shading is smoothed.
but we like to have flat shading.

we do not calculate normals because of high processing time.
do we have to?

if we would calculate normals, do we have to make seperated vertices for flat shading?

thank you very much,
a german developer team


(Mrchlblng) #2

We smooth normals with a 45° crease angle when none is provided (as it is the most expected behavior).
To have flat shading, you indeed will have to compute them, which should not take that long; each primitive (triangle in the sample above) will need to have its vertices duplicated and the normal for all vertices should "point" to the same value.


#3

Here it is with all the normals split:


(fabian) #4

dear friends,

thank you for the extended answer and the good looking example :slight_smile:
we are currently recoding our export for double vertices and with correct normals.

you are a fantastic team at sketchfab.
thumbs up!

hope to get the project running soon.
you can expect loads of beautiful vase-like shapes (for public download of course).