A 2D tile-based sandbox game.
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #include "shaders.h"
  2. namespace Cygnet::Shaders {
  3. const char *spriteVx = R"glsl(
  4. uniform mat3 camera;
  5. uniform mat3 transform;
  6. uniform vec3 frameInfo; // frame height, frame count, frame index
  7. attribute vec2 vertex;
  8. varying vec2 v_texCoord;
  9. void main() {
  10. v_texCoord = vec2(
  11. vertex.x,
  12. (frameInfo.x * frameInfo.z + (frameInfo.x * vertex.y)) /
  13. (frameInfo.x * frameInfo.y));
  14. vec3 pos = camera * transform * vec3(vertex, 1);
  15. gl_Position = vec4(pos.xy, 0, 1);
  16. }
  17. )glsl";
  18. const char *spriteFr = R"glsl(
  19. precision mediump float;
  20. varying vec2 v_texCoord;
  21. uniform sampler2D tex;
  22. void main() {
  23. gl_FragColor = texture2D(tex, v_texCoord);
  24. }
  25. )glsl";
  26. const char *chunkVx = R"glsl(
  27. uniform mat3 camera;
  28. uniform vec2 pos;
  29. attribute vec2 vertex;
  30. varying vec2 v_tileCoord;
  31. void main() {
  32. vec3 pos = camera * vec3(pos + vertex, 1);
  33. gl_Position = vec4(pos.xy, 0, 1);
  34. v_tileCoord = vec2(vertex.x, vertex.y);
  35. }
  36. )glsl";
  37. const char *chunkFr = R"glsl(
  38. precision mediump float;
  39. #define TILE_SIZE 32.0
  40. #define CHUNK_WIDTH 64
  41. #define CHUNK_HEIGHT 64
  42. varying vec2 v_tileCoord;
  43. uniform sampler2D tileAtlas;
  44. uniform vec2 tileAtlasSize;
  45. uniform sampler2D tiles;
  46. void main() {
  47. vec2 tilePos = floor(vec2(v_tileCoord.x, v_tileCoord.y));
  48. vec4 tileColor = texture2D(tiles, tilePos / vec2(CHUNK_WIDTH, CHUNK_HEIGHT));
  49. float tileID = floor((tileColor.r * 256.0 + tileColor.a) * 256.0);
  50. vec2 atlasPos = vec2(
  51. tileID + v_tileCoord.x - tilePos.x,
  52. floor(tileID / tileAtlasSize.x) + v_tileCoord.y - tilePos.y);
  53. gl_FragColor = texture2D(tileAtlas, fract(atlasPos / tileAtlasSize));
  54. }
  55. )glsl";
  56. }