What kind of shader for 2D games (ie. Super Mario)

空扰寡人 提交于 2019-12-13 00:18:05

问题


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?

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?

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.


回答1:


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);
      }


来源:https://stackoverflow.com/questions/9714443/what-kind-of-shader-for-2d-games-ie-super-mario

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