Gourad texturing

Blitz3D Forums/Blitz3D Programming/Gourad texturing

WolRon(Posted 2004) [#1]
I am converting a screensaver I wrote a while back from C++ (using DirectX) to Blitz3D. In my old code, I was able to change how the scene was rendered from Gourad shading (D3DRMRENDER_GOURAUD) to flat shading (D3DRMRENDER_UNLITFLAT) and back.

Does anyone know how I can acheive this in Blitz? Currently my entities are being drawn in what appears to be equivalent to unlit flat.


Klaas(Posted 2004) [#2]
You cannot change the whole scene but each entity with EntityFX .. Flag 4 is for flatshading


WolRon(Posted 2004) [#3]
Yes, 4 is for flatshading, but what is for *Gouraud* shading? Sorry if my question was misleading. I want to know how to acheive Gouraud shading.


RetroBooster(Posted 2004) [#4]
it's standard, just add some lights ;)


Klaas(Posted 2004) [#5]
yes, no light, no lighting ... but make sure your models got correct normals or use UpdateNormals to do so.


AntonyWells(Posted 2004) [#6]
I think blitz uses phong or blinn shading though.

Your best bet is to force vertex colors(EntityFX) again, do the lighting manually. If it's vital. But if not, as Klass said, use normal/faster lighting etc.


WolRon(Posted 2004) [#7]
Ok, I figured out that the problem was that I didn't have any normals applied to my meshes.

I tried using UpdateNormals (and that created the shading effect I wanted), BUT that averages the normals between faces. This IS an effect that I want applied to parts of my mesh but not the entire mesh. On other parts of the mesh, I want very defined edges. (It's a mesh of a gear. I want the gear teeth to be shaded so that they look smooth but I want the sides of the gears to be shaded so that they look flat.)

I found the VertexNormal command in the command set. However, it seems to be able to only set one normal per vertex. Since the sides of my gears share the same vertices with the teeth of the gears, I need two seperate normals to define the side as flat and the teeth as smooth.

Is there a way to create two (or more) normals per vertex (basically a normal for each face that shares the vertex)?

Or

Must I create seperate vertices (that are in the exact same positions as the other vertices) so that I can seperately set normals for those vertices?

Or

Must I create an entirely different surface with different vertices? (I've heard you should try to keep surfaces to a minimum though).


jhocking(Posted 2004) [#8]
"I think blitz uses phong or blinn shading though."

I think you have Blitz confused with the scanline renderer in 3D Studio Max.


AntonyWells(Posted 2004) [#9]
No I think you do.

Have you ever coded a 3D engine? Well, in GL you to explicity set the light shading model.

Of which those two are an option unless I'm suffering brain damage. And since they are obviously hardware accelerated options on modern cards, it stands to reason DX will offer similar model options.


WolRon(Posted 2004) [#10]
No I think you do.

Huh?

"No I think you do" WHAT?

I asked three different questions.

Of which those two are an option unless I'm suffering brain damage. And since they are obviously hardware accelerated options on modern cards, it stands to reason DX will offer similar model options.
What is this in reference to?


jhocking(Posted 2004) [#11]
He was responding to me ie. the post directly above his.


WolRon(Posted 2004) [#12]
Oh, I see. I have heard of Phong before and I know nothing about OpenGL, so it must have been in reference to DirectX...

Anyways, back to the questions I asked above!


DJWoodgate(Posted 2004) [#13]
I think you have to create separate vertices. But I think it's also the case that the blitz's updatenormals function will still smooth them so you will have to create your own normals, or more likely write your own routine to generate normals which does not do this, which should not be that hard, though it's not quite so trivial that I have got around to doing it yet.:) Actually I thought SSwift came up with something of the sort, but I can't see it in the code archives, so maybe I am imagining it.

Oh and I am pretty sure blitz does not do phong as that implies calculating the lighting at every pixel across the triangle which means generating a new normal for every pixel based on the averaged triangle normals which is too slow. Blitz does do Dot3 blending though which is similar in principle and as the normals are pregenerated it's a lot quicker. I believe true phong can now be done in hardware by using pixel shaders but thats post DX7 which is blitz's current high watermark so as to achieve maximum compatibility across a wide range of hardware.


big10p(Posted 2004) [#14]
WolRon,

You can only have 1 normal per vertex. Also, blitz meshes dont have surface normals (which you need to do proper flat shading). Instead, when flat shading, blitz seems to take the first vertex normal of each triangle and use that as the surface normal, but since this normal is unlikely to be perpendicular to the tri, results of flat shading in blitz can be poor.

The only way I know of getting round this is to unweld all the tris so no vertices are shared, and set the normals to be perpendicular. There is a function for calculating this in the archives somewhere.


DJWoodgate(Posted 2004) [#15]
I see Sswift has just added his modified updatenormals routine to the code archive, good chap that he is, so my memory was not playing tricks on me.

http://www.blitzbasic.co.nz/codearcs/codearcs.php?code=975