Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //|/////////////////:DIAGRAM[SC[DIA_TILTEX]]:|//
- //| |//
- //| Working out logic using a 4x4 tilemap: |//
- //| |//
- //| TILE[ 0 ]: ( 0 + 0.5 ) / 4 === 0.125 |//
- //| TILE[ 1 ]: ( 1 + 0.5 ) / 4 === 0.375 |//
- //| TILE[ 2 ]: ( 2 + 0.5 ) / 4 === 0.625 |//
- //| TILE[ 3 ]: ( 3 + 0.5 ) / 4 === 0.875 |//
- //| |//
- //| |<----- 4 pixels / texels ----->| |//
- //| +---+---+---+---+---+---+---+---+ |//
- //| | | | | | |//
- //| + 0 + 1 + 2 + 3 + <<<<< |//
- //| | | | | | ^^ |//
- //| +---+---+---+---+---+---+---+---+ ^^ |//
- //| ^ ^ .25 ^ 0.5 ^ .75 ^ ^ ^^ |//
- //| | | | | | | ^^ |//
- //| | 0.125 0.375 0.625 0.875 | ^^ |//
- //| | | ^^ |//
- //| 0<--WEBGL_MAPPED_RANGE_0_TO_1-->1 ^^ |//
- //| ^^ |//
- //| [ TILE_COORDINATES >>>^^] |//
- //| (If each pixel encodes ) |//
- //| (a tile value on tilemap) |//
- //| |//
- //|/////////////////:DIAGRAM[SC[DIA_TILTEX]]:|//
- TileCoord To TexelCoord Formula:
- ( for use inside a GLSL shader)
- //: tile_coord_x: 0-indexed integer tile
- //: coordinate on x-axis.
- //: img_wid: width of image used to encode
- //: tile values. Also our texture we
- //: are sampling from.
- function TileCoord_TO_TexelCoord_X(
- tile_coord_x
- , img_wid
- ){
- return( (tile_coord_x + 0.5 ) / img_wid );
- //: Divided by "img_wid" and NOT "img_wid - 1".
- };;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement