Simple flat shading using Stage3D/AGAL

我的梦境 提交于 2019-12-08 03:49:28

I'm digging up an old question here since I stumbled on it via google and can see there is no accepted answer.

Stage3D does not have an equivalent "GL_FLAT" option for it's shader engine. What this means is that the fragment shader program always receives a "varying" or interpolated value from the output of the three respective vertices (via the vertex program). If you want flat shading, you have basically only one option:

Create three unique vertices for each triangle and set the normal for each vertex to the face normal of the triangle. This way, each vertex will calculate the same lighting and result in the same vertex color. When the fragment shader interpolates, it will be interpolating three identical values, resulting in flat shading.

This is pretty lame. The requirement of unique vertices per triangle means you can't share vertices between triangles. This will definitely increase your vertex count, causing increased delays during your VertexBuffer3D uploads as well as overall lower frame rates. However, I have not seen a better solution anywhere.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!