How to create flat shaded box?

Blitz3D Forums/Blitz3D Programming/How to create flat shaded box?

Shifty Geezer(Posted 2005) [#1]
Now I wonder how many readers saw the title and just thought 'why not use CreateCube()? ;)

I'm wanting a flat shaded box as produced by CreateCube, but where I can apply a texture to one face. I've modelled a cube with 8 vertices, 12 triangles, but the shading is wrong. I've also modelled a box with 6 separate 4 vertex planes but they still shade wrong. By wrong I mean triangles appearing across the square face, instead of a uniform shading per face.

How can I create a flat-shaded box and apply a texture to a single face?


Shifty Geezer(Posted 2005) [#2]
Well I've found EntityFX flag 4 for flat shaded, but my object hasn't the same Shininess result as other cubes. If I use Createcube() alongside my own cube, where the top of the CreateCube() mesh is shiny and white my own object isn't. From a different angle the face facing the light does get illuminated though. How do I get the same lighting response?


jfk EO-11110(Posted 2005) [#3]
Probably the normals are stored bugous. Try UpdateNOrmals mesh right after loading.


markcw(Posted 2005) [#4]
updatenormals *should* set normals to length of 1.
this is the standard normal-lighting length, used for
smooth-shading objects.

to get a flat-shaded cube, either use that entityfx flag
thingy, or you can write a normals routine, to set the
normal positions from the corresponding vertex
positions, or a slight scaling of (i can't remember).


WolRon(Posted 2005) [#5]
Don't you have to use 24 vertices in order to correctly get the normals to face the correct way for each face? (because you can only have 1 normal per vertex)


sswift(Posted 2005) [#6]
Blitz smooths across unwelded vertices closer than a certain threshold. This causes the shading on cubes to be wrong because the normals for all the corner vertices will point out in the same direction diagonally from the three adjacent sides. In essence it shades it like it would a sphere.

The solution is not to use the Blitz normal shading function. There is a function in the coe archives I wrote along time ago that calculates the normals in a way which does not smooth across unwelded vertices. Click my username and select code archive entries to find it.

Of course my fucntion has it's own limitations. It may not work well on spheres and cylinders which have unwelded edges where the texture wraps.

A better solution is to have a smoothing function that takes an angle and only smooths across edges which are less than that angle. I don't know if there is a function in the code archives which does that.

But the best solution is to specify all your normals yourself in the 3d pakcage when you create the models. Of course this won't work if you're building stuff with primitives in Blitz.


puki(Posted 2005) [#7]
I'm not normal.

Woof.


John Blackledge(Posted 2005) [#8]
I'm trying to write an app which will display other people's models.

This flat-shading (or lack of it) has been a constant bug-bear. (Obviously when I make my own I weld all my vertices - I'm a good boy.)

I tried your suggestion of EntityFx ent,4 but it made no difference as you can see below. Any other ideas?