使用 Stage3D/AGAL 的简单平面着色 [英] Simple flat shading using Stage3D/AGAL

查看:20
本文介绍了使用 Stage3D/AGAL 的简单平面着色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 3D 开发比较陌生,目前正在使用 Actionscript、Stage3D 和 AGAL 进行学习.我正在尝试使用一个简单的程序网格创建一个平面阴影的场景.但是,我一直坚持到底应该如何将表面法线传递给着色器以进行照明.我真的很想为每个三角形使用一个单一的表面法线,并为每个三角形做平面,甚至阴影.我知道使用每个顶点的法线来实现更好看的照明很容易,但这就是我所追求的外观.

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.

推荐答案

我在这里挖掘了一个老问题,因为我是通过谷歌偶然发现的,可以看到没有被接受的答案.

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

Stage3D 的着色器引擎没有等效的GL_FLAT"选项.这意味着片段着色器程序始终从三个相应顶点的输出(通过顶点程序)接收变化"或内插值.如果你想要平面着色,你基本上只有一种选择:

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.

这太蹩脚了.每个三角形的唯一顶点的要求意味着您不能在三角形之间共享顶点.这肯定会增加您的顶点数,导致 VertexBuffer3D 上传期间的延迟增加以及整体帧速率降低.但是,我在任何地方都没有看到更好的解决方案.

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.

这篇关于使用 Stage3D/AGAL 的简单平面着色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆