Advertisement
CODE_TOLD_FAST

JS/NOTES/TILTEX

May 15th, 2020
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.         //|/////////////////:DIAGRAM[SC[DIA_TILTEX]]:|//
  2.         //|                                          |//
  3.         //| Working out logic using a 4x4 tilemap:   |//
  4.         //|                                          |//
  5.         //| TILE[ 0 ]: ( 0 + 0.5 ) / 4 === 0.125     |//
  6.         //| TILE[ 1 ]: ( 1 + 0.5 ) / 4 === 0.375     |//
  7.         //| TILE[ 2 ]: ( 2 + 0.5 ) / 4 === 0.625     |//
  8.         //| TILE[ 3 ]: ( 3 + 0.5 ) / 4 === 0.875     |//
  9.         //|                                          |//
  10.         //| |<----- 4 pixels / texels ----->|        |//
  11.         //| +---+---+---+---+---+---+---+---+        |//
  12.         //| |       |       |       |       |        |//
  13.         //| +   0   +   1   +   2   +   3   + <<<<<  |//
  14.         //| |       |       |       |       |    ^^  |//
  15.         //| +---+---+---+---+---+---+---+---+    ^^  |//
  16.         //| ^   ^  .25  ^  0.5  ^  .75  ^   ^    ^^  |//
  17.         //| |   |       |       |       |   |    ^^  |//
  18.         //| | 0.125   0.375   0.625   0.875 |    ^^  |//
  19.         //| |                               |    ^^  |//
  20.         //| 0<--WEBGL_MAPPED_RANGE_0_TO_1-->1    ^^  |//
  21.         //|                                      ^^  |//
  22.         //|                [ TILE_COORDINATES >>>^^] |//
  23.         //|                (If each pixel encodes  ) |//
  24.         //|                (a tile value on tilemap) |//
  25.         //|                                          |//
  26.         //|/////////////////:DIAGRAM[SC[DIA_TILTEX]]:|//
  27.  
  28.  
  29.         TileCoord To TexelCoord Formula:
  30.         ( for use inside a GLSL shader)
  31.  
  32.         //: tile_coord_x: 0-indexed integer tile
  33.         //:               coordinate on x-axis.
  34.         //: img_wid: width of image used to encode
  35.         //:          tile values. Also our texture we
  36.         //:          are sampling from.
  37.         function TileCoord_TO_TexelCoord_X(
  38.             tile_coord_x
  39.         ,   img_wid
  40.         ){
  41.               return(  (tile_coord_x + 0.5 ) / img_wid );
  42.               //: Divided by "img_wid" and NOT "img_wid - 1".
  43.         };;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement