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

查看:219
本文介绍了使用的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.

由于着色器正常处理每个顶点,不是每一个三角形,是有可能对我来说,只是传递一个正常的每个三角形,而不是每个顶点吗?我想彻底断吗?如果任何人有做一些简单的,平面着色我会非常的工作示例AP preciate吧。

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:

为每个三角形的三个独特的顶点,并设置正常   每个顶点在脸上正常的三角形。这种方式,每个顶点   将计算相同的照明,并导致在同一个顶点颜色。   当片段着色器内插,将内插3   相同的值,从而产生平坦的阴影

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.

这是pretty的跛脚。每个三角形的顶点独特的要求意味着你不能三角形之间共享顶点。这肯定会增加你的顶点数量,在你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天全站免登陆