Simple flat shading using Stage3D/AGAL

我只是一个虾纸丫 提交于 2019-12-23 01:38:29

问题


I'm relatively new to 3D development and am currently using Actionscript, Stage3D and AGAL to learn. I'm trying to create a scene with a simple procedural mesh that is flat shaded. However, I'm stuck on exactly how I should be passing surface normals to the shader for the lighting. I would really like to just use a single surface normal for each triangle and do flat, even shading for each. I know it's easy to achieve better looking lighting with normals for each vertex, but this is the look I'm after.

Since the shader normally processes every vertex, not every triangle, is it possible for me to just pass a single normal per triangle, rather than one per vertex? Is my thinking completely off here? If anyone had a working example of doing simple, flat shading I'd greatly appreciate it.


回答1:


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.



来源:https://stackoverflow.com/questions/12319822/simple-flat-shading-using-stage3d-agal

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