什么样的 2D 游戏着色器(即超级马里奥) [英] What kind of shader for 2D games (ie. Super Mario)
问题描述
我一直在尝试弄清楚如何将 OpenGL ES 2.0 用于 2D.到目前为止,我认为我可以处理大多数事情.但我还没有想出的一件事是着色器要做什么?
I've been trying to figure out how to use OpenGL ES 2.0 for 2D. So far I think I have a handle on most things. But the one thing that I haven't figured out is what to do for the shaders?
我知道您在着色器中设置了相机/视图和灯光,但我不想要阴影或任何类型的照明迹象.基本上我只想在屏幕上移动精灵,让精灵看起来和我在 Photoshop 中绘制它们时完全一样.
I understand that you set up the camera/view and the lights in the shader, but I don't want shadows or any kind of sign of lighting. Basically I just want to move sprites around the screen and have the sprites look exactly like they did when I drew them in photoshop.
有没有人有一个可以做到这一点的着色器的例子?或者可能是一篇讨论这个的文章?
Anyone have an example of a shader that would do this? Or maybe an article that talks about this?
我已经发现,在尝试制作纯 2D 程序时,OpenGL 中存在大量 3d 开销,但显然这是 Android 上唯一可行的选择.
I already find that there's a lot of 3d overhead in OpenGL when trying to make a purely 2D program, but apparently it's the only viable option on Android.
推荐答案
我制作了一个 2D 视频游戏,这些是我使用的着色器.两个非常简单的着色器.这是你要的吗?
I made a 2D videogame and these are the shaders I used. Two very simple shaders. Is this what you asking for?
**VERTEX_SHADER_2D =**
attribute vec4 position;
attribute vec2 textureCoordIn;
varying vec2 vTextureCoordOut;
uniform mediump mat4 modelViewMatrix;
void main()
{
gl_Position = modelViewMatrix * position;
vTextureCoordOut = textureCoordIn;
}
**FRAGMENT_SHADER_2D =**
varying mediump vec2 vTextureCoordOut;
uniform sampler2D sampler;
void main()
{
gl_FragColor = texture2D(sampler, vTextureCoordOut);
}
这篇关于什么样的 2D 游戏着色器(即超级马里奥)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!