在低级 AGAL 中编码时,是否需要为每个纹理创建一个新的 Program3D?
例如...
如果我正在开发一个需要多个纹理的应用程序(基本上是唯一的精灵),我是否需要调用 context3D.createProgram();
并组装一个新的 < code>Program3D(带有 VertexShaderAssembler
和 FragmentShaderAssembler
),用于我希望在 应用?
Program3D
通常如何在引擎中工作?是一个程序运行整个事情,还是每个纹理、模型、使用一个程序地图?
我是否正确地假设您只需要在初始化时间(Event.ADDED_TO_STAGE
)期间创建一次Program3D
,而不是在每个帧期间(Event.ENTER_FRAME)
),对吗?
For example...
If I'm developing an application that requires more than one texture in it (unique sprites, basically), do I need to call context3D.createProgram();
and assemble a new Program3D
(with a VertexShaderAssembler
and a FragmentShaderAssembler
) for each individual textures that I wish to use in the application?
How does a Program3D
work within an engine typically? Does one program run the whole thing, or does it use one program per textures, models, maps?
And am I correct to assume that you only need to create the Program3D
once during initialization time (Event.ADDED_TO_STAGE
), and not during each frames (Event.ENTER_FRAME
), right?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于一个程序(着色器),您可以拥有多个纹理。通常,您为拥有的每个着色器编写一个程序。
例如,在我的游戏中,我有一个用于地形照明、纹理和着色的着色器(程序)。我有另一个用于水的着色器(程序)。
所以程序只制作一次,但我在绘制场景之前告诉 context3d 使用哪个程序。这样它将绘制我要使用当前程序绘制的任何内容。
用法示例:
我首先绘制水,然后绘制地形,每个都使用不同的着色器。
我的 TerrainShader 有多种纹理,例如沙子、岩石和泥土纹理。着色器决定在给定时间使用哪个纹理。例如,如果顶点的高度<1。 10、然后使用沙子纹理。
因此,只需创建一次程序并在需要时使用它们。
我希望这能以正确的方式帮助您。
For one program (shader) you can have multiple textures. Usually you write a program for each shader that you have.
For example in my game I have one shader (program) for the terrain lighting, texturing and coloring. I have another shader (program) for the water.
So the programs are made once, but I tell context3d which program to use before drawing the scene. That way it will draw whatever I'm about to draw with the current program.
Example usage:
I draw the water first and then the terrain, each using a different shader.
My TerrainShader has multiple textures in, e.g. sand, rock and dirt textures. The shader decides which texture to use at given time. E.g. if the height of the vertex is < 10, then use the sand texture.
So, create the programs once and use them when needed.
I hope this helps you in the right way.
您不需要为每个纹理创建一个新的 Program3D。每当您调用drawTriangles()时,渲染器都会使用最后设置的程序。如果您需要以不同方式处理特定纹理,从而需要不同的片段着色器,那么您确实需要多个 Program3D 对象,但在极少数情况下,您需要为每个对象和纹理使用不同的着色器。
由于没有编写引擎,我无法告诉您这通常是如何完成的。我认为对于不同类别的模型、环境地图等,您会有不同的 Program3D 对象。可能每个实体都没有一个。您最多只能使用大约 4000 个 Program3D 对象。
是的,您应该提前创建并初始化您的 Program3D 对象。在渲染期间,您可以调用 Context3D.setProgram() 来指定活动程序。该程序用于渲染,直到您更改它为止。
You don't need a new Program3D for each texture. The renderer uses the last program set whenever you call drawTriangles(). If you need to treat particular textures differently such that you need a different fragment shader, then you do need more than one Program3D object, but it would be a rare case in which you would need a different shader for every object and texture.
Not having written an engine, I can't tell you how this would be done typically. I would think you would have different Program3D objects for different classes of models, environment maps, etc. Probably not one per entity. You are limited to about 4000 Program3D objects.
Yes, you should create and initialize your Program3D objects ahead of time. During rendering, you call Context3D.setProgram() to specify the active program. That program is used for rendering until you change it.