Advertisement
DEKTEN

SDF_019_COMMON

Dec 3rd, 2020
744
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //[ THIS_FILE_IS[ SDF_019.COMMON._ ]                 ]//
  2. /** ************************************************ ***
  3. ***                                                  ***
  4. ***     Live Stream Of Me Working On This Code:      ***
  5. ***                                                  ***
  6. *** ************************************************ ***
  7.  
  8.                 twitch.com/kanjicoder    
  9.  
  10. *** ************************************************ ***
  11. ***                                                  ***
  12. *** LIVE__________DEMO:  tinyurl.com/SDF-019-DEMO    ***
  13. *** SETUP________VIDEO:  tinyurl.com/SDF-019-SETUP   ***
  14. ***                                                  ***
  15. ***      SELF______URL:  tinyurl.com/SDF-019-COMMON  ***
  16. ***      DOCUMENTATION:  tinyurl.com/SDF-019         ***
  17. ***      SOURCE_COMMON:  tinyurl.com/SDF-019-COMMON  ***
  18. ***      SOURCE_BUFFER:  tinyurl.com/SDF-019-BUFFER  ***
  19. ***      SOURCE__IMAGE:  tinyurl.com/SDF-019-IMAGE   ***
  20. ***                                                  ***
  21. *** ************************************************ **/
  22. //:INSTRUCTIONS:IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII://
  23. /** ************************************************ ***
  24.  
  25.     Click And Drag on the canvas to set pixels.
  26.  
  27. *** ************************************************ **/
  28. //:IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII:INSTRUCTIONS://
  29. //:MACROS:MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM://
  30.  
  31.     #define IV2 ivec2
  32.     #define IV3 ivec3
  33.     #define V_4  vec4
  34.     #define V_3  vec3
  35.     #define V_2  vec2
  36.     #define F32 float
  37.     #define I32   int
  38.     #define U32  uint
  39.  
  40. //:MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM:MACROS://
  41. //:DATA:DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD://
  42.  
  43.  
  44. //:DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD:DATA://
  45. //:FUNC:FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF://
  46. //:TILE_DATA_LAYOUT:=================================://
  47.  
  48. IV3 v3d_CTO_xyc_256( IV3 v3d     ){
  49.  
  50.     IV3 xyc_256; /**return:value**/
  51.  
  52.     I32 v_x = v3d.x;
  53.     I32 v_y = v3d.y;
  54.     I32 v_z = v3d.z;
  55.  
  56.     //[  CODED_WHILE_LOOKING_AT[ #TILE_DATA_LAYOUT#  ]//
  57.  
  58.     //+@SIXTEEN_FLOORS_OF_EACH_COLOR@+//
  59.     I32 csC = int(trunc( F32(v_z) / 16.0 ));
  60.     I32 csF =( csC * I32(16) );
  61.     I32 csL = v_z - ( csF );
  62.  
  63.     //+@EACH_FLOOR_IS_64_BY_64@+//
  64.     //+@16_64X64_FLOORS_ON_4X4_GRID@+//
  65.     I32 csY = int(trunc( F32(csL) /        4.0 ));
  66.     I32 csX =                csL - ( csY *(4)   );
  67.  
  68.     I32 coX = csX * I32(64);
  69.     I32 coY = csY * I32(64);
  70.  
  71.     I32 p_x = coX + v_x; //: p_x = [ 0 -to- (256-1) ]
  72.     I32 p_y = coY + v_y; //: p_y = [ 0 -to- (256-1) ]
  73.  
  74.     xyc_256=IV3( p_x , p_y, csC );
  75.     return( xyc_256 );
  76.  
  77. } IV3 v_i_512_CTO_v3d( I32 v_i_512 ){
  78.  
  79.     IV3 v3d; /** return:value **/
  80.  
  81.     //:#WHY_VOB_DEX#://
  82.     //[  CODED_WHILE_LOOKING_AT[ #TILE_DATA_LAYOUT#  ]//
  83.  
  84.     //:Map onto conceptual 512x512 bitmap, D01.
  85.     I32 p_y_512 = int(trunc( F32( v_i_512 ) / 512.0 ));
  86.     I32 p_x_512 = v_i_512 - ( p_y_512 * I32(512) );
  87.  
  88.     //:What color floors are you on?
  89.     //:Find Cell Color Quadrant (csC):
  90.     I32 cqX = int(trunc( F32(p_x_512) / 256.0 ));
  91.     I32 cqY = int(trunc( F32(p_y_512) / 256.0 ));
  92.  
  93.     //: True, but not needed here.
  94.     //: I32 csC = (cqY << 1 ) | ( cqX << 0 );
  95.     //: I32 csF = ( csC * I32( 16 ) );
  96.  
  97.     //:Map conceptual 512x512 XY to actual 256x256 XY.
  98.     I32 p_x_256 = p_x_512 - ( cqX * 256 );
  99.     I32 p_y_256 = p_y_512 - ( cqY * 256 );
  100.  
  101.     //:Get 2D representation of your colored floors:
  102.     I32 csX = int(trunc( F32(p_x_256) / 64.0 ) );
  103.     I32 csY = int(trunc( F32(p_y_256) / 64.0 ) );
  104.  
  105.     //: [v_x,v_y] is local coord inside [csX,csY] cell.
  106.     I32 v_x = p_x_256 - ( csX * I32(64) );
  107.     I32 v_y = p_y_256 - ( csY * I32(64) );
  108.  
  109.     //: v_z is the INDEX value of [csX,csY]:
  110.     I32 v_z = ( csY * I32(4) ) + csX;
  111.  
  112.     v3d = IV3( v_x , v_y , v_z );
  113.     return( v3d );
  114.  
  115. }   U32 v3d_sam_CTO_vob( IV3 v3d , sampler2D sam ){
  116.  
  117.     U32 vob ; /**return:value**/
  118.  
  119.     IV3 xyc_256 = v3d_CTO_xyc_256( v3d );
  120.  
  121.     I32 p_x = xyc_256.x;
  122.     I32 p_y = xyc_256.y;
  123.     I32 csC = xyc_256.z;
  124.  
  125.     /** sam == iChannel0 in shadertoy. **/
  126.     V_4 c4d = texelFetch( sam,ivec2(p_x,p_y),0);
  127.  
  128.     vob = U32(  c4d[ csC ] * 255.0 );
  129.  
  130. //  if( U32( 0 ) == csC /** RED_BYTE **/ ){
  131. //
  132. //      vob = U32(  c4d.x * 255.0 );
  133. //
  134. //  }else
  135. //  if( U32( 1 ) == csC /** RED_BYTE **/ ){
  136. //
  137. //      vob = U32(  c4d.y * 255.0 );
  138. //
  139. //  }else
  140. //  if( U32( 2 ) == csC /** RED_BYTE **/ ){
  141. //
  142. //      vob = U32(  c4d.z * 255.0 );
  143. //
  144. //  }else
  145. //  if( U32( 3 ) == csC /** RED_BYTE **/ ){
  146. //
  147. //      vob = U32(  c4d.w * 255.0 );
  148. //
  149. //  }else{
  150. //      /** THIS IS AN ERROR **/
  151. //  };;
  152.    
  153.     return( vob );
  154.  
  155. } U32 v_i_512_sam_CTO_vob(I32 v_i_512 , sampler2D sam){
  156.  
  157.     U32 vob; /**return:value**/
  158.  
  159.     IV3 v3d = v_i_512_CTO_v3d( v_i_512 );
  160.      
  161.     vob = v3d_sam_CTO_vob( v3d , sam) ;
  162.     return( vob );
  163.  
  164. } //:===============================:TILE_DATA_LAYOUT://
  165. //:FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF:FUNC://
  166. //:MACROS:MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM://
  167.  
  168.     #undef  IV2  
  169.     #undef  IV3  
  170.     #undef  V_4  
  171.     #undef  V_3  
  172.     #undef  V_2  
  173.     #undef  F32  
  174.     #undef  I32  
  175.     #undef  U32  
  176.  
  177. //:MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM:MACROS://
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement