Game Development Community

Flat shading

by Ivan Mandzhukov · in Torque 3D Professional · 07/12/2009 (11:48 am) · 6 replies

Is flat shading exposed to the material system ?
I need a material with a single diffuse map to look somehow faceted - with sharp edges.
I want to discard the default gouraud color interpolation.

#1
07/12/2009 (11:52 am)
Create a shader that does the whole lighting basing on the face normals only.
#2
07/12/2009 (11:56 am)
Yes,that was the idea.
I take each face normal and compute the diffuse light of each face.

But i was thinking about also for something that works on the fly (for free) .. as set a render state.
#3
07/12/2009 (12:01 pm)
Oddly enough, its one of the few effects you can't do in a vertex shader, because of shared normals. It is possible to do in the pixel shader but its a pain (one way is to use the DDX/DDY, and use that to derive the face normal).

Direct3D and OpenGL have a render state that can be switched to make it easy but that is legacy really.

However the correct method really is to not share the face vertices and give each vertex attached to each face, the face normal. Then it will work with the existing light models (both simple and advanced) without any special shader or render state work.
#4
07/12/2009 (12:36 pm)
You mean to create an additional vertices (detach the surface),
without sharing them between faces ?
It sounds good.
#5
07/12/2009 (7:08 pm)
Summary: if you want flat shading, your geometry needs to be exported with flat normals. You cannot toggle that on/off in real-time in T3D without plain re-generating the normals inside the engine (which is what 3D modeling applications do).
#6
07/13/2009 (12:24 am)
Smoothing Groups FTW.