Advertisement
DEKTEN

SDF_017

Dec 1st, 2020
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 114.68 KB | None | 0 0
  1. /** ************************************************ ***
  2. *** ***
  3. *** Live Stream Of Me Working On This Code: ***
  4. *** ***
  5. *** ************************************************ ***
  6.  
  7. twitch.com/kanjicoder
  8.  
  9. *** ************************************************ ***
  10. *** ***
  11. *** EASY___SOURCE: tinyurl.com/SDF-017 ***
  12. *** DIRECT_SOURCE: pastebin.com/******** ***
  13. *** ***
  14. *** EASY_____DEMO: tinyurl.com/SDF-017-DEMO ***
  15. *** DIRECT___DEMO: shadertoy.com/view/****** ***
  16. *** ***
  17. *** About: Voxel Engine Work. ***
  18. *** ***
  19. *** AGENDA: ***
  20. *** Lets figure out how to merge 3 bitmaps ***
  21. *** together to create booleaned 3D pixel ***
  22. *** geometry for different voxel types. ***
  23. *** (Did not finish this in SDF_016) ***
  24. *** ***
  25. *** ************************************************ **/
  26. //:MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM://
  27. /** M: Macros Section **/
  28.  
  29. #define V_4 vec4
  30. #define V_3 vec3
  31. #define V_2 vec2
  32. #define F32 float
  33. #define I32 int
  34. #define U32 uint
  35.  
  36. /** M: Macros Section **/
  37. //:MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM://
  38. //:DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD://
  39. /** D: Data Section **/
  40.  
  41. //:DEBUGGING:====================================://
  42.  
  43. #define SDF_DEBUG_MODE_ON ( 1 )
  44.  
  45. V_4 THE_COLOR_OF_EMPTY_SPACE=V_4(
  46. 0.0 , 0.0 , 0.0 , 1.0
  47. /** RED GRE BLU ALP **/
  48. );
  49.  
  50. //:====================================:DEBUGGING://
  51. //:CONFIGURATION:================================://
  52. //:FUN_STUFF:--------------------------------://
  53.  
  54. #define ANIMATE_THE_CORES ( 1 )
  55.  
  56. //:--------------------------------:FUN_STUFF://
  57. //:PROJECTION_GEOMETRY_SETTINGS:-------------://
  58.  
  59. /** The total number of projection **/
  60. /** bitmaps used to create subvoxel **/
  61. /** geometry. 0 is currently not used **/
  62. /** because that will be the "emptyspace"**/
  63. /** tile, thus "SDF_PRO_MAX" can be **/
  64. /** seen as a "maximum inclusive index" **/
  65.  
  66. /** If: 0 < TILE_VALUE <= SDF_PRO_MAX **/
  67. /** THEN: Will render boolean geometry **/
  68. /** for tiles of that value. **/
  69.  
  70. #define SDF_PRO_MAX ( 3 )
  71.  
  72. #define SDF_PRO_TYP_SUB ( 707 )
  73. #define SDF_PRO_TYP_ADD ( 808 )
  74. #define SDF_PRO_TYP_GEO ( 909 )/**LITERAL**/
  75.  
  76. //:-------------:PROJECTION_GEOMETRY_SETTINGS://
  77. //:CAMERA_SETTINGS:--------------------------://
  78. /** **************************************** ***
  79. PREFIX:
  80.  
  81. OGP: OrthoGraphicProjection
  82. P3D: Perspective_3D
  83. T3O: TUBE360_OUT (TubeCam Looking OUTWARD)
  84. T3I: TUBE360_INN (TubeCam Looking INWARD )
  85.  
  86. POSTFIX: (SUFFIX ):
  87. TOP: Top View
  88. 34D: 3/4 Tilted DOWN view.
  89. AAZ: Around_Axis_Z (NOT:WAZ)
  90.  
  91. NOTES:
  92.  
  93. T3O : commonly known as PANORAMIC 360
  94. TubeCam: Revolve Around Axis As Camera.
  95. Literally "Tube Camera"
  96.  
  97. *** **************************************** **/
  98.  
  99. #define OGP_TOP ( 1 ) /** Good For Debug **/
  100. #define OGP_34D ( 2 ) /** PATENT_DRAWING **/
  101. #define T3O_AAZ ( 3 ) /** Outward: Z-Axis**/
  102. #define T3I_AAZ ( 4 ) /** Inward : Z-Axis**/
  103. #define S3I_AAZ ( 5 ) /** SPHERE:INN:AAZ **/
  104.  
  105. /** Selected Camera Type **/
  106. // #define CAMTYPE ( OGP_34D )
  107. // #define CAMTYPE ( OGP_TOP )
  108. // #define CAMTYPE ( T3I_AAZ )
  109. #define CAMTYPE ( S3I_AAZ )
  110.  
  111. //:--------------------------:CAMERA_SETTINGS://
  112.  
  113. /** SLICE_RENDER_USING_CAMERA_PLANE **/
  114. int CFG_SLICE_RENDER=( 0 );
  115.  
  116. //:================================:CONFIGURATION://
  117. //:RAYMARCHING_AND_VOXEL_CONSTANTS:==============://
  118.  
  119. //:These defines are for ray marching when using
  120. //:fragment coordinates as our coordinate space.
  121. #define MAX_STE 1000 //:Max Step
  122. #define MIN_DIS 0.02 //:Min Dist (SurfaceDist)
  123. #define MAX_DIS (64.0*16.0 * 1.0) //:Max Dist
  124.  
  125. //:Number of tiles on each axis:
  126. #define TILEMAP_PRESET ( 847 )
  127. #if( 847 == TILEMAP_PRESET ) /** 8 x 4 x 7 **/
  128.  
  129. #define NTX 8 //: Number Of [tiles/voxels]
  130. #define NTY 4 //: Number Of [tiles/voxels]
  131. #define NTZ 7 //: Number Of [tiles/voxels]
  132.  
  133. #endif
  134. #if( 111 == TILEMAP_PRESET )
  135.  
  136. #define NTX 1 //: Number Of [tiles/voxels]
  137. #define NTY 1 //: Number Of [tiles/voxels]
  138. #define NTZ 1 //: Number Of [tiles/voxels]
  139.  
  140. #endif
  141. #if( 222 == TILEMAP_PRESET )
  142.  
  143. #define NTX 2 //: Number Of [tiles/voxels]
  144. #define NTY 2 //: Number Of [tiles/voxels]
  145. #define NTZ 2 //: Number Of [tiles/voxels]
  146.  
  147. #endif
  148. #if( 333 == TILEMAP_PRESET )
  149.  
  150. #define NTX 3 //: Number Of [tiles/voxels]
  151. #define NTY 3 //: Number Of [tiles/voxels]
  152. #define NTZ 3 //: Number Of [tiles/voxels]
  153.  
  154. #endif
  155.  
  156. #define VOXEL_SIZE_PRESET ( 161616 )
  157. #if( 161616 == VOXEL_SIZE_PRESET )
  158.  
  159. //:Size_Of_A_Voxel_Tile_Measured_In_Pixels:
  160. #define NPX 16 //: NPX : Num_Pixels_X
  161. #define NPY 16 //: NPY : Num_Pixels_Y
  162. #define NPZ 16 //: NPZ : Num_Pixels_Z
  163.  
  164. #endif
  165. #if( 555 == VOXEL_SIZE_PRESET )
  166.  
  167. //:Size_Of_A_Voxel_Tile_Measured_In_Pixels:
  168. #define NPX 5 //: NPX : Num_Pixels_X
  169. #define NPY 5 //: NPY : Num_Pixels_Y
  170. #define NPZ 5 //: NPZ : Num_Pixels_Z
  171.  
  172. #endif
  173. #if( 567 == VOXEL_SIZE_PRESET )
  174.  
  175. //:Size_Of_A_Voxel_Tile_Measured_In_Pixels:
  176. #define NPX 5 //: NPX : Num_Pixels_X
  177. #define NPY 6 //: NPY : Num_Pixels_Y
  178. #define NPZ 7 //: NPZ : Num_Pixels_Z
  179.  
  180. #endif
  181. #if( 579 == VOXEL_SIZE_PRESET )
  182.  
  183. //:Size_Of_A_Voxel_Tile_Measured_In_Pixels:
  184. #define NPX 5 //: NPX : Num_Pixels_X
  185. #define NPY 7 //: NPY : Num_Pixels_Y
  186. #define NPZ 9 //: NPZ : Num_Pixels_Z
  187.  
  188. #endif
  189. #if( 51015 == VOXEL_SIZE_PRESET )
  190.  
  191. //:Size_Of_A_Voxel_Tile_Measured_In_Pixels:
  192. #define NPX 5 //: NPX : Num_Pixels_X
  193. #define NPY 10 //: NPY : Num_Pixels_Y
  194. #define NPZ 15 //: NPZ : Num_Pixels_Z
  195.  
  196. #endif
  197.  
  198. //:Total__number_of__Pixels__in_entire_voxel_map
  199. #define TPX ( NTX * NPX ) //: Total_Pixels_X
  200. #define TPY ( NTY * NPY ) //: Total_Pixels_Y
  201. #define TPZ ( NTZ * NPZ ) //: Total_Pixels_Z
  202.  
  203. //: - ://
  204. #define _ U32( 0 )
  205. #define X U32( 1 )
  206. #define R U32( 0xFF0000ff ) //: PRIMARY
  207. #define r U32( 0x880000ff ) //: PRIMARY
  208. #define G U32( 0x00FF00ff ) //: PRIMARY
  209. #define g U32( 0x008800ff ) //: PRIMARY
  210. #define B U32( 0x0000FFff ) //: PRIMARY
  211. #define b U32( 0x000088ff ) //: PRIMARY
  212. //: - ://
  213. #define C U32( 0x00FFFFff ) //: SECONDARY
  214. #define c U32( 0x008888ff ) //: SECONDARY
  215. #define M U32( 0xFF00FFff ) //: SECONDARY
  216. #define m U32( 0x880088ff ) //: SECONDARY
  217. #define Y U32( 0xFFFF00ff ) //: SECONDARY
  218. #define y U32( 0x888800ff ) //: SECONDARY
  219. //: - ://
  220. #define L U32( 0x88FF00ff ) //: TERTIARY
  221. #define l U32( 0x448800ff ) //: TERTIARY
  222. #define O U32( 0xFF8800ff ) //: TERTIARY
  223. #define o U32( 0x884400ff ) //: TERTIARY
  224. //: - ://
  225. #define K U32( 0x212121ff ) //: BLACK | GRAY
  226. #define k U32( 0x323232ff ) //: BLACK | GRAY
  227. //: - ://
  228.  
  229. #if( 1 == NTX && 1 == NTY && 1 == NTZ )
  230.  
  231. U32
  232. VAT[ NTX * NTY * NTZ ]= U32[ 1 * 1 * 1 ](
  233.  
  234. C /** <<<< JUST ONE TILE(VOXEL) **/
  235.  
  236. );
  237.  
  238. #endif
  239. #if( 2 == NTX && 2 == NTY && 2 == NTZ )
  240.  
  241. U32
  242. VAT[ NTX * NTY * NTZ ]= U32[ 2 * 2 * 2 ](
  243.  
  244. C,M,
  245. Y,_,
  246.  
  247. c,m,
  248. y,_ //:<---NO_COMMA_LAST
  249.  
  250. );
  251.  
  252. #endif
  253. #if( 333 == TILEMAP_PRESET )
  254. #if( 3 == NTX && 3 == NTY && 3 == NTZ )
  255.  
  256. U32
  257. VAT[ NTX * NTY * NTZ ]= U32[ 3 * 3 * 3 ](
  258.  
  259. /** Something about the bounding **/
  260. /** calculations is definitely off **/
  261.  
  262. R,R,R, //: <<< PROBLEM HERE
  263. R,_,R,
  264. R,R,R, //: <<< LOOKS GOOD
  265.  
  266. G,_,G,
  267. _,_,_,
  268. G,_,G,
  269.  
  270. B,B,B,
  271. B,_,B,
  272. B,B,B
  273.  
  274. );
  275.  
  276. #endif
  277. #endif
  278. #if( 847 == TILEMAP_PRESET )
  279. #if( 8 == NTX && 4 == NTY && 7 == NTZ )
  280.  
  281. U32
  282. VAT[ NTX * NTY * NTZ ]= U32[ 8 * 4 * 7 ](
  283.  
  284. /** TODO: Eventually use an integer **/
  285. /** texture for this tilemap data. **/
  286.  
  287. /** #STRATA_OF_2D_TILEMAPS# * * * **/
  288. /** #BACK_SLASH_COMMENT_FUCKERY# * * * **/
  289.  
  290. //: 1 2 3 4 5 6 7 8
  291. C,_,C,_,C,_,C,_, //: 1 ---+
  292. _,C,_,C,_,C,_,C, //: 2 |__ Z == 0
  293. C,_,C,_,C,_,C,_, //: 3 |
  294. _,C,_,C,_,C,_,C, //: 4 ---+
  295. //: 1 2 3 4 5 6 7 8
  296. _,M,_,M,_,M,_,M, //: 1 ---+
  297. M,_,M,_,M,_,M,_, //: 2 |__ Z == 1
  298. _,M,_,M,_,M,_,M, //: 3 |
  299. M,_,M,_,M,_,M,_, //: 4 ---+
  300. //: 1 2 3 4 5 6 7 8
  301. Y,_,Y,_,Y,_,Y,_, //: 1 ---+
  302. _,Y,_,Y,_,Y,_,Y, //: 2 |__ Z == 2
  303. Y,_,Y,_,Y,_,Y,_, //: 3 |
  304. _,Y,_,Y,_,Y,_,Y, //: 4 ---+
  305. //: 1 2 3 4 5 6 7 8
  306. O,_,O,_,O,_,O,_, //: 1 ---+
  307. _,O,_,O,_,O,_,O, //: 2 |__ Z == 3
  308. O,_,O,_,O,_,O,_, //: 3 |
  309. _,O,_,O,_,O,_,O, //: 4 ---+
  310. //: 1 2 3 4 5 6 7 8
  311. _,L,_,L,_,L,_,L, //: 1 ---+
  312. L,_,L,_,L,_,L,_, //: 2 |__ Z == 4
  313. _,L,_,L,_,L,_,L, //: 3 |
  314. L,_,L,_,L,_,L,_, //: 4 ---+
  315. //: 1 2 3 4 5 6 7 8
  316. R,_,R,_,R,_,R,_, //: 1 ---+
  317. _,R,_,R,_,R,_,R, //: 2 |__ Z == 5
  318. R,_,R,_,R,_,R,_, //: 3 |
  319. _,R,_,R,_,R,_,R, //: 4 ---+
  320. //: 1 2 3 4 5 6 7 8
  321. _,G,_,G,_,G,_,G,
  322. G,_,G,_,G,_,G,_,
  323. _,G,_,G,_,G,_,G,
  324. G,_,G,_,G,_,G,_ //:<<< NO_COMMA_ON_LAST
  325.  
  326. );
  327.  
  328.  
  329. #endif /** [ 8 x 4 x 7 ] **/
  330. #endif /** 847 **/
  331.  
  332. //: - ://
  333. #undef _
  334. #undef X
  335. #undef R
  336. #undef r
  337. #undef G
  338. #undef g
  339. #undef B
  340. #undef b
  341. //: -undef
  342. #undef C
  343. #undef c
  344. #undef M
  345. #undef m
  346. #undef Y
  347. #undef y
  348. //: -undef
  349. #undef L
  350. #undef l
  351. #undef O
  352. #undef o
  353. //: -undef
  354. #undef K
  355. #undef k
  356. //: - ://
  357.  
  358. //:==============:RAYMARCHING_AND_VOXEL_CONSTANTS://
  359. //:VOXEL_PROJECTION_GEOMETRY:====================://
  360. #define _ U32( 0 )
  361. #define X U32( 1 )
  362.  
  363. /** #SDF_PRO_MAX# , is calculated by * * **/
  364. /** counting the number of SDF_PRO_### * * **/
  365. /** tilemaps in this section of code. * * **/
  366.  
  367. #define SDF_PRO_001_TYP ( SDF_PRO_TYP_SUB )
  368. U32 SDF_PRO_001[ 8 * 8 ]= U32[ 8 * 8 ](
  369. /** **************************************** ***
  370.  
  371. When applied addatively as projection
  372. into empty space, creates a cubic shell.
  373.  
  374. When bits are INVERTED and applied
  375. as a subtractive volume on a filled
  376. voxel, creates a 3D tesseract shape.
  377.  
  378. *** **************************************** **/
  379. //: 1|2|3|4|5|6|7|8
  380. X,X,X,X,X,X,X,X,//: 1 ://
  381. X,_,_,_,_,_,_,X,//: 2 ://
  382. X,_,_,_,_,_,_,X,//: 3 ://
  383. X,_,_,_,_,_,_,X,//: 4 ://
  384. X,_,_,_,_,_,_,X,//: 5 ://
  385. X,_,_,_,_,_,_,X,//: 6 ://
  386. X,_,_,_,_,_,_,X,//: 7 ://
  387. X,X,X,X,X,X,X,X //: 8 : <--NO_COMMA_LAST
  388. );
  389.  
  390. #define SDF_PRO_002_TYP ( SDF_PRO_TYP_ADD )
  391. U32 SDF_PRO_002[ 8 * 8 ]= U32[ 8 * 8 ](
  392. /** **************************************** ***
  393. ADDATIVE ======> Small Cube In Voxel Cell.
  394. SUBTRACTIVE ===> Very Thick Shelled Shape.
  395.  
  396. *** **************************************** **/
  397.  
  398. //: 1|2|3|4|5|6|7|8
  399. _,_,_,_,_,_,_,_,//: 1 ://
  400. _,_,_,_,_,_,_,_,//: 2 ://
  401. _,_,_,_,_,_,_,_,//: 3 ://
  402. _,_,_,X,X,_,_,_,//: 4 ://
  403. _,_,_,X,X,_,_,_,//: 5 ://
  404. _,_,_,_,_,_,_,_,//: 6 ://
  405. _,_,_,_,_,_,_,_,//: 7 ://
  406. _,_,_,_,_,_,_,_ //: 8 : <--NO_COMMA_LAST
  407. );
  408.  
  409. #define SDF_PRO_003_TYP ( SDF_PRO_TYP_GEO )
  410. U32 SDF_PRO_003[ 3*3*3 ]= U32[ 3*3*3 ](
  411. /** **************************************** ***
  412. ADDATIVE ======> Small Cube In Voxel Cell.
  413. SUBTRACTIVE ===> Very Thick Shelled Shape.
  414.  
  415. *** **************************************** **/
  416.  
  417. //: 1|2|3|
  418. _,_,_, //: --+
  419. _,X,_, //: +--0
  420. _,_,_, //: --+
  421.  
  422. _,X,_, //: --+
  423. X,X,X, //: +--1
  424. _,X,_, //: --+
  425.  
  426. _,_,_, //: --+
  427. _,X,_, //: +--2
  428. _,_,_ //: --+
  429. );
  430.  
  431.  
  432. #undef _
  433. #undef X
  434. //:====================:VOXEL_PROJECTION_GEOMETRY://
  435. //:STRUCTS:======================================://
  436.  
  437. //:RWC_AND_RWN:------------------------------://
  438.  
  439. struct RWC_AND_RWN{
  440. V_3 rwC ;
  441. V_3 rwN;
  442. };
  443.  
  444. //:------------------------------:RWC_AND_RWN://
  445. //:VOX_000:----------------------------------://
  446.  
  447. /** VOC: VOxel_Current(information) **/
  448. struct VOC{
  449. U32 has ; // voxel:exists? : 1 :
  450. U32 val ; // voxel:tile_value : 2 :
  451. // :---:
  452. I32 til_d3d; // voxel:1d_index : 3 :
  453. I32 t_x ; // voxel:tile_x : 4 :
  454. I32 t_y ; // voxel:tile_y : 5 :
  455. I32 t_z ; // voxel:tile_z : 6 :
  456. //
  457. I32 pix_d3d; // voxel:pixel_d : 7 :
  458. I32 p_x; // voxel:pixel_x : 8 :
  459. I32 p_y; // voxel:pixel_y : 9 :
  460. I32 p_z; // voxel:pixel_z :10 :
  461. };
  462.  
  463. /** VOD: VOxel_Distance(information) **/
  464. struct VOD{
  465. F32 dis_nex; //:Distance_To_Next
  466. F32 dis_sur; //:Distance_To_Surface
  467. //:Within_Current_Voxel
  468. };
  469.  
  470. struct VOE{
  471. F32 msg_err;
  472. };
  473.  
  474. struct VOX_000{ /** var: vox_000 **/
  475.  
  476. VOC voc; //:Voxel_Current_Info
  477. VOD vod; //:Voxel_Distance_Info
  478. VOE voe; //:Voxel_Error____Info
  479.  
  480. };
  481.  
  482. //:----------------------------------:VOX_000://
  483. //:PIX_000:----------------------------------://
  484.  
  485. struct PIX_000{ //:SEE[ #VOX_MAR_ABOUT# ]
  486.  
  487. uint exit;
  488.  
  489. };
  490.  
  491. //:----------------------------------:PIX_000://
  492. //:O_K_C4D:----------------------------------://
  493.  
  494. struct O_K_C4D{
  495.  
  496. I32 o_k;
  497. V_4 c4d;
  498.  
  499. };
  500.  
  501. //:----------------------------------:O_K_C4D://
  502. //:VON:--------------------------------------://
  503.  
  504. struct VON{
  505.  
  506. //: von_d3d===[til_d3d,pix_d3d,etc]
  507. I32 von_d3d;
  508.  
  509. };
  510.  
  511. //:--------------------------------------:VON://
  512. //:REFACTOR_ME_001:--------------------------://
  513. //:REFAC01:----------------------------------://
  514.  
  515. struct REFAC01{
  516.  
  517. /** Rather than have VOX_000 & **/
  518. /** PIX_000 structs, everything **/
  519. /** can just use **/
  520. /** sta_add (stack_address) **/
  521. /** sta_con (stack_context) **/
  522. /** **/
  523. /** But for now, just get rendering **/
  524. /** first before be abstract code. **/
  525.  
  526. RWC_AND_RWN rwC_AND_rwN;
  527. O_K_C4D o_k_c4d;
  528.  
  529. /** TODO: Replace VOX_000 & PIX_000 **/
  530. /** with generic[ sta_add ]and **/
  531. /** [ sta_con ]variables. **/
  532. VOX_000 vox_000;
  533. PIX_000 pix_000;
  534.  
  535. /** xyz's TotalDistanceFrom(TDF) rwC **/
  536. F32 xyz_TDF_rwC;
  537.  
  538. V_3 xyz; /** xyz == Copy of rwC **/
  539.  
  540. /** Because we offboarded inner loop **/
  541. /** code to a "looptick" functions, **/
  542. /** we require a "should_break" **/
  543. /** flag to maintain the original **/
  544. /** ability of early exiting **/
  545. /** our shader raymarch loop. **/
  546. U32 should_break;
  547. };
  548.  
  549. //:----------------------------------:REFAC01://
  550. //:--------------------------:REFACTOR_ME_001://
  551. //:======================================:STRUCTS://
  552.  
  553. /** D: Data Section **/
  554. //:DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD://
  555. //:IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII://
  556. /** I: Inifnite Degree Functions. Always At Top. **/
  557.  
  558. //:NO_HALT_USE_ERROR_PIXEL:======================://
  559. //:PIX_ERR:======================================://
  560.  
  561. #define ERR_001 1 /** msg_err #1 (0x101010)**/
  562. /** msg_err #1 (0x010101)**/
  563.  
  564. #define ERR_002 2 /** msg_err #2 (0x202020)**/
  565. /** msg_err #2 (0x020202)**/
  566.  
  567. #define ERR_003 3 /** msg_err #3 (0x303030)**/
  568. /** msg_err #3 (0x030303)**/
  569.  
  570. V_4 PIX_ERR(
  571. int msg_err /** EX: MSG_ERR_001 **/
  572. , V_4 pix_err /** Previous Pixel Error **/
  573. , int o_k
  574. )
  575. {
  576. /** Muddy Pastel Yellow For When You **/
  577. /** forget to set the pix_err_out value. **/
  578. V_4 pix_err_out=V_4(0.5,0.5,0.2,1);
  579.  
  580. float flux=( mod(iTime,1.0) );
  581.  
  582. //:COLOR_PICKER_DEBUG_HEX:---------------://
  583.  
  584. /** Make it easy to find source of error **/
  585. /** in code by using color picker on **/
  586. /** shader output and then doing a **/
  587. /** CTRL+F with that hex code to find **/
  588. /** the offending source code. **/
  589.  
  590. F32 _ =F32( 0.0 );
  591. F32 MAX =F32( 255.0 ); // MaxIntensity
  592. F32 A =F32( 1.0 ); // Alpha_Max
  593.  
  594. //:ERROR_CODE_STROBE_COLORS:---------://
  595.  
  596. F32 _01_ =( F32(0x01) / MAX );
  597. F32 _10_ =( F32(0x10) / MAX );
  598. //
  599. F32 _02_ =( F32(0x02) / MAX );
  600. F32 _20_ =( F32(0x20) / MAX );
  601. //
  602. F32 _03_ =( F32(0x03) / MAX );
  603. F32 _30_ =( F32(0x30) / MAX );
  604. //
  605. F32 _04_ =( F32(0x04) / MAX );
  606. F32 _40_ =( F32(0x40) / MAX );
  607. //
  608. F32 _05_ =( F32(0x05) / MAX );
  609. F32 _50_ =( F32(0x50) / MAX );
  610. //
  611. F32 _06_ =( F32(0x06) / MAX );
  612. F32 _60_ =( F32(0x60) / MAX );
  613. //
  614. F32 _07_ =( F32(0x07) / MAX );
  615. F32 _70_ =( F32(0x70) / MAX );
  616. //
  617. F32 _08_ =( F32(0x08) / MAX );
  618. F32 _80_ =( F32(0x80) / MAX );
  619. //
  620. F32 _09_ =( F32(0x09) / MAX );
  621. F32 _90_ =( F32(0x90) / MAX );
  622.  
  623. V_4 _0x010101_ = V_4(_01_,_01_,_01_, A);
  624. V_4 _0x101010_ = V_4(_10_,_10_,_10_, A);
  625.  
  626. V_4 _0x020202_ = V_4(_02_,_02_,_02_, A);
  627. V_4 _0x202020_ = V_4(_20_,_20_,_20_, A);
  628.  
  629. V_4 _0x030303_ = V_4(_03_,_03_,_03_, A);
  630. V_4 _0x303030_ = V_4(_30_,_30_,_30_, A);
  631.  
  632. V_4 _0x040404_ = V_4(_04_,_04_,_04_, A);
  633. V_4 _0x404040_ = V_4(_40_,_40_,_40_, A);
  634.  
  635. V_4 _0x050505_ = V_4(_05_,_05_,_05_, A);
  636. V_4 _0x505050_ = V_4(_50_,_50_,_50_, A);
  637.  
  638. V_4 _0x060606_ = V_4(_06_,_06_,_06_, A);
  639. V_4 _0x606060_ = V_4(_60_,_60_,_60_, A);
  640.  
  641. V_4 _0x070707_ = V_4(_07_,_07_,_07_, A);
  642. V_4 _0x707070_ = V_4(_70_,_70_,_70_, A);
  643.  
  644. V_4 _0x080808_ = V_4(_08_,_08_,_08_, A);
  645. V_4 _0x808080_ = V_4(_80_,_80_,_80_, A);
  646.  
  647. V_4 _0x090909_ = V_4(_09_,_09_,_09_, A);
  648. V_4 _0x909090_ = V_4(_90_,_90_,_90_, A);
  649.  
  650. //:---------:ERROR_CODE_STROBE_COLORS://
  651. //:ERROR_ZERO_COLORS:----------------://
  652. #define F float
  653. #define V vec4
  654. /** If you forget to set error code, **/
  655. /** you will see flashing red and **/
  656. /** blue. ( _0xFF0666_ & _0x6660FF_ )**/
  657.  
  658. F _FF_=( F32(0xFF) / MAX );
  659. // _06_=( F32(0x06) / MAX );
  660. // _60_=( F32(0x60) / MAX );
  661. F _66_=( F32(0x66) / MAX );
  662. V _0xFF0666_ =V_4(_FF_,_06_,_66_,A);
  663. V _0x6660FF_ =V_4(_66_,_60_,_FF_,A);
  664.  
  665. #undef F
  666. #undef V
  667. //:----------------:ERROR_ZERO_COLORS://
  668. //:BAD_OK_ERROR_COLOR:---------------://
  669. #define F float
  670. #define V vec4
  671. /** You will see this if you init **/
  672. /** o_k to a value other than 1 in **/
  673. /** your source code. **/
  674. /** Strobes between orange and lime. **/
  675. /** ( _0xFF7700_ & _0x77FF00_ ) **/
  676.  
  677. // _FF_=( F32(0xFF) / MAX );
  678. F _77_=( F32(0x77) / MAX );
  679. F _00_=( F32(0x00) / MAX );
  680. V _0xFF7700_ =V_4(_FF_,_77_,_00_,A);
  681. V _0x77FF00_ =V_4(_77_,_FF_,_00_,A);
  682.  
  683. #undef F
  684. #undef V
  685. //:---------------:BAD_OK_ERROR_COLOR://
  686.  
  687. //:---------------:COLOR_PICKER_DEBUG_HEX://
  688.  
  689. if( o_k <= 0 ){
  690. pix_err_out = pix_err;
  691. }else
  692. if( 1 == o_k ){
  693.  
  694. /** table of error "messages" #0 **/
  695. V_4 tab_err_000[10]=V_4[10](
  696.  
  697. // 0: Invalid Error Code
  698. _0xFF0666_ // RED_FLASH
  699.  
  700. // Odd Frame Error Colors:
  701. , _0x010101_ // ERR_001 : ODD_FRAME
  702. , _0x020202_ // ERR_002 : ODD_FRAME
  703. , _0x030303_ // ERR_003 : ODD_FRAME
  704. , _0x040404_ // ERR_004 : ODD_FRAME
  705. , _0x050505_ // ERR_005 : ODD_FRAME
  706. , _0x060606_ // ERR_006 : ODD_FRAME
  707. , _0x070707_ // ERR_007 : ODD_FRAME
  708. , _0x080808_ // ERR_008 : ODD_FRAME
  709. , _0x090909_ // ERR_009 : ODD_FRAME
  710. );;
  711. /** table of error "messages" #1 **/
  712. V_4 tab_err_001[10]=V_4[10](
  713.  
  714. // 0: Invalid Error Code
  715. _0x6660FF_ // BLUE_FLASH
  716.  
  717. // Even Frame Error Colors:
  718. , _0x101010_ // ERR_001 : EVE_FRAME
  719. , _0x202020_ // ERR_002 : EVE_FRAME
  720. , _0x303030_ // ERR_003 : EVE_FRAME
  721. , _0x404040_ // ERR_004 : EVE_FRAME
  722. , _0x505050_ // ERR_005 : EVE_FRAME
  723. , _0x606060_ // ERR_006 : EVE_FRAME
  724. , _0x707070_ // ERR_007 : EVE_FRAME
  725. , _0x808080_ // ERR_008 : EVE_FRAME
  726. , _0x909090_ // ERR_009 : EVE_FRAME
  727. );;
  728.  
  729. if( mod(iTime*16.0,2.0) < 1.0 ){
  730. pix_err_out =( tab_err_000
  731. [ msg_err ] );;
  732. }else{
  733. pix_err_out =( tab_err_001
  734. [ msg_err ] );;
  735. };;
  736.  
  737. }else{
  738. /** Orange strobe for an o_k value **/
  739. /** that is NOT expected. (o_k >= 2) **/
  740.  
  741. if( mod(iTime*2.0,2.0) < 1.0 ){
  742. pix_err_out = _0xFF7700_; // ORANGE
  743. }else{
  744. pix_err_out = _0x77FF00_; // LIME
  745. };;
  746.  
  747. };;
  748.  
  749. return( pix_err_out );
  750. }
  751.  
  752. //:======================================:PIX_ERR://
  753. //:======================:NO_HALT_USE_ERROR_PIXEL://
  754. //:MAX_OF_3:=====================================://
  755.  
  756. F32
  757. max_003( F32 a , F32 b , F32 c )
  758. {
  759. return( max( max(a,b) , c ) );
  760. }
  761.  
  762. //:=====================================:MAX_OF_3://
  763.  
  764. /** I: Inifnite Degree Functions. Always At Top. **/
  765. //:IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII://
  766. //:33333333333333333333333333333333333333333333333333://
  767.  
  768. //:SAMPLE_PROJECTION_GEOMETRY:===================://
  769.  
  770. /** SampleProjectionGeometry **/
  771. U32 til_d3d_AND_pix_d3d_CTO_u32_bit(
  772. I32 til_d3d,I32 pix_d3d
  773. ){
  774.  
  775. /** Bit should be 0 or 1 when returned. **/
  776. U32 u32_bit=U32( 404 /**TRAP_VALUE**/ );
  777.  
  778. //:SHORTCUT[ D3D_CTO_XYZ ]- - - - - - - -://
  779. #define T trunc
  780. #define I int
  781. #define F float
  782.  
  783. /// I D3D =( pix_d3d /**[GIVEN/INPUT]**/ );
  784. /// I T_Z = I( T( F(D3D) / F ( NTX*NTY )));
  785. /// I D2D = D3D -(T_Z*( NTX*NTY ) );
  786. /// I T_Y = I( T( F(D2D) / F ( NTX )));
  787. /// I T_X = D2D -(T_Y*( NTX ) );
  788.  
  789. #undef T
  790. #undef I
  791. #undef F
  792. //:- - - - - - - -SHORTCUT[ D3D_CTO_XYZ ]://
  793.  
  794. U32 til_val = VAT[ til_d3d ];
  795.  
  796. if( til_val > U32( SDF_PRO_MAX ) ){
  797.  
  798. /** no cross sectional data to create**/
  799. /** interior voxel topology. So just **/
  800. /** return 1 (filled) for every pixel**/
  801. /** of the current voxel. **/
  802.  
  803. u32_bit =U32( 1 );
  804. }else
  805. if( U32(1) == til_val /** SDF_PRO_001 **/ ){
  806.  
  807. u32_bit=U32( 9001 /**[TODO]:ACTUAL_LOGIC**/ ); //# <<<<<<<<<<<<<<<<<<<<<<<<< TODO #//
  808.  
  809. }else
  810. if( U32(2) == til_val /** SDF_PRO_002 **/ ){
  811.  
  812. u32_bit=U32( 9002 /**[TODO]:ACTUAL_LOGIC**/ ); //# <<<<<<<<<<<<<<<<<<<<<<<<< TODO #//
  813.  
  814. }else
  815. if( U32(3) == til_val /** SDF_PRO_003 **/ ){
  816.  
  817. u32_bit=U32( 9003 /** TODO:LOGIC **/ ); //:<<<<<<<<<<TODO
  818.  
  819. }else{
  820. u32_bit =U32(666 /** ERROR_CODE **/ );
  821. };;
  822.  
  823. return( u32_bit );
  824.  
  825. }
  826.  
  827. //:===================:SAMPLE_PROJECTION_GEOMETRY://
  828.  
  829.  
  830. //:33333333333333333333333333333333333333333333333333://
  831. //:22222222222222222222222222222222222222222222222222://
  832.  
  833. //:INTERPOLATION_3D:=============================://
  834. //:sfd_i3d:======================================://
  835.  
  836. V_3 sdf_i3d(
  837. /**/V_3 _1_
  838. , V_3 _2_
  839. , F32 f_p
  840. ){
  841. return( _1_ + ( ( _2_ - _1_ )*f_p ) );
  842. }
  843.  
  844. //:=============================:INTERPOLATION_3D://
  845. //:======================================:sfd_i3d://
  846. //:FIRST_VOXEL_QUERY_NEEDED:=====================://
  847. //:@WHATVOX@
  848. // ############################# //
  849. #define T_X ( vox_000.voc.t_x )
  850. #define T_Y ( vox_000.voc.t_y )
  851. #define T_Z ( vox_000.voc.t_z )
  852. // ############################# //
  853. #define P_X ( vox_000.voc.p_x )
  854. #define P_Y ( vox_000.voc.p_y )
  855. #define P_Z ( vox_000.voc.p_z )
  856. #define P_I ( vox_000.voc.pix_d3d )
  857. // ############################# //
  858.  
  859. /** rwN used to find distance to NEXT voxel. **/
  860. VOX_000
  861. GET_vox_000_USE_xyz_rwN(
  862. V_3 xyz
  863. , V_3 rwN
  864. )
  865. {
  866. VOX_000 vox_000;
  867.  
  868. /** f: floor(xyz) values: **/
  869. F32 f_x = floor( xyz.x );
  870. F32 f_y = floor( xyz.y );
  871. F32 f_z = floor( xyz.z );
  872.  
  873. //:CURRENT_VOXEL_CELL:-------------------://
  874.  
  875. vox_000.voc.val = U32( 0 );
  876. T_X = ( int(floor( xyz.x / float( NPX ))));
  877. T_Y = ( int(floor( xyz.y / float( NPY ))));
  878. T_Z = ( int(floor( xyz.z / float( NPZ ))));
  879.  
  880. //:-------------------:CURRENT_VOXEL_CELL://
  881. //:GET_VOXEL_CELL_VALUE:-----------------://
  882.  
  883. /** Voxel Volume Is Hard Coded To have **/
  884. /** voxel__tile[0,0,0] stuck at world **/
  885. /** world_coord[0,0,0] **/
  886. if( T_X >= 0 && T_X < NTX
  887. && T_Y >= 0 && T_Y < NTY
  888. && T_Z >= 0 && T_Z < NTZ
  889. ){
  890.  
  891. //: Index2D -and- Index3D
  892. int D2D = T_X + ( NTX * T_Y );
  893. int D3D = D2D + ( NTX * NTY * T_Z );
  894.  
  895. vox_000.voc.til_d3d=( D3D );
  896. vox_000.voc.val =( VAT[ D3D ] );
  897.  
  898. /** NOTE: Voxel value 0 will NOT get **/
  899. /** special treatment. It could**/
  900. /** contain geometry if we **/
  901. /** really wanted it to. **/
  902. vox_000.voc.has= U32( 1 );
  903.  
  904. }else{
  905. /** Using a "has" flag so we **/
  906. /** can keep more logic UNSIGNED. **/
  907. /** (No need for negative value to ) **/
  908. /** (be used for invalid dex or val) **/
  909. vox_000.voc.til_d3d= int( 0 );
  910. vox_000.voc.val = U32( 0 );
  911. vox_000.voc.has = U32( 0 );
  912. };;
  913. //:-----------------:GET_VOXEL_CELL_VALUE://
  914. //:DIST_TO_NEXT_VOXEL:-------------------://
  915. /** ************************************ ***
  916. x_bound
  917. |||
  918. |||
  919. |||
  920. ====+-----+---[i]----+====== y_bound ====
  921. | | / ||
  922. | | / ||
  923. | | / ||
  924. | |/ ||
  925. +- - -P----------+|
  926. | . ||
  927. | . ||
  928. +-----+----------+|
  929. |||
  930. |||
  931. |||
  932. |||
  933. *** ************************************ **/
  934. #define P xyz /** Point **/
  935. #define N rwN /** Normal **/
  936.  
  937. //:SIGNS_OF_RAY_VECTOR:--------------://
  938. /** We need to know if the ray is **/
  939. /** moving forwards to HIGHER tile **/
  940. /** values or BACKWARDS to LOWER **/
  941. /** tile values. **/
  942.  
  943. /** SEE[ #CONSISTENT_VOXEL_COORDS# **/
  944. F32 b_x /** x_bound **/ ;
  945. F32 b_y /** y_bound **/ ;
  946. F32 b_z /** z_bound **/ ;
  947. /** **/ ;
  948. F32 x_0 /** x_bound : MIN **/ ;
  949. F32 y_0 /** y_bound : MIN **/ ;
  950. F32 z_0 /** z_bound : MIN **/ ;
  951. /** **/ ;
  952. F32 x_1 /** x_bound : MAX **/ ;
  953. F32 y_1 /** y_bound : MAX **/ ;
  954. F32 z_1 /** z_bound : MAX **/ ;
  955. ;
  956. x_1 =F32( ( T_X + 1 ) * NPX ) ;
  957. y_1 =F32( ( T_Y + 1 ) * NPY ) ;
  958. z_1 =F32( ( T_Z + 1 ) * NPZ ) ;
  959. ;
  960. /** #MINUS_EPSILON# **/
  961. //:.....................10........20
  962. //:...........0.12345678901234567890
  963. #define EPS_X ( 0.0001 ) /**#ITBIDKW#**/
  964. #define EPS_Y ( 0.0001 ) /**#ITBIDKW#**/
  965. #define EPS_Z ( 0.0001 ) /**#ITBIDKW#**/
  966. x_0 =F32( ( T_X - 0 ) * NPX ) -EPS_X ;
  967. y_0 =F32( ( T_Y - 0 ) * NPY ) -EPS_Y ;
  968. z_0 =F32( ( T_Z - 0 ) * NPZ ) -EPS_Z ;
  969. #undef EPS_X
  970. #undef EPS_Y
  971. #undef EPS_Z
  972. /** #MINUS_EPSILON# **/
  973. ;
  974. b_x = N.x >= 0.0 ? x_1 : x_0 ;
  975. b_y = N.y >= 0.0 ? y_1 : y_0 ;
  976. b_z = N.z >= 0.0 ? z_1 : z_0 ;
  977.  
  978. //:--------------:SIGNS_OF_RAY_VECTOR://
  979. /** ******************************** ***
  980. SEE[ #NEXT_VOXEL_BOUNDING_VOLUME# ]
  981. The intersection point to next voxel
  982. (By using plane intersections) should
  983. not be further than ONE PIXEL away
  984. from the current voxel we are inside.
  985.  
  986. +----------------+----------------+
  987. | +- - - - - -+ | +- - - - - -+ |
  988. | | | | | | |
  989. | | |
  990. | | | | | | |
  991. | | |
  992. | | | | | | |
  993. | +- - - - - -+ | +- - - - - -+ |
  994. +----------------+----------------+
  995. | +- - - - - -+ | +- - - - - -+ |
  996. | | | | | | |
  997. | | |
  998. | | CV | | | | |
  999. | (CurVoxel) | |
  1000. | | | | | | |
  1001. | +- - - - - -+ | +- - - - - -+ |
  1002. +----------------+----------------+
  1003.  
  1004. *** ******************************** **/
  1005. /** ******************************** ***
  1006. ___ == DONT CARE ABOUT
  1007. P + (N * S )==[ b_x, ___ , ___ ]
  1008. P.x + (N.x * S.x )== b_x
  1009. (N.x * S.x )== b_x - P.x
  1010. S.x == (b_x - P.x) / N.x
  1011. *** ******************************** **/
  1012. //:FIRST_PIXEL_OF_NEXT_VOXEL:--------://
  1013. #define N_X ( 0.0 != N.x )
  1014. #define N_Y ( 0.0 != N.y )
  1015. #define N_Z ( 0.0 != N.z )
  1016.  
  1017. //:Scalar for point normal form.
  1018. //:F32 MAX_F32=intBitsToFloat(0x7f7fFFFF);
  1019. //:F32 MAX_F32=F32( 2147483647 );
  1020. F32 MAX_F32=F32( 1000 * 1000 );
  1021. V_3 S = V_3(MAX_F32,MAX_F32,MAX_F32);
  1022. //:V_3 S = V_3( 0,0,0 );
  1023.  
  1024. /** [f_x,f_y,f_z] or [ P.x,P.y,P.z ]**/
  1025. if( N_X ){ S.x = ( b_x - P.x ) / N.x; }; //:<<<<<<<<<<< THIS EQUATION MINUS BY floored or by P ?
  1026. if( N_Y ){ S.y = ( b_y - P.y ) / N.y; };
  1027. if( N_Z ){ S.z = ( b_z - P.z ) / N.z; };
  1028.  
  1029. /** #TRAP_VALUE_MUST_BE_NEG_666# **/
  1030. #define _666_ ( 0.0 - 666.0 )
  1031. F32 shortest_scalar_distance=( _666_ );
  1032. V_3 first_pixel_of_next_voxel;
  1033. #undef _666_
  1034.  
  1035. if( N_X && S.x <= S.y && S.x <= S.z ){
  1036. shortest_scalar_distance=( S.x );
  1037. }else
  1038. if( N_Y && S.y <= S.x && S.y <= S.z ){
  1039. shortest_scalar_distance=( S.y );
  1040. }else
  1041. if( N_Z && S.z <= S.x && S.z <= S.y ){
  1042. shortest_scalar_distance=( S.z );
  1043. };;
  1044.  
  1045. /** Not using this anywhere, BUT KEEP**/
  1046. /** for now. Now is not the time **/
  1047. /** to optimize. **/
  1048. first_pixel_of_next_voxel=(
  1049. //: P + ( N * [ S.x | S.y | S.z ] )
  1050. P + ( N * shortest_scalar_distance )
  1051. );;
  1052.  
  1053. vox_000.vod.dis_nex=(
  1054. shortest_scalar_distance );;
  1055.  
  1056. //:vox_000.vod.dis_nex=( 8.0 );
  1057.  
  1058. #undef N_X
  1059. #undef N_Y
  1060. #undef N_Z
  1061. //:--------:FIRST_PIXEL_OF_NEXT_VOXEL://
  1062.  
  1063.  
  1064. #undef P /** Point **/
  1065. #undef N /** Normal **/
  1066. //:-------------------:DIST_TO_NEXT_VOXEL://
  1067. //:GET_VOXEL_PIXEL:----------------------://
  1068. if( vox_000.voc.has >= U32(1) ){ //:-----://
  1069.  
  1070. /** If you are inside a voxel, than **/
  1071. /** you by definition MUST be at a **/
  1072. /** certain pixel within that voxel. **/
  1073.  
  1074. P_X = I32( f_x ) - (T_X * NPX);
  1075. P_Y = I32( f_y ) - (T_Y * NPY);
  1076. P_Z = I32( f_z ) - (T_Z * NPZ);
  1077.  
  1078.  
  1079. /** ******************************** ***
  1080.  
  1081. This is why we should FLOOR xyz
  1082. values when figuring out what
  1083. Tile(voxel) or Pixel(VoxelSubCell)
  1084. we are inside of.
  1085.  
  1086. |<- 0 ->|<- 1 ->| <-- DISCREET_MODEL
  1087. +---+---+---+---+
  1088. | . | . |
  1089. + - + - + - + - +
  1090. | . | . |
  1091. +---+---+---+---+
  1092. ^ ^
  1093. | |
  1094. 0 1 <---------- FRACTIONAL_MODEL
  1095.  
  1096. *** ******************************** **/
  1097.  
  1098. //: Index2D -and- Index3D
  1099. int D2D = P_X + ( NPX * P_Y );
  1100. int D3D = D2D + ( NPX * NPY * P_Z );
  1101.  
  1102. P_I = ( D3D /** inDEX_3D **/ );
  1103.  
  1104. };; //:------------------:GET_VOXEL_PIXEL://
  1105.  
  1106. return( vox_000 );
  1107.  
  1108. } // <<<<<<<<<<<<<{ GET_vox_000_USE_xyz_rwN } //
  1109.  
  1110. // ---------------------------------------------- //
  1111. #undef T_X // ( vox_000.voc.t_x ) // --------- //
  1112. #undef T_Y // ( vox_000.voc.t_y ) // --------- //
  1113. #undef T_Z // ( vox_000.voc.t_z ) // --------- //
  1114. // ---------------------------------------------- //
  1115. #undef P_X // ( vox_000.voc.p_x ) // ----- //
  1116. #undef P_Y // ( vox_000.voc.p_y ) // ----- //
  1117. #undef P_Z // ( vox_000.voc.p_z ) // ----- //
  1118. #undef P_I // ( vox_000.voc.pix_d3d ) // ----- //
  1119. //:=====================:FIRST_VOXEL_QUERY_NEEDED://
  1120. //:MARCH_INTO_VOXEL:=============================://
  1121. //:sdf_MarchIntoVoxel:===========================://
  1122. /** COULD_MAKE_USE_OF[ #STACK_ADDRESS_WORKINGS# ]**/
  1123.  
  1124. PIX_000
  1125. GET_pix_000_USE_xyz_rwN_til_d3d_pix_d3d(
  1126. /**/V_3 xyz
  1127. , V_3 rwN
  1128. , I32 til_d3d
  1129. , I32 pix_d3d
  1130. )
  1131. {
  1132.  
  1133. PIX_000 pix_000;
  1134. pix_000.exit=U32( 1 );
  1135.  
  1136. U32 til_val; /** AKA: vox_000.voc.val **/
  1137. //: U32 pix_d3d: /** AKA: vox_000.voc.pix_d3d**/
  1138.  
  1139. //:RE_LOOKUP_CURRENT_TILE_VALUE:---------://
  1140.  
  1141. /**************************************/
  1142. /** Auto tiling at the voxel level **/
  1143. /** would Go here and replace this **/
  1144. /** simple lookup. **/
  1145. /**************************************/
  1146.  
  1147. til_val = VAT[ til_d3d ];
  1148.  
  1149. /**************************************/
  1150.  
  1151.  
  1152.  
  1153.  
  1154. //:---------:RE_LOOKUP_CURRENT_TILE_VALUE://
  1155. //:INTERIOR_VOXEL_MARCHING_LOOP:---------://
  1156. //:PIXEL_MARCHING:-----------------------://
  1157.  
  1158. U32 some_condition_i_dont_know_yet = U32( 0 ); //:<<<<<<<<<<<<<<<<<<<< TODO: What should this condition be?
  1159. if( some_condition_i_dont_know_yet >= U32(1) ){
  1160.  
  1161. U32 u32_bit =U32( 123 /**TRAP_VALUE**/);
  1162. //: U32 til_val = ( vox_000.voc.val );
  1163. //: I32 pix_d3d = ( vox_000.voc.pix_d3d );
  1164.  
  1165. //:NOT:til_val_AND_pix_d3d_CTO_u32_bit
  1166. //:YES:til_d3d_AND_pix_d3d_CTO_u32_bit
  1167. //:#CASH_IN_INDEXES_AT_LAST_MOMENT#
  1168.  
  1169. /** SampleProjectionGeometry **/
  1170. u32_bit=(
  1171. til_d3d_AND_pix_d3d_CTO_u32_bit(
  1172. til_d3d , pix_d3d ));;
  1173.  
  1174. };;
  1175.  
  1176. //:-----------------------:PIXEL_MARCHING://
  1177. //:---------:INTERIOR_VOXEL_MARCHING_LOOP://
  1178.  
  1179. return( pix_000 );
  1180. }
  1181.  
  1182. //:===========================:sdf_MarchIntoVoxel://
  1183. //:=============================:MARCH_INTO_VOXEL://
  1184. //:MAP_UINT32_TO_COLOR_4D:=======================://
  1185. #define F float
  1186. #define U uint
  1187. #define _FF_ uint( 0xFF )
  1188.  
  1189. V_4 u32_CTO_c4d(
  1190. U32 u32
  1191. ){
  1192. V_4
  1193. c4d = V_4( /** c4d:Color_4_Dimensional **/
  1194. F( ( u32 >> U(24) ) & _FF_ ) / 255.0
  1195. , F( ( u32 >> U(16) ) & _FF_ ) / 255.0
  1196. , F( ( u32 >> U( 8) ) & _FF_ ) / 255.0
  1197. , F( ( u32 >> U( 0) ) & _FF_ ) / 255.0
  1198. );;
  1199. return( c4d );
  1200. }
  1201.  
  1202. //:- - - - - - - - - - - -- - - - - - - - - - - -://
  1203.  
  1204. V_4 Flash_rgb_rgb_CTO_c4d(
  1205. U32 h_1 /** NO_ALPHA_CHANNEL !! **/
  1206. , U32 h_2 /** NO_ALPHA_CHANNEL !! **/
  1207. )
  1208. {
  1209. V_4 c4d; /** RETURN_THIS **/
  1210. U32 hex_no_alpha;
  1211.  
  1212. if( mod(iTime*16.0,2.0) < 1.0 ){
  1213. hex_no_alpha = ( h_1 );
  1214. }else{
  1215. hex_no_alpha = ( h_2 );
  1216. };;
  1217.  
  1218. /** Append 100% alpha before calling. **/
  1219. c4d = u32_CTO_c4d(
  1220. ( hex_no_alpha << U(8) ) | _FF_
  1221. );;
  1222.  
  1223. return( c4d /** RETURN_THIS **/ );
  1224. }
  1225.  
  1226. #undef F
  1227. #undef U
  1228. #undef _FF_
  1229. //:=======================:MAP_UINT32_TO_COLOR_4D://
  1230. //:INTEGER_MODULO:===============================://
  1231.  
  1232. #ifndef I32
  1233. #define I32 int
  1234. #endif
  1235.  
  1236. #ifndef F32
  1237. #define F32 float
  1238. #endif
  1239.  
  1240. /** PRIVATE: Called only by I32_MOD **/
  1241. I32 i32_mod_neg( I32 neg_a , I32 pos_d ){
  1242.  
  1243. /** ************************************ ***
  1244. Function Calculates:
  1245.  
  1246. FIXED: (d-1)-[ mod(abs(a)+1 , d) ]
  1247.  
  1248. GOAL: Negatives keep exact same tiling
  1249. pattern as the positives.
  1250.  
  1251. IN : -6 -5 -4 -3 -2 -1 0 +1 +2 +3 +4 +5 +6
  1252. OUT: 2 3 0 1 2 3 0 1 2 3 0 1 2
  1253.  
  1254. 0123 -> 0123 -> 0123 -> 0123 -> 0123 -> ect
  1255.  
  1256.  
  1257.  
  1258. *** ************************************ **/
  1259.  
  1260. I32 pos_a = ( 0 - neg_a ) + 1;
  1261.  
  1262. F32 A = F32( pos_a );
  1263. F32 D = F32( pos_d );
  1264.  
  1265. //: GLSL_MODULUS_WITH_INTEGERS_FORMULA
  1266. //: WARD:Wholepart,All,Remainder,Divisor
  1267. int W = int( trunc( A / ( D )) );
  1268. int R = int( A - ( F32(W) * D ) );
  1269.  
  1270. return( (pos_d-1) - R );
  1271. }
  1272.  
  1273. I32
  1274. I32_MOD(
  1275. /**/I32 a /** ALL : CAN BE NEGATIVE **/
  1276. , I32 d /** DIVISOR : ALWAYS POSITIVE **/
  1277. ){
  1278.  
  1279. /** ************************************ ***
  1280.  
  1281. Allow for I32_MOD to be used for wrapping
  1282. even when the input to wrap[ a ] goes
  1283. negative. d should always be positive.
  1284.  
  1285. EX: mod( x , 2 ) , where x == -1
  1286. | -1 | 0 [ 1 ] 2 |
  1287. | 1 | 0 [ 1 ] 0 | 1 | 0 |
  1288. d + 1 == 2 + (-1) == 1
  1289. *** ************************************ **/
  1290.  
  1291. int R;
  1292.  
  1293. if( a < 0 ){
  1294.  
  1295. //:This is CLOSE but then new problem
  1296. //:of lots of green checkers is showing
  1297. //:up. No clue...
  1298. R = i32_mod_neg( a , d );
  1299.  
  1300. }else{
  1301.  
  1302. F32 A = F32( a );
  1303. F32 D = F32( d );
  1304. //:<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<FIX_THE_OVERFLOW_BELOW
  1305. //: GLSL_MODULUS_WITH_INTEGERS_FORMULA
  1306. //: WARD:Wholepart,All,Remainder,Divisor
  1307. int W = int( trunc( A / ( D )) );
  1308. R = int( A - ( F32(W) * D ) );
  1309.  
  1310. };;
  1311.  
  1312. return( R );
  1313. }
  1314. //:===============================:INTEGER_MODULO://
  1315. //:MAX_OF_3_NAMED_BY_USE_CASE:===================://
  1316. #define F float
  1317. #define M max
  1318.  
  1319. F32
  1320. GET_npm_USE_npx_npy_npz(
  1321. I32 npx /** I32 so we don't **/
  1322. , I32 npy /** need to CAST when**/
  1323. , I32 npz /** calling this. **/
  1324. ){ /** ACTUALLY U32 vals**/
  1325.  
  1326. //: npm: Number_of_Pixels_Max(x,y,z)
  1327. F32 npm = M( M( F(NPX),F(NPY) ),F(NPZ) );
  1328. return( npm );
  1329. }
  1330.  
  1331. #undef F
  1332. #undef M
  1333. //:===================:MAX_OF_3_NAMED_BY_USE_CASE://
  1334. //:VOXEL_TO_DEBUG_COLOR:=========================://
  1335. /** @VOXBUGCOLOR@ **/
  1336. #define P_X ((( vox_000.voc.p_x )))
  1337. #define P_Y ((( vox_000.voc.p_y )))
  1338. #define P_Z ((( vox_000.voc.p_z )))
  1339. #define ALP ( 1.0 )
  1340.  
  1341. V_4 vox_000_CTO_c4d(
  1342.  
  1343. VOX_000 vox_000
  1344. )
  1345. {
  1346. V_4 c4d; /** [output/return/result] **/
  1347.  
  1348. /** base color **/
  1349. V_4 b_c=( u32_CTO_c4d( vox_000.voc.val ));
  1350.  
  1351. #define F float
  1352. F d_x = min( F(P_X) , F( NPX - P_X - 1 ));
  1353. F d_y = min( F(P_Y) , F( NPY - P_Y - 1 ));
  1354. F d_z = min( F(P_Z) , F( NPZ - P_Z - 1 ));
  1355. #undef F
  1356.  
  1357. F32 m2d ; /** m2d: Minimum 2D **/
  1358.  
  1359. if( d_x <= d_y && d_x <= d_z ){
  1360. /** d_x == X_PLANE == [ y , z ] **/
  1361.  
  1362. m2d = min( d_y , d_z );
  1363. //: c4d =V_4( 1,0,0, ALP );
  1364. }else
  1365. if( d_y <= d_x && d_y <= d_z ){
  1366. /** d_y == Y_PLANE == [ x , z ] **/
  1367.  
  1368. m2d = min( d_x , d_z );
  1369. //: c4d =V_4( 0,1,0, ALP );
  1370.  
  1371. }else
  1372. if( d_z <= d_x && d_z <= d_y ){
  1373. /** d_z == Z_PLANE == [ x , y ] **/
  1374.  
  1375. m2d = min( d_x , d_y );
  1376. //: c4d =V_4( 0,0,1, ALP );
  1377.  
  1378. }else{
  1379. /** This should never execute **/
  1380. };;
  1381.  
  1382. #define F float
  1383. F32 n_p = max_003( F(NPX),F(NPY),F(NPZ) );
  1384. F32 per =( m2d*2.0 ) / n_p ;
  1385. #undef F
  1386.  
  1387. if( per > 0.0 ){
  1388.  
  1389. #if( ANIMATE_THE_CORES >= 1 ) //:####://
  1390.  
  1391. per = mod( per - iTime , 1.0 );
  1392.  
  1393. #endif //:###########################://
  1394.  
  1395. c4d =V_4(
  1396. b_c.x * per
  1397. , b_c.y * per
  1398. , b_c.z * per
  1399. , b_c.w * 1.0
  1400. );;
  1401.  
  1402. }else{
  1403. #define X d_x
  1404. #define Y d_y
  1405. #define Z d_z
  1406.  
  1407. /** #VOXEL_EDGE_COLOR# **/
  1408. /** #NO_ELSE_FOR_EDGE_COLORING# **/
  1409.  
  1410. F32 R=( 0.0 );
  1411. F32 G=( 0.0 );
  1412. F32 B=( 0.0 );
  1413.  
  1414. if( X <= Y && X <= Z ){ /** X_PLANE **/
  1415.  
  1416. R =( 1.0 );
  1417.  
  1418. };; /** NO ELSE! **/
  1419. if( Y <= X && Y <= Z ){ /** Y_PLANE **/
  1420.  
  1421. G =( 1.0 );
  1422.  
  1423. };; /** NO ELSE! **/
  1424. if( Z <= X && Z <= Y ){ /** Z_PLANE **/
  1425.  
  1426. B =( 1.0 );
  1427.  
  1428. };; /** NO ELSE! **/
  1429.  
  1430. c4d =V_4( R,G,B, ALP );
  1431.  
  1432. #undef X
  1433. #undef Y
  1434. #undef Z
  1435. };;
  1436.  
  1437. return( c4d );
  1438. }
  1439.  
  1440. #undef P_X
  1441. #undef P_Y
  1442. #undef P_Z
  1443. #undef ALP
  1444. //:=========================:VOXEL_TO_DEBUG_COLOR://
  1445.  
  1446. //:22222222222222222222222222222222222222222222222222://
  1447. //:11111111111111111111111111111111111111111111111111://
  1448.  
  1449. //:FRAGCOORD_TO_FRAGPERCENT:=====================://
  1450. //:f_c_CTO_f_p:==================================://
  1451.  
  1452. V_2 f_c_CTO_f_p( V_2 f_c ){
  1453. V_2 f_p;
  1454. f_p = f_c / ( iResolution.xy - 1.0 );
  1455. return( f_p );
  1456. }
  1457.  
  1458. //:==================================:f_c_CTO_f_p://
  1459. //:=====================:FRAGCOORD_TO_FRAGPERCENT://
  1460. //:FRAGPER_TO_CAMERA_RAY:========================://
  1461. //:f_p_CTO_rwC_AND_rwN_CAMTYPE_OGP_TOP:==========://
  1462.  
  1463. RWC_AND_RWN
  1464. f_p_CTO_rwC_AND_rwN_CAMTYPE_OGP_TOP(
  1465. V_2 f_p /** 2 dimensional percentage **/
  1466. )
  1467. {
  1468. F32 bug = ( F32(NPZ) * 4.0 ); //:DEBUG_ONLY
  1469. F32 spd =( 0.5 /**SPEED FACTOR **/ );
  1470. F32 pos_cos =( cos(iTime*spd)+1.0 ) / 2.0;
  1471. F32 neg_cos =( cos(iTime*spd)-1.0 ) / 2.0;
  1472. bug=bug*pos_cos;
  1473. //:bug = ( (-16.1) * bug );
  1474. //:bug = ( -1036.8 );
  1475. //:bug=( -32.2 );
  1476.  
  1477. /** ************************************ ***
  1478. TODO: Fix bug...
  1479. bug=( - 0.2 ); <<<<< OK
  1480. bug=( - 16.2 ); <<<<< OK
  1481. bug=( - 32.2 ); <<<<< ERR
  1482. bug=( - 48.2 ); <<<<< OK
  1483. bug=( - 64.2 ); <<<<< ERR
  1484. bug=( - 80.2 ); <<<<< OK
  1485. bug=( - 96.2 ); <<<<< ERR
  1486. bug=( - 112.2 ); <<<<< OK
  1487. bug=( - 128.2 ); <<<<< ERR
  1488. bug=( -1036.8 );
  1489.  
  1490. *** ************************************ **/
  1491.  
  1492. V_3 rwC; //:ray_word__COORDINATE
  1493. V_3 rwN; //:ray_world_NORMAL____
  1494.  
  1495. //:#FIND_POINT_ON_SCREEN_PLANE#
  1496. F32 H = F32( 0 - 9 );; //:Cam Height Pos
  1497. F32 X = iResolution.x - 1.0;
  1498. F32 Y = iResolution.y - 1.0;
  1499. /** ************************************ ***
  1500. A_B
  1501. A----|------B
  1502. | | |
  1503. | rwC |
  1504. | | |
  1505. C----|------D
  1506. C_D
  1507.  
  1508. *** ************************************ **/
  1509.  
  1510. F32 _ =F32( 0.0 /**ALWAYS_ZERO **/ );
  1511. F32 XOS=F32( 0 );
  1512. F32 YOS=F32( 0 );
  1513. F32 ZOS=F32( 0 );
  1514.  
  1515. V_3 _A_ = V_3( _+XOS,_+YOS, bug+H+ZOS );
  1516. V_3 _B_ = V_3( X+XOS,_+YOS, bug+H+ZOS );
  1517.  
  1518. V_3 _C_ = V_3( _+XOS,Y+YOS, bug+H+ZOS );
  1519. V_3 _D_ = V_3( X+XOS,Y+YOS, bug+H+ZOS );
  1520.  
  1521.  
  1522. V_3 A_B = sdf_i3d( _A_ , _B_ , f_p.x );
  1523. V_3 C_D = sdf_i3d( _C_ , _D_ , f_p.x );
  1524. rwC = sdf_i3d( A_B , C_D , f_p.y );
  1525.  
  1526. //:#POSITIVE_Z_DIVES_INTO_SCREEN#://
  1527. rwN = normalize( V_3( 0 , 0 , 1 ) );
  1528.  
  1529. RWC_AND_RWN
  1530. rwC_AND_rwN;
  1531. rwC_AND_rwN.rwC = rwC;
  1532. rwC_AND_rwN.rwN = rwN;
  1533. return( rwC_AND_rwN );
  1534. }
  1535.  
  1536. //:==========:f_p_CTO_rwC_AND_rwN_CAMTYPE_OGP_TOP://
  1537. //:f_p_CTO_rwC_AND_rwN_CAMTYPE_OGP_34D:==========://
  1538. #define _0_ (0.0)
  1539. #define _ (0.0)
  1540.  
  1541. RWC_AND_RWN
  1542. f_p_CTO_rwC_AND_rwN_CAMTYPE_OGP_34D(
  1543. V_2 f_p /** 2 dimensional percentage **/
  1544. )
  1545. {
  1546. RWC_AND_RWN /** OUTPUT_OBJECT **/
  1547. rwC_AND_rwN; /** OUTPUT_OBJECT **/
  1548.  
  1549. V_3 rwC; //:ray_word__COORDINATE
  1550. V_3 rwN; //:ray_world_NORMAL____
  1551.  
  1552. //:#FIND_POINT_ON_SCREEN_PLANE#
  1553. /** ************************************ ***
  1554. Could possibly use these as slice planes.
  1555. But for now using these to navigate our
  1556. voxel map bounds.
  1557.  
  1558. [ A ]Is_Directly_Above[ E ]On_Z_Axis
  1559. [ B ]Is_Directly_Above[ F ]On_Z_Axis
  1560. [ C ]Is_Directly_Above[ G ]On_Z_Axis
  1561. [ D ]Is_Directly_Above[ H ]On_Z_Axis
  1562.  
  1563. (In World/Frag Coords)
  1564. [0,0,0]
  1565. \
  1566. A_B \
  1567. A----|------B A --> +=======+ <-- B
  1568. | | | /. .\
  1569. | rwC_001 | / . . \
  1570. | | | / . . \
  1571. C----|------D C->+===============+<-D
  1572. C_D [ ._....._. ]
  1573. [ / \ ]
  1574. [ . . ]
  1575. [/ \]
  1576. +===============+<-H
  1577.  
  1578. +===============+
  1579. [\ /]
  1580. [ . . ]
  1581. [ \_......._/ ]
  1582. E_F [ . . ]
  1583. E----|------F G->+===============+<-H
  1584. | | | \ . . /
  1585. | rwC_002 | \ . . /
  1586. | | | \. ./
  1587. G----|------H E --> +=======+ <-- F
  1588. G_H
  1589.  
  1590. *** ************************************ **/
  1591.  
  1592. //:Dimensions Of Voxel Volume:
  1593. //:As maximum indexes.
  1594. F32 M_X =( F32(TPX) - 1.0 );
  1595. F32 M_Y =( F32(TPY) - 1.0 );
  1596. F32 M_Z =( F32(TPZ) - 1.0 );
  1597.  
  1598. //:TOP LAYER OF PIXELS OF VOXEL VOLUME:
  1599. //:(INCLUSIVE MATH. We are inside the)
  1600. //:(first layer of pixels of the first)
  1601. //:(layer of voxels)
  1602. V_3 _A_ = V_3( _-_ , _-_ , _-_ );
  1603. V_3 _B_ = V_3( M_X , _-_ , _-_ );
  1604. V_3 _C_ = V_3( _-_ , M_Y , _-_ );
  1605. V_3 _D_ = V_3( M_X , M_Y , _-_ );
  1606.  
  1607. //:BOTTOM LAYER OF PIXELS OF VOXEL VOLUME
  1608. //:(Incluseive Math. We are inside the )
  1609. //:(last layer of pixels of the last )
  1610. //:(layer of voxels. )
  1611. V_3 _E_ = V_3( _-_ , _-_ , M_Z );
  1612. V_3 _F_ = V_3( M_X , _-_ , M_Z );
  1613. V_3 _G_ = V_3( _-_ , M_Y , M_Z );
  1614. V_3 _H_ = V_3( M_X , M_Y , M_Z );
  1615.  
  1616. /** ************************************ ***
  1617. Take our plane and pretend it is
  1618. the top of a cube that we want to
  1619. get plane in an isometric position to.
  1620. Where the new plane tangents corner _D_
  1621.  
  1622.  
  1623. A------_B_ vec_D_B
  1624. /| \\ \
  1625. / | |\\ \
  1626. / | | \\ vec_D_C <---D
  1627. _C_============_D_ ^
  1628. | |_ _ _ _| || |
  1629. | /E F\ || vec_H_D
  1630. | / \||
  1631. |/ || Corner_Vector:
  1632. G-------------_H_
  1633. *** *** * * * * * * **** * * * * * * *** **/
  1634.  
  1635. /** Edge Vectors **/
  1636.  
  1637. V_3 vec_C_D = normalize( _D_ - _C_ );
  1638. V_3 vec_D_C = normalize( _C_ - _D_ );
  1639. V_3 vec_D_B = normalize( _B_ - _D_ );
  1640. V_3 vec_H_D = normalize( _D_ - _H_ );
  1641. V_3 vec_D_H = normalize( _H_ - _D_ );
  1642.  
  1643. /** *** * * * * * * **** * * * * * * *** ***
  1644. Use Corner_Vector to calculate a 3/4
  1645. perspective plane that tangents _D_.
  1646. *** ************************************ **/
  1647. /** ************************************ ***
  1648.  
  1649. X axis vector is pretty easy because the
  1650. camera X axis does not move in the Z
  1651. direction.
  1652. ^ /
  1653. | / ^
  1654. A-------B / | a_x Is Average
  1655. | | / |
  1656. | | / vec_D_B
  1657. C-------D--> vec_C_D ----->
  1658. /
  1659. /
  1660. /<-- goal is THIS line for X-axis.(a_x)
  1661. /
  1662. *** *** * * * * * * **** * * * * * * *** **/
  1663. #define _X_ vec_C_D
  1664. #define _Y_ vec_D_B
  1665. V_3 a_x =normalize(
  1666.  
  1667. /** 45 degree line on XY plane **/
  1668. ( _X_ + _Y_ ) / 2.0
  1669.  
  1670. );;
  1671. #undef _X_
  1672. #undef _Y_
  1673. /** *** * * * * * * **** * * * * * * *** ***
  1674.  
  1675. Y axis vector is a bit tricky because it
  1676. moves on all axis(es). XYZ.
  1677.  
  1678. +--B If we average vec_D_C & vec_D_B
  1679. |\ | To get a 45 degree on the XY plane,
  1680. | \| we can then tilt that vector up
  1681. C--D by 45 degrees by averaging it
  1682. | with vec_H_D
  1683. |
  1684. H
  1685.  
  1686. *** ************************************ **/
  1687.  
  1688. //: a_y: Axis_Y
  1689. #define _X_ vec_D_C
  1690. #define _Y_ vec_D_B
  1691. #define _Z_ vec_H_D
  1692. V_3 a_y =normalize(
  1693.  
  1694. (
  1695. normalize( (_X_ + _Y_)/2.0 )
  1696. + ( _Z_ )
  1697. ) /2.0
  1698. );;
  1699. #undef _X_
  1700. #undef _Y_
  1701. #undef _Z_
  1702.  
  1703.  
  1704. /** Looking into the voxel volume from **/
  1705. /** a 3/4 isometric direction. **/
  1706. V_3 a_z = normalize(
  1707. ( vec_D_C + vec_D_B + vec_D_H ) / 3.0
  1708. );;
  1709.  
  1710. /** ************************************ ***
  1711.  
  1712. We can now use point-normal form to
  1713. build our camera polygon. We will start
  1714. from point _D_ and walk HALFWAY the
  1715. WIDTH in both directions on our altered
  1716. x-axis vector( a_x ) and HALFWAY the
  1717. HEIGHT in both directions on our altered
  1718. y-axis vector( a_y ).
  1719.  
  1720. HEIGHT: The height of our camera plane.
  1721. WIDTH: The width of our camera plane.
  1722.  
  1723. P_X +---+
  1724. +------+------+ | |
  1725. | | | +---+---+
  1726. N_Y +---- _D_ ----+ P_Y |_D_|
  1727. | | | +---+---+
  1728. +------+------+ | |#DIA_CAMCENTER#
  1729. N_X +---+
  1730.  
  1731. #CAMCENTER#:
  1732. In order for the camera to be 100%
  1733. centered, it may be necessary to
  1734. squash or stretch the camera by 1
  1735. pixel IF the camera is NOT an odd
  1736. number of pixels on that axis.
  1737. SEE_DIAGRAM[ #DIA_CAMCENTER# ]
  1738.  
  1739. +0 +1 +2 +2.5 +0 +1 +2 +3
  1740. [D] [+] || [+]
  1741. [ ][ ][ ][ ][ ] [ ][ ][ ][ ][ ][ ]
  1742. |<---- 5 ---->| |<------ 6 ----->|
  1743.  
  1744. *** ************************************ **/
  1745.  
  1746. #define ZOOMED_IN_CAMERA_2020_11_26 ( 1 )
  1747. float H_W ; //:H_W:Halfway_Width
  1748. float H_H ; //:H_H:Halfway_Height
  1749. if( ZOOMED_IN_CAMERA_2020_11_26 >= 1 ){
  1750.  
  1751. F32 npm = GET_npm_USE_npx_npy_npz(
  1752. NPX,NPY,NPZ);;
  1753.  
  1754. /** Display Size Of A Single Voxel **/
  1755. /** In Terms Of PIXELS/FRAGS **/
  1756. F32 zoo_mul =( 128.0 );
  1757. F32 zoo_div =( zoo_mul / npm );
  1758.  
  1759. /** Camera surface smaller than **/
  1760. /** client viewport means zoomed in **/
  1761. //: H_W = ( F32(TPX) / 2.0 );
  1762. //: H_H = ( F32(TPY) / 2.0 );
  1763.  
  1764. H_W = ( iResolution.x / 2.0 );
  1765. H_H = ( iResolution.y / 2.0 );
  1766.  
  1767. H_W = ( H_W / zoo_div );
  1768. H_H = ( H_H / zoo_div );
  1769.  
  1770. }else
  1771. if( ZOOMED_IN_CAMERA_2020_11_26 <= 0 ){
  1772.  
  1773. /** Camera surface exactly same size **/
  1774. /** as client viewport means no zoom.**/
  1775. H_W = ( iResolution.x / 2.0 );
  1776. H_H = ( iResolution.y / 2.0 );
  1777.  
  1778. };;
  1779. #undef ZOOMED_IN_CAMERA_2020_11_26
  1780.  
  1781. /** To be pixel-perfect, floor and ceil **/
  1782. /** need to be used. This is an OCD **/
  1783. /** optimization that can probably **/
  1784. /** be removed without noticable **/
  1785. /** difference in the result. **/
  1786. //- P_X = floor( _D_ + ( a_x * H_W ) ); -//
  1787. //- N_X = ceil( _D_ - ( a_x * H_W ) ); -//
  1788. //- P_Y = floor( _D_ + ( a_y * H_H ) ); -//
  1789. //- N_Y = ceil( _D_ - ( a_y * H_H ) ); -//
  1790. //+ We can't do it this way, because the +//
  1791. //+ plane is not aligned with our native +//
  1792. //+ XYZ axis. +//
  1793. //+ What I mean is we can't get the top +//
  1794. //+ left corner by saying: +//
  1795. //+ vec3( N_Y.x , P_X.y , _D_.z ) +//
  1796. /** ************************************ ***
  1797. RASTER_GRAPHICS_STYLE_TOP_LEFT_ORIGIN
  1798. \
  1799. +----------- +X ------------>
  1800. |
  1801. | _I_ _J_
  1802. | \ P_X /
  1803. | +------+------+ ^
  1804. | | | | |
  1805. +Y N_Y +---- _D_ ----+ P_Y [ -y ]
  1806. | | | | |
  1807. | +------+------+ |
  1808. | / N_X \ |
  1809. V _K_ _L_ |
  1810. |
  1811. <---------[ -x ]------------+
  1812.  
  1813. *** *** * * * * * * **** * * * * * * *** **/
  1814.  
  1815. V_3 _I_ = _D_ - ( a_x * H_W )
  1816. - ( a_y * H_H ) ;;
  1817.  
  1818. V_3 _J_ = _D_ + ( a_x * H_W )
  1819. - ( a_y * H_H ) ;;
  1820.  
  1821. V_3 _K_ = _D_ - ( a_x * H_W )
  1822. + ( a_y * H_H ) ;;
  1823.  
  1824. V_3 _L_ = _D_ + ( a_x * H_W )
  1825. + ( a_y * H_H ) ;;
  1826.  
  1827. /** ************************************ **/
  1828. #define USE_ANIMATED_DOLLY_FOR_DEBUG ( 1 )
  1829. if( USE_ANIMATED_DOLLY_FOR_DEBUG >= 1 ){
  1830.  
  1831. F32 max_dolly =max(
  1832. F32(TPX)
  1833. ,
  1834. max(
  1835. F32(TPY)
  1836. ,
  1837. F32(TPZ)
  1838. )
  1839. );;
  1840.  
  1841. F32 spd=( iTime*0.10 ); /**spd==SPEED**/
  1842. F32 pos_cos=( (cos( spd )/2.0)+0.5 );
  1843. F32 neg_cos=( (cos( spd )/2.0)-0.5 );
  1844.  
  1845. F32 dolly_amount =(
  1846. pos_cos * max_dolly
  1847. );;
  1848.  
  1849. _I_ += ( a_z * dolly_amount );
  1850. _J_ += ( a_z * dolly_amount );
  1851. _K_ += ( a_z * dolly_amount );
  1852. _L_ += ( a_z * dolly_amount );
  1853.  
  1854. };;
  1855. #undef USE_ANIMATED_DOLLY_FOR_DEBUG
  1856.  
  1857. V_3 I_J = sdf_i3d( _I_ , _J_ , f_p.x );
  1858. V_3 K_L = sdf_i3d( _K_ , _L_ , f_p.x );
  1859. rwC = sdf_i3d( I_J , K_L , f_p.y );
  1860.  
  1861. //:#POSITIVE_Z_DIVES_INTO_SCREEN#://
  1862. rwN = normalize( a_z );
  1863.  
  1864. rwC_AND_rwN.rwC = rwC;
  1865. rwC_AND_rwN.rwN = rwN;
  1866. return( rwC_AND_rwN );
  1867. }
  1868. #undef _0_
  1869. #undef _
  1870. //:==========:f_p_CTO_rwC_AND_rwN_CAMTYPE_OGP_34D://
  1871. //:f_p_CTO_rwC_AND_rwN_CAMTYPE_T3O_AAZ:==========://
  1872.  
  1873. RWC_AND_RWN
  1874. f_p_CTO_rwC_AND_rwN_CAMTYPE_T3O_AAZ(
  1875. V_2 f_p /** 2 dimensional percentage **/
  1876. )
  1877. {
  1878. RWC_AND_RWN
  1879. rwC_and_rwN;
  1880.  
  1881. //:TODO: Logic.
  1882.  
  1883. return( rwC_and_rwN );
  1884.  
  1885. }
  1886.  
  1887. //:==========:f_p_CTO_rwC_AND_rwN_CAMTYPE_T3O_AAZ://
  1888. //:f_p_CTO_rwC_AND_rwN_CAMTYPE_T3I_AAZ:==========://
  1889. /** TAGS[ t3i_aaz : t3i:aaz ] **/
  1890. #define RWC rwC_and_rwN.rwC
  1891. #define RWN rwC_and_rwN.rwN
  1892.  
  1893. RWC_AND_RWN
  1894. f_p_CTO_rwC_AND_rwN_CAMTYPE_T3I_AAZ(
  1895. V_2 f_p /** 2 dimensional percentage **/
  1896. )
  1897. {
  1898. RWC_AND_RWN
  1899. rwC_and_rwN;
  1900.  
  1901. F32 pos_cos=(cos(iTime)+1.0) / 2.0 ;
  1902.  
  1903. #define F float
  1904. #define M max
  1905. F32 N_T = M( M( F(NTX),F(NTY) ),F(NTZ) );
  1906. F32 N_P = M( M( F(NPX),F(NPY) ),F(NPZ) );
  1907. F32 rad =( N_T * N_P ) * 2.0 * pos_cos;
  1908. #undef F
  1909. #undef M
  1910.  
  1911. //: 123456789
  1912. F32 PI2 = ( 3.141592653 * 2.0 );
  1913. F32 hig = ( 400.0 ); //:Cylinder Height.
  1914.  
  1915. F32 pop = f_p.x ; //: Percent_On_Path
  1916. V_2 c_n ; //: Circle_Normal
  1917. F32 ang = pop * PI2 ; //: Angle
  1918. RWC.x = c_n.x = (0.0+rad) +cos(ang)*rad;
  1919. RWC.y = c_n.y = (0.0+rad) +sin(ang)*rad;
  1920. RWC.z = hig * f_p.y ;
  1921.  
  1922. RWN.x = 0.0 - c_n.x;
  1923. RWN.y = 0.0 - c_n.y;
  1924. RWN.z = 0.0; //:Perpendicular To Z axis.
  1925.  
  1926. return( rwC_and_rwN );
  1927. }
  1928.  
  1929. #undef RWC
  1930. #undef RWN
  1931. //:==========:f_p_CTO_rwC_AND_rwN_CAMTYPE_T3I_AAZ://
  1932. //:f_p_CTO_rwC_AND_rwN_CAMTYPE_S3I_AAZ:==========://
  1933. /** TAGS[ s3i_aaz : s3i:aaz ] **/
  1934. #define RWC rwC_and_rwN.rwC
  1935. #define RWN rwC_and_rwN.rwN
  1936.  
  1937. RWC_AND_RWN
  1938. f_p_CTO_rwC_AND_rwN_CAMTYPE_S3I_AAZ(
  1939. V_2 f_p /** 2 dimensional percentage **/
  1940. )
  1941. {
  1942. RWC_AND_RWN
  1943. rwC_and_rwN;
  1944.  
  1945. /** Make camera sphere grow and shrink **/
  1946. F32 pos_cos=(cos(iTime/8.0)+1.0) / 2.0 ;
  1947.  
  1948. #define F float
  1949. #define M max
  1950. F32 N_T = M( M( F(NTX),F(NTY) ),F(NTZ) );
  1951. F32 N_P = M( M( F(NPX),F(NPY) ),F(NPZ) );
  1952. F32 rad =( N_T * N_P ) * pos_cos*1.0;
  1953. #undef F
  1954. #undef M
  1955.  
  1956. //: 123456789
  1957. F32 PI2 = ( 3.141592653 * 2.0 );
  1958. F32 hig = ( rad*2.0); //:Cylinder Height.
  1959.  
  1960. F32 pop = f_p.x ; //: Percent_On_Path
  1961. V_2 c_n ; //: Circle_Normal
  1962. F32 ang = pop * PI2 ; //: Angle
  1963.  
  1964. /** TODO: Taper the cylinder at top and **/
  1965. /** bottom at correct rate to **/
  1966. /** create a spherical enclosure. **/
  1967. RWC.z = ( hig * f_p.y ) + rad;
  1968.  
  1969. /** ........ .1234567890 **/
  1970. #define PI 3.1415926535
  1971. F32 per_hig =(
  1972. /** Center is 0% , tips are 100% **/
  1973. ( abs( 0.5 - f_p.y ) ) * 2.0
  1974. );;
  1975.  
  1976. F32 sphere_taper=(
  1977. cos( per_hig * PI/2.0 ) );;
  1978.  
  1979. #define R taper_rad
  1980. F32 taper_rad = rad * sphere_taper;
  1981. RWC.x = c_n.x = (0.0+R) +cos(ang)*R;
  1982. RWC.y = c_n.y = (0.0+R) +sin(ang)*R;
  1983. #undef R
  1984.  
  1985. #undef PI
  1986.  
  1987. /** Make normal always look towards **/
  1988. /** the center of our sphere. **/
  1989. RWN.x = 0.0 - RWC.x ;
  1990. RWN.y = 0.0 - RWC.y ;
  1991. RWN.z = 0.0 - RWC.z ;
  1992.  
  1993. return( rwC_and_rwN );
  1994. }
  1995.  
  1996. #undef RWC
  1997. #undef RWN
  1998. //:==========:f_p_CTO_rwC_AND_rwN_CAMTYPE_S3I_AAZ://
  1999. //:f_p_CTO_rwC_AND_rwN:==========================://
  2000. #define ogp_top f_p_CTO_rwC_AND_rwN_CAMTYPE_OGP_TOP
  2001. #define ogp_34d f_p_CTO_rwC_AND_rwN_CAMTYPE_OGP_34D
  2002. #define t3o_aaz f_p_CTO_rwC_AND_rwN_CAMTYPE_T3O_AAZ
  2003. #define t3i_aaz f_p_CTO_rwC_AND_rwN_CAMTYPE_T3I_AAZ
  2004. #define s3i_aaz f_p_CTO_rwC_AND_rwN_CAMTYPE_S3I_AAZ
  2005.  
  2006. RWC_AND_RWN
  2007. f_p_CTO_rwC_AND_rwN(
  2008. V_2 f_p /** 2 dimensional percentage **/
  2009. )
  2010. {
  2011. RWC_AND_RWN
  2012. rwC_and_rwN;
  2013.  
  2014. switch( CAMTYPE ){
  2015.  
  2016. case OGP_TOP :
  2017. rwC_and_rwN = ogp_top( f_p ); break;
  2018.  
  2019. case OGP_34D :
  2020. rwC_and_rwN = ogp_34d( f_p ); break;
  2021.  
  2022. case T3O_AAZ :
  2023. rwC_and_rwN = t3o_aaz( f_p ); break;
  2024.  
  2025. case T3I_AAZ :
  2026. rwC_and_rwN = t3i_aaz( f_p ); break;
  2027.  
  2028. case S3I_AAZ :
  2029. rwC_and_rwN = s3i_aaz( f_p ); break;
  2030.  
  2031. default : /** OGP_TOP **/
  2032. rwC_and_rwN = ogp_top( f_p ); break;
  2033.  
  2034. };;
  2035.  
  2036. return( rwC_and_rwN );
  2037. }
  2038.  
  2039. #undef ogp_top
  2040. #undef ogp_34d
  2041. #undef t3o_aaz
  2042. #undef t3i_aaz
  2043. #undef s3i_aaz
  2044. //:==========================:f_p_CTO_rwC_AND_rwN://
  2045. //:========================:FRAGPER_TO_CAMERA_RAY://
  2046. //:RENDER_SCENE:=================================://
  2047. //:sdf_RenderScene.BUG_001:======================://
  2048.  
  2049. O_K_C4D
  2050. BUG_001(
  2051. /**/ I32 o_k /** Is everything "ok"? **/
  2052. , V_4 c4d /** Color_4_Dimensional **/
  2053. , F32 d_n /** vox_000.vod.dis_nex **/
  2054. )
  2055. {
  2056. O_K_C4D
  2057. o_k_c4d;
  2058.  
  2059. #if( SDF_DEBUG_MODE_ON <= 0 ) //:########://
  2060.  
  2061. /** DO NOTHING **/
  2062.  
  2063. #else //:################################://
  2064.  
  2065. /** if( d_n <= 0.0 we have trouble ) **/
  2066.  
  2067. F32 MF3=intBitsToFloat(0x7f7fFFFF);
  2068. if( 0.0 - 666.0 == d_n ){
  2069.  
  2070. /** Exit On Error **/
  2071. /** #DIST_NEXT_NEVER_ZERO# **/
  2072. c4d=PIX_ERR(ERR_003,c4d,o_k--);
  2073.  
  2074. }else
  2075. if( d_n <= 0.0 ){
  2076.  
  2077. c4d=Flash_rgb_rgb_CTO_c4d(
  2078. U32( 0x2F3F4F )
  2079. , U32( 0x5F6F7F )
  2080. );;
  2081.  
  2082. o_k--;
  2083.  
  2084. }else
  2085. if( d_n == MF3 /** MaxFloat32 **/ ){
  2086.  
  2087. c4d=Flash_rgb_rgb_CTO_c4d(
  2088. U32( 0xBAD001 ) //:LIME
  2089. , U32( 0x100BAD ) //:BLUE
  2090. );;
  2091.  
  2092. o_k--;
  2093.  
  2094. }else
  2095. if( isinf( d_n ) ){
  2096.  
  2097. c4d=Flash_rgb_rgb_CTO_c4d(
  2098. U32( 0xBAD002 ) //:LIME
  2099. , U32( 0x200BAD ) //:BLUE
  2100. );;
  2101.  
  2102. o_k--;
  2103. };;
  2104.  
  2105. #endif //:###############################://
  2106.  
  2107. o_k_c4d.o_k =( o_k );
  2108. o_k_c4d.c4d =( c4d );
  2109. return( o_k_c4d );
  2110. }
  2111.  
  2112. //:======================:sdf_RenderScene.BUG_001://
  2113. //:sdf_RenderScene:==============================://
  2114.  
  2115. /** RMT: Ray_Marching_Tick **/
  2116. REFAC01
  2117. sdf_RenderScene_RMT_001(
  2118. REFAC01
  2119. refac01
  2120. )
  2121. {
  2122. //:RAY_MARCH_LOOP:-----------------------://
  2123.  
  2124. //:March by distance to next voxel:
  2125.  
  2126. //:Point_Normal_Form_To_Get:xyz
  2127. //:#DISTANCE_IS_NOT_CUMULATIVE#
  2128. #define R01 refac01 //:##################://
  2129. #define D_N refac01.vox_000.vod.dis_nex ////
  2130.  
  2131. R01.xyz +=(
  2132. R01.rwC_AND_rwN.rwN //:NORMAL://
  2133. * //: ://
  2134. R01.vox_000.vod.dis_nex //:SCALAR://
  2135. );; //:( D_N )://
  2136.  
  2137. #undef D_N //:##########################://
  2138. #undef R01 //:##########################://
  2139. #define R01 refac01 //:##################://
  2140. #define D_N refac01.vox_000.vod.dis_nex ////
  2141.  
  2142. /** This section must come BEFORE **/
  2143. /** call to: GET_vox_000_USE_xyz_rwN **/
  2144.  
  2145. /** Update Current Origin (xyz)'s **/
  2146. /** dist from original origin (rwC) **/
  2147.  
  2148. R01.xyz_TDF_rwC +=(
  2149.  
  2150. refac01.vox_000.vod.dis_nex
  2151.  
  2152. );;
  2153.  
  2154. /** EXIT, if shot off into space. ** **/
  2155.  
  2156. if( R01.xyz_TDF_rwC > MAX_DIS ){
  2157.  
  2158. //:#BREAK#://
  2159. R01.should_break=U32( 1 );
  2160. return( refac01 /** R01 **/ );
  2161.  
  2162. };;
  2163.  
  2164. #undef D_N //:##########################://
  2165. #undef R01 //:##########################://
  2166. #define R01 refac01 //:##################://
  2167. #define D_N refac01.vox_000.vod.dis_nex ////
  2168.  
  2169. //:@WHATVOX@://
  2170. R01.vox_000 =
  2171. GET_vox_000_USE_xyz_rwN(
  2172. R01.xyz
  2173. , R01.rwC_AND_rwN.rwN
  2174. );;
  2175.  
  2176. /** DEBUG DISTANCE TO NEXT **/
  2177. R01.o_k_c4d = BUG_001(
  2178. R01.o_k_c4d.o_k
  2179. , R01.o_k_c4d.c4d
  2180. , D_N );;
  2181.  
  2182. if( I32(1) != R01.o_k_c4d.o_k ){
  2183.  
  2184. /** Was "break" before extracted **/
  2185. R01.should_break=U32( 1 );
  2186. return( refac01 /** R01 **/ );
  2187.  
  2188. };;
  2189.  
  2190. #undef D_N //:##########################://
  2191. #undef R01 //:##########################://
  2192.  
  2193. //:If voxel is not empty, ray march
  2194. //:inside of the voxel.
  2195. #define _0_ U32( 0 ) //:#####################://
  2196. #define R01 refac01 //:#####################://
  2197. #define HAS refac01.vox_000.voc.has //:######://
  2198. #define VAL refac01.vox_000.voc.val //:######://
  2199.  
  2200. if( I32(1) != R01.o_k_c4d.o_k ){
  2201.  
  2202. /** Do nothing if in an **/
  2203. /** Erroneious state. **/
  2204.  
  2205. }else
  2206. if( HAS > _0_ && _0_ == VAL ){
  2207.  
  2208. //:EMPTY_TILE_INSIDE_MAP_BOUNDS:
  2209. R01.o_k_c4d.c4d = u32_CTO_c4d(U32(
  2210. 0x003300FF ));;
  2211.  
  2212. }else
  2213. if( _0_ == HAS ){
  2214. //:OUT_OF_MAP_BOUNDS:--------------------://
  2215. #define XYZ refac01.xyz
  2216. #define RWC refac01.rwC_AND_rwN.rwC
  2217.  
  2218. //:OUT_OF_MAP_BOUNDS:
  2219. // R01.o_k_c4d.c4d=u32_CTO_c4d(U32(
  2220. // 0x330011FF ));
  2221.  
  2222. R01.xyz_TDF_rwC=(length(XYZ - RWC));
  2223. F32 per=(R01.xyz_TDF_rwC / MAX_DIS);
  2224. F32 inv=( 1.0 - per );
  2225.  
  2226.  
  2227. /** #INTO_THE_BLACK_VOID# **/
  2228. R01.o_k_c4d.c4d=V_4(
  2229. V_3(1)*(inv) , 1.0 );;
  2230.  
  2231. #undef XYZ
  2232. #undef RWC
  2233. //:--------------------:OUT_OF_MAP_BOUNDS://
  2234. }else
  2235. if( HAS > _0_ && VAL > _0_ ){
  2236. #define XYZ refac01.xyz
  2237. #define RWN refac01.rwC_AND_rwN.rwN
  2238. #define TIL_D3D refac01.vox_000.voc.til_d3d
  2239. #define PIX_D3D refac01.vox_000.voc.pix_d3d
  2240.  
  2241. R01.pix_000 = (
  2242. GET_pix_000_USE_xyz_rwN_til_d3d_pix_d3d(
  2243. XYZ,RWN,TIL_D3D,PIX_D3D
  2244. ));;
  2245.  
  2246. /*[FIX]: ALWAYS RETURNS EXIT */
  2247. if( R01.pix_000.exit >= U32(1) ){
  2248.  
  2249. //: c4d=( u32_CTO_c4d(
  2250. //: vox_000.voc.val ) );;
  2251.  
  2252. R01.o_k_c4d.c4d =( vox_000_CTO_c4d(
  2253. /**/ R01.vox_000 ));;
  2254.  
  2255. /** Was "break" before extracted **/
  2256. R01.should_break=U32( 1 );
  2257. return( refac01 /** R01 **/ );
  2258. };;
  2259.  
  2260. #undef XYZ
  2261. #undef RWN
  2262. #undef TIL_D3D
  2263. #undef PIX_D3D
  2264. }else{
  2265.  
  2266. //:SHOULD_NEVER_EXECUTE:
  2267. R01.o_k_c4d.c4d=Flash_rgb_rgb_CTO_c4d(
  2268. U32( 0x404001 ) //:TURTLE_GREEN
  2269. , U32( 0x100404 ) //:BLACK____ISH
  2270. );;
  2271.  
  2272. };;
  2273.  
  2274. #undef _0_ //:#############################://
  2275. #undef R01 //:#############################://
  2276. #undef HAS //:#############################://
  2277. #undef VAL //:#############################://
  2278.  
  2279. /** Don't move the ray anywhere **/
  2280. /** We are going to slice into **/
  2281. /** whatever voxels the camera **/
  2282. /** plane passes through. **/
  2283. if( CFG_SLICE_RENDER >= 1 ){
  2284. #define R01 refac01
  2285.  
  2286. /** Was "break" before extracted **/
  2287. R01.should_break=U32( 1 );
  2288. return( refac01 /** R01 **/ );
  2289.  
  2290. #undef R01
  2291. };;
  2292. //:-----------------------:RAY_MARCH_LOOP://
  2293.  
  2294. return( refac01 );
  2295. }
  2296.  
  2297. V_4 sdf_RenderScene( RWC_AND_RWN rwC_AND_rwN )
  2298. {
  2299. //:PAYLOAD_OBJECT_FOR_RENDER_LOOP:-------://
  2300.  
  2301. REFAC01 refac01; /** REFACTOR_ME_001 **/
  2302.  
  2303. //:-------:PAYLOAD_OBJECT_FOR_RENDER_LOOP://
  2304. //:VARIABLE_SETUP:-----------------------://
  2305. #define R01 refac01
  2306.  
  2307. //:MISC_MEMBERS:---------------------://
  2308.  
  2309. /** Pass it down. **/
  2310.  
  2311. R01.rwC_AND_rwN = rwC_AND_rwN;
  2312.  
  2313. /** xyz's TotalDistanceFrom rwC **/
  2314.  
  2315. R01.xyz_TDF_rwC = ( 0.0 );
  2316.  
  2317. /** xyz is a copy of rwC so that **/
  2318. /** we can alter the origin of **/
  2319. /** the ray march each iteration.**/
  2320.  
  2321. R01.xyz = rwC_AND_rwN.rwC ;
  2322.  
  2323. /** Needed addition now that **/
  2324. /** loop body is extracted into **/
  2325. /** another function. **/
  2326.  
  2327. R01.should_break= U32( 0 ) ;
  2328.  
  2329. //:---------------------:MISC_MEMBERS://
  2330. //:vox_000:--------------------------://
  2331. #define VOC refac01.vox_000.voc
  2332. #define VOD refac01.vox_000.vod
  2333.  
  2334. VOD.dis_nex =( 0.0 );
  2335.  
  2336. VOC.has = uint( 0 ); //:1://
  2337. VOC.val = uint( 0 ); //:2://
  2338. VOC.til_d3d = int( 0 ); //:3://
  2339. VOC.t_x = int( 0 ); //:4://
  2340. VOC.t_y = int( 0 ); //:5://
  2341. VOC.t_z = int( 0 ); //:6://
  2342.  
  2343. #undef VOC
  2344. #undef VOD
  2345. //:--------------------------:vox_000://
  2346. //:pix_000:--------------------------://
  2347. #define PIX refac01.pix_000
  2348.  
  2349. PIX.exit=U32( 0 );
  2350.  
  2351. #undef PIX
  2352. //:--------------------------:pix_000://
  2353. //:o_k_c4d:--------------------------://
  2354. #define C4D refac01.o_k_c4d.c4d
  2355. #define O_K refac01.o_k_c4d.o_k
  2356.  
  2357. /** c4d corret initial value.....**/
  2358. /** cd4 =THE_COLOR_OF_EMPTY_SPACE**/
  2359.  
  2360. O_K =I32( 1 );
  2361. C4D =u32_CTO_c4d( U32(0x123456FF) );
  2362. /**DARK_SKY_BLUE**/
  2363.  
  2364. #undef C4D
  2365. #undef O_K
  2366. //:--------------------------:o_k_c4d://
  2367.  
  2368. #undef R01
  2369. //:-----------------------:VARIABLE_SETUP://
  2370. //:RAY_MARCH_LOOP:-----------------------://
  2371. /** #ABOUT_RAY_MARCH_LOOP# **/
  2372. #define R01 refac01
  2373.  
  2374. //:(RayMarch)March to VOXEL:
  2375. for( int i = 0; i < MAX_STE ; i++ ){
  2376.  
  2377. /** #LOOPTICK_FUNCTION# **/
  2378. R01=( sdf_RenderScene_RMT_001(
  2379. R01 ));;
  2380.  
  2381. if( R01.should_break >= U32(1)){
  2382.  
  2383. break;
  2384.  
  2385. };;
  2386. };;
  2387.  
  2388. #undef R01
  2389. //:-----------------------:RAY_MARCH_LOOP://
  2390.  
  2391.  
  2392. if( CFG_SLICE_RENDER >= 1 ){
  2393. #define T_X refac01.vox_000.voc.t_x
  2394. #define T_Y refac01.vox_000.voc.t_y
  2395. #define T_Z refac01.vox_000.voc.t_z
  2396. #define HAS refac01.vox_000.voc.has
  2397.  
  2398. //:Layer value, 1 or 0
  2399. int lay = I32_MOD( T_Z, 2 );
  2400.  
  2401. //:#MODULO_CHECKER_PATTERN#://
  2402. int chk =(
  2403. I32_MOD( //:<<<<<<<<<<<<<<:SET_003
  2404. I32_MOD( T_Y, 2 ) //:SET_YYY
  2405. + I32_MOD( T_X, 2 ) //:SET_XXX
  2406. , 2
  2407. )
  2408. );;
  2409.  
  2410. if( 0 != 0
  2411. || ( lay < 0 )
  2412. || ( lay > 1 )
  2413. || ( chk < 0 || chk > 1 )
  2414. || ( HAS > uint(1) )
  2415. ){
  2416. #define C4D refac01.o_k_c4d.c4d //:##://
  2417. #define O_K refac01.o_k_c4d.o_k //:##://
  2418.  
  2419. //: _0x010101_ & _0x101010_
  2420. C4D=PIX_ERR(ERR_001,C4D,O_K--);
  2421.  
  2422. #undef C4D //:#####################://
  2423. #undef O_K //:#####################://
  2424. };;
  2425.  
  2426.  
  2427. F32 M =( 255.0); //:Max RGB value.
  2428. F32 X =( 1.0 ); //:FOR_DEBUGGING_COLORS
  2429. //:F32 ...........; Replace with "_"
  2430. //:F32 ...........; when done debugging.
  2431. F32 a =( 1.0 ); //:ALPHA
  2432. F32 _ =( 0.0 );
  2433. F32 g =( F32(0x33)/M ); //:DARK-GREY
  2434. F32 G =( F32(0x38)/M );
  2435. F32 w =( F32(0xE5)/M ); //:WHITE-GREY
  2436. F32 W =( F32(0xF2)/M );
  2437.  
  2438. V_4 _0x333333_ =V_4(g,g,g,a);
  2439. V_4 _0x383838_ =V_4(G,G,G,a);
  2440. V_4 _0xE5E5E5_ =V_4(w,w,w,a);
  2441. V_4 _0xF2F2F2_ =V_4(W,W,W,a);
  2442. V_4 _0x003300_ =V_4(_,g,_,a);
  2443. V_4 _0x003800_ =V_4(_,G,_,a);
  2444. V_4 _0x00E500_ =V_4(_,w,_,a);
  2445. V_4 _0x00F200_ =V_4(_,W,_,a);
  2446.  
  2447. V_4 tab_000[8]=V_4[8](
  2448. //:OUT OF BOUNDS: //:HAS?
  2449. _0x333333_ , _0x383838_ //:LAY0
  2450. ,_0xE5E5E5_ , _0xF2F2F2_ //:LAY1
  2451. //: | CHK0 | CHK1 |::::::::://
  2452.  
  2453. //:IN BOUNDS: //:HAS?
  2454. ,_0x003300_ , _0x003800_ //:LAY0
  2455. ,_0x00E500_ , _0x00F200_ //:LAY1
  2456. //: | CHK0 | CHK1 |::::::::://
  2457. );;
  2458.  
  2459. I32 pik = (
  2460. (4 * ( HAS >= uint(1) ? 1 : 0 ))
  2461. + (2 * lay ) //: LAY0 -or- LAY1
  2462. + (1 * chk ) //: CHK0 -or- CHK1
  2463. );;
  2464.  
  2465. #define C4D refac01.o_k_c4d.c4d //:##://
  2466. #define O_K refac01.o_k_c4d.o_k //:##://
  2467.  
  2468. if( pik < 0 || pik >= 8 ){
  2469. C4D=PIX_ERR(ERR_002,C4D,O_K--);
  2470. };;
  2471.  
  2472. //:TODO: Why is not rendering as
  2473. //: checker?
  2474. if( 1 == O_K ){
  2475. C4D = tab_000[ pik ];
  2476. };;
  2477.  
  2478. #undef C4D //:#####################://
  2479. #undef O_K //:#####################://
  2480.  
  2481. #undef T_X //:##########################://
  2482. #undef T_Y //:##########################://
  2483. #undef T_Z //:##########################://
  2484. #undef HAS //:##########################://
  2485. }else{ /** CFG_SLICE_RENDER ? **/
  2486.  
  2487. //:DEBUG_ONLY: c4d=V_4(1,1,1,1);
  2488.  
  2489. };;
  2490.  
  2491. return( refac01.o_k_c4d.c4d );
  2492. }
  2493.  
  2494. //:==============================:sdf_RenderScene://
  2495. //:=================================:RENDER_SCENE://
  2496.  
  2497. //:11111111111111111111111111111111111111111111111111://
  2498. //:00000000000000000000000000000000000000000000000000://
  2499.  
  2500. void mainImage(
  2501. out vec4 fragColor
  2502. , in V_2 fragCoord
  2503. )
  2504. {
  2505.  
  2506. #define R_Y iResolution.y
  2507. V_2 f_c = V_2(
  2508. //:( FLIP? ) ( Discrete XY ) ://
  2509. ( 0.0 ) + ( fragCoord.x - 0.5 )
  2510. , (R_Y-1.0) - ( fragCoord.y - 0.5 )
  2511. );;
  2512. #undef R_Y
  2513. V_2 f_p = f_c_CTO_f_p( f_c );
  2514.  
  2515.  
  2516. //:CAMERA_RAY_FOR_CURRENT_PIXEL:-------------://
  2517.  
  2518. /** The coordinate and direction of the **/
  2519. /** camera ray [rwC,rwN] are closely **/
  2520. /** related, so return them using the **/
  2521. /** same function. This will save **/
  2522. /** processing power when we decide **/
  2523. /** to create a camera lense that **/
  2524. /** is a 360 degree cylinder around **/
  2525. /** an object. (for fun) **/
  2526.  
  2527. RWC_AND_RWN
  2528. rwC_AND_rwN;
  2529.  
  2530. rwC_AND_rwN = f_p_CTO_rwC_AND_rwN( f_p );
  2531.  
  2532. //:-------------:CAMERA_RAY_FOR_CURRENT_PIXEL://
  2533.  
  2534. fragColor = sdf_RenderScene( rwC_AND_rwN );
  2535.  
  2536. }
  2537. //:00000000000000000000000000000000000000000000000000://
  2538. //:DOCUMENTATION:====================================://
  2539. /** ************************************************ ***
  2540. ABBREVIATIONS:
  2541.  
  2542. f : fragment
  2543. p : percent (Never Position, use C for coord)
  2544. c : coordinate
  2545. r : ray
  2546. n : normal, for directions.
  2547. d : distance. NEVER DIRECTION.( use: n:normal )
  2548.  
  2549. IDENTIFIERS:
  2550.  
  2551. CTO: Convert_TO
  2552. rwC: RayWorldCoord
  2553. rwN: RayWorldNormal
  2554. f_p: FragPercent
  2555. f_c: FragCoord (With Discrete Pixel Coords)
  2556. (instead of pixel centers )
  2557. dad: Distance_And_inDEX
  2558. Index is 1D index of XYZ voxel tile
  2559. coordinate.
  2560. vat: Voxel_Array__of__Tiles
  2561. c4d: Color_4_Dimensional(RGBA)
  2562.  
  2563. FUNCTIONS:
  2564.  
  2565. f_c_CTO_f_p : FragmentCoord -CTO- FragPercent
  2566. f_c_CTO_per : USE[ f_c_CTO_f_p ]
  2567. sdf_i3d : Interpolate_Two_3D_Points
  2568.  
  2569. CTRL_F_INDEX: (CTRL+F:INDEX, Search Phrases)
  2570. (CTR + F)<-- Spaces Between Letters
  2571.  
  2572. Which Voxel Am I On? .... SEE[ @WHATVOX@ ]
  2573. What Voxel Am I On? ..... SEE[ @WHATVOX@ ]
  2574. Find Current Voxel ...... SEE[ @WHATVOX@ ]
  2575. pix_3d3 ................. TYPOFIX[ pix_d3d ]
  2576. til_3d3 ................. TYPOFIX[ til_d3d ]
  2577. cd4 ..................... TYPOFIX[ c4d ]
  2578. m3d ..................... TYPOFIX[ m2d ]
  2579. Voxel To Color Debug .... SEE[ @VOXBUGCOLOR@ ]
  2580. gradient,Gradient........ SEE[ @VOXBUGCOLOR@ ]
  2581. which voxel are we in ... SEE[ @WHATVOX@ ]
  2582. SDF_PRJ_MAX.............. TYPOFIX[ SDF_PRO_MAX ]
  2583. generic ........ 001[ #STACK_ADDRESS_WORKINGS# ]
  2584. generic ........ 002[ GET_pix_000... could_use ]
  2585. hex-to-color-c4d ........ SEE[ u32_CTO_c4d ]
  2586.  
  2587. EXTRACTED_BLOCK_COMMENTS:
  2588.  
  2589. #ABOUT_RAY_MARCH_LOOP###########################
  2590.  
  2591. Ray marching loop should be able to look
  2592. at the current voxel coordinate returned
  2593. and decide to STOP marching if it wants.
  2594. By stopping immediately without marching
  2595. at all we can make the camera phosphore
  2596. surface a slice plane that renders
  2597. cross sectional views of tilemap data.
  2598.  
  2599. ##########################ABOUT_RAY_MARCH_LOOP##
  2600. #POSITIVE_Z_DIVES_INTO_SCREEN###################
  2601.  
  2602. Positive Z is further back into screen.
  2603. This way to help normalize voxel grid math.
  2604.  
  2605. ###################POSITIVE_Z_DIVES_INTO_SCREEN#
  2606. #FIND_POINT_ON_SCREEN_PLANE#####################
  2607.  
  2608. ORIGINAL_COMMENT:
  2609.  
  2610. Polygon in 3d space to serve as the
  2611. phosphor surface the CRT monitor
  2612. electrons will be projected onto.
  2613. Could probably use a mat4 for this.
  2614.  
  2615. MORE_INFORMATION_IN_RETROSPECT:
  2616.  
  2617. "Screen Plane" is also known as
  2618. "CRT Phospore" or "PHO" for short.
  2619. This is a plane put into 3D space that
  2620. represents the pixels of the client
  2621. viewport (physical monitor).
  2622.  
  2623. The "IMAGE" plane from this diagram:
  2624. https://tinyurl.com/IMAGE-PLANE
  2625.  
  2626. #####################FIND_POINT_ON_SCREEN_PLANE#
  2627. #MODULO_CHECKER_PATTERN#########################
  2628.  
  2629. // Checker pattern value, 1 or 0. //
  2630. // Combine Sets so that they create //
  2631. // a checkerboard of odd/even values, //
  2632. // and then convert even to 0 and //
  2633. // odd to 1. //
  2634. // //
  2635. // SET_YYY:[ 0 1 0 1 0 1 0 ] //
  2636. // SET_XXX:[ 0 1 0 1 0 1 0 ] //
  2637. // //
  2638. // SET_XXX: [ 0 1 0 1 0 1 0 ] //
  2639. // | | | | | | | //
  2640. // SET_YYY:[ 0 ]- 0 1 0 1 0 1 0 //
  2641. // [ 1 ]- 1 2 1 2 1 2 1 //
  2642. // [ 0 ]- 0 1 0 1 0 1 0 //
  2643. // [ 1 ]- 1 2 1 2 1 2 1 //
  2644. // [ 0 ]- 0 1 0 1 0 1 0 //
  2645. // [ 1 ]- 1 2 1 2 1 2 1 //
  2646. // [ 0 ]- 0 1 0 1 0 1 0 //
  2647. int chk =(
  2648. I32_MOD( // <<<<<<<<<<<<<< SET_003
  2649. I32_MOD( T_Y, 2 ) // SET_YYY
  2650. + I32_MOD( T_X, 2 ) // SET_XXX
  2651. , 2
  2652. )
  2653. );;
  2654.  
  2655. #########################MODULO_CHECKER_PATTERN#
  2656. #CONSISTENT_VOXEL_COORDS########################
  2657.  
  2658. The tilemap math for calculating what
  2659. [voxel/tile] we are inside of is
  2660. geometrically consistent, even when
  2661. given NEGATIVE numbers.
  2662.  
  2663. Meaning: The FIRST PIXELS of any
  2664. [tile/voxel] are in the same
  2665. relative position.
  2666.  
  2667. +-+-----+-+-----+-+-----+-+-----+
  2668. | | -1 | | 0 | | +1 | | +2 |
  2669. | | | | | | | | |
  2670. | +-----| +-----| +-----| +-----+
  2671. +-------+-------+-------+-------+
  2672.  
  2673. +-+
  2674. | | <--- The first edge of pixels for
  2675. | | [voxel/tile] seen on the X/Y
  2676. | +-----| axis.
  2677. +-------+
  2678. ########################CONSISTENT_VOXEL_COORDS#
  2679. #NEXT_VOXEL_BOUNDING_VOLUME#####################
  2680.  
  2681. Assuming vectors are moving in a positive
  2682. direction, the intersection point to
  2683. next voxel MUST be within the bounds of
  2684. the CURRENT VOXEL + One Pixel All Around.
  2685.  
  2686. Because we know the DIRECTION of the
  2687. ray vector, we don't need a bounding volume
  2688. and can just check that the respective
  2689. X,Y,Z bounding planes have
  2690. not been exceeded.
  2691.  
  2692. +--------------------+--------------------+
  2693. | | |
  2694. | +- - - - - -+ | +- - - - - -+ |
  2695. | | | | | | |
  2696. | | |
  2697. | | | | | | |
  2698. | | |
  2699. | | | | | | |
  2700. | +- - - - - -+ | +- - - - - -+ |
  2701. 111111111111111111111111111 |
  2702. 1 +--------------------+-1------------------+
  2703. 1 | | 1 |
  2704. 1 | +- - - - - -+ | 1 +- - - - - -+ |
  2705. 1 | | | | 1 | | |
  2706. 1 | | 1 |
  2707. 1 | | CV | | 1 | | |
  2708. 1 | (CurVoxel) | 1 |
  2709. 1 | | | | 1 | | |
  2710. 1 | +- - - - - -+ | 1 +- - - - - -+ |
  2711. 1 | | 1 |
  2712. 1 +--------------------+-1------------------+
  2713. 111111111111111111111111111
  2714.  
  2715. #####################NEXT_VOXEL_BOUNDING_VOLUME#
  2716. #VOX_MAR_ABOUT##################################
  2717.  
  2718. VOX_MAR: ( VOXel_MARch )
  2719.  
  2720. Holds information about ray
  2721. marching WITHIN a single voxel.
  2722.  
  2723. REFACTORED[ VOX_MAR ]TO[ PIX_000 ]
  2724. Because we need to do the analogous
  2725. of what we did when marching into
  2726. voxel space using VOX_000, just this
  2727. time marching into pixel space and
  2728. filling PIX_000 struct.
  2729.  
  2730. ##################################VOX_MAR_ABOUT#
  2731. #DISTANCE_IS_NOT_CUMULATIVE#####################
  2732.  
  2733. WRONG: xyz = rwC + ( rwN * D_N );
  2734. RIGHT: xyz = xyz + ( rwN * D_N );
  2735.  
  2736. The distance is NOT cumulative. Our ray
  2737. marching is not anchored to the original
  2738. ray world coordinate ( rwC ).
  2739.  
  2740. Reason:
  2741. Collision with the first pixel of
  2742. the next voxel is PIXEL PERFECT and
  2743. if[ D_N ]were a cumulative distance
  2744. over multiple iterations we would
  2745. probably see weird artifacts as slight
  2746. rounding errors compound.
  2747.  
  2748. Thus do NOT anchor to[ rwC ]but
  2749. rather make a new origin location at
  2750. [ xyz ]each loop iteration.
  2751.  
  2752. Think: Folds in orgami.
  2753.  
  2754. #####################DISTANCE_IS_NOT_CUMULATIVE#
  2755. #DIST_NEXT_NEVER_ZERO###########################
  2756.  
  2757. Even if you are 1 pixel away from the next
  2758. voxel, the distance to the next voxel should
  2759. NEVER be zero. It should always be a
  2760. POSITIVE NON-ZERO value.
  2761.  
  2762. If this is NOT the case, your point-normal
  2763. form ray marching will fail.
  2764.  
  2765. ###########################DIST_NEXT_NEVER_ZERO#
  2766. #TRAP_VALUE_MUST_BE_NEG_666#####################
  2767.  
  2768. Using ( 0.0 - 666.0 ) as a trap value
  2769. in our code that determines the distance
  2770. to the next voxel. If you detect (-666.0)
  2771. in your ray march loop, it means that
  2772. the distance to the next voxel was never
  2773. set. Distance to next voxel should ALWAYS
  2774. be NON-ZERO and POSITIVE.
  2775.  
  2776. #####################TRAP_VALUE_MUST_BE_NEG_666#
  2777. #PIXEL_PROBABILITY_CLOUD########################
  2778.  
  2779. [TODO](MAYBE)
  2780.  
  2781. We should probably have 1 pixel equal to
  2782. 3 native frag coords. That way if you
  2783. are in the CENTER of the pixel, you know
  2784. you don't need to alias. But if you are
  2785. on one of the boarder edges, you know
  2786. you need to use some aliasing.
  2787.  
  2788. [ONE FRAG COORD]
  2789. _|_
  2790. / \
  2791. + + X: CENTER, no aliasing
  2792. | | required.
  2793. V V
  2794. +---+---+---+ <--+
  2795. | | | | \
  2796. +---+---+---+ \
  2797. | | X | | +--[ ONE PIXEL ]
  2798. +---+---+---+ /
  2799. | | | | /
  2800. +---+---+---+ <--+
  2801.  
  2802. ########################PIXEL_PROBABILITY_CLOUD#
  2803. #VOXEL_EDGE_COLOR###############################
  2804.  
  2805. When percent(per) is zero the edges are
  2806. BLACK and blend with background. That is
  2807. not very useful for debugging, so lets
  2808. give the edges a useful color coding to
  2809. identify which planes of the voxel are
  2810. intersecting at that edge.
  2811.  
  2812.  
  2813. +--.--+--.--+
  2814. 1\ \ \ [X]: X_Plane: RED
  2815. 1 \ --[Z]-- \ [Y]: Y_PLANE: GREEN
  2816. 1 \ \ \ [Z]: Z_PLANE: BLUE
  2817. 1 +--.--+--.--+
  2818. 1[X]2 3 1: Edge 1, YELLOW (R+G)
  2819. + 2 3 2: Edge 2, YELLOW (R+G)
  2820. \ 2 [Y] 3 3: Edge 3, YELLOW (R+G)
  2821. \ 2 3
  2822. \2 3
  2823. +--.--+--.--+
  2824.  
  2825. +--.--+--.--+ 4: Edge 4, MAGENTA (R+B)
  2826. |4 \ \ 5: Edge 5, CYAN (G+B)
  2827. | 4 --[Z]-- \ 6: Edge 6, YELLOW (R+G)
  2828. | 4 \ \
  2829. | +55555555555+
  2830. |[X]6 | (Edge #'s Are Arbitrary)
  2831. + 6 | (and do NOT reflect )
  2832. \ 6 [Y] | (values in our code. )
  2833. \ 6 |
  2834. \6 | (Aritrary as in for )
  2835. +--.--+--.--+ (illustrative purposes.)
  2836.  
  2837. ###############################VOXEL_EDGE_COLOR#
  2838. #NO_ELSE_FOR_EDGE_COLORING######################
  2839.  
  2840. Statement for calculating edge colors
  2841. should NOT have "else" or "if else"
  2842. because 2 planes intersect at edges
  2843. and 3 planes intersect at vertex.
  2844.  
  2845. THUS: EDGES : 2ndary(secondary) colors.(CMY)
  2846. VERTEX: WHITE (R+G+B)
  2847.  
  2848. ######################NO_ELSE_FOR_EDGE_COLORING#
  2849. #STRATA_OF_2D_TILEMAPS##########################
  2850.  
  2851. We abstract the 3D tilemap (voxelmap) data
  2852. as a series of 2-dimensional tile maps
  2853. that are stacked on top of each other.
  2854.  
  2855. Because positive Z moves DOWN INTO THE
  2856. MONITOR, larger Z-layers go further
  2857. back into the screen.
  2858.  
  2859.  
  2860. U32
  2861. VAT[ NTX * NTY * NTZ ]= U32[ 8 * 4 * 7 ](
  2862.  
  2863. //: Z == 0 === First 2D TileMap
  2864.  
  2865. //: 1 2 3 4 5 6 7 8 --- -------------
  2866. _,_,_,_,_,_,_,_, //: 1 | ^
  2867. _,_,_,_,_,_,_,_, //: 2 | Z == 0 |
  2868. _,_,_,_,_,_,_,_, //: 3 | |
  2869. _,_,_,_,_,_,_,_, //: 4 | |
  2870. //: --- |
  2871. //: 1 2 3 4 5 6 7 8 --- |
  2872. _,_,_,_,_,_,_,_, //: 1 | TILEMAP_STRATA
  2873. _,_,_,_,_,_,_,_, //: 2 | |
  2874. _,_,_,_,_,_,_,_, //: 3 | Z == 1 |
  2875. _,_,_,_,_,_,_,_, //: 4 | |
  2876. //: --- |
  2877. //: 1 2 3 4 5 6 7 8 --- |
  2878. _,_,_,_,_,R,_,_, //: 1 | |
  2879. _,_,_,_,Y,_,_,_, //: 2 | Z == 2 |
  2880. _,_,_,M,_,_,_,_, //: 3 | |
  2881. _,_,C,_,_,_,_,_, //: 4 | V
  2882. //: --- -------------
  2883.  
  2884. );
  2885.  
  2886. //: Z == 2 === First 2D TileMap
  2887.  
  2888. ##########################STRATA_OF_2D_TILEMAPS#
  2889. #BACK_SLASH_COMMENT_FUCKERY#####################
  2890.  
  2891. The use of "\" in a comment line seems
  2892. to be erroneously interpreted as a newline.
  2893.  
  2894. Example: Below wil NOT compile, even
  2895. though it is syntactically correct.
  2896.  
  2897. U32
  2898. VAT[ NTX * NTY * NTZ ]= U32[ 8 * 4 * 1 ](
  2899.  
  2900. //: 1 2 3 4 5 6 7 8
  2901. _,_,_,_,_,_,_,_, //: 1 \
  2902. _,_,_,_,_,_,_,_, //: 2 \__ Z == 0
  2903. _,_,_,_,_,_,_,_, //: 3 /
  2904. _,_,_,_,_,_,_,_, //: 4 /
  2905.  
  2906. );
  2907.  
  2908. #####################BACK_SLASH_COMMENT_FUCKERY#
  2909. #MINUS_EPSILON##################################
  2910.  
  2911. NEG POS
  2912. | |
  2913. V V
  2914. | |
  2915. +---+ +---+
  2916. |_n_| |_p_|
  2917. +-----------++-----------++-----------+
  2918. | | | || | | || | | |
  2919. |---+---+---||---+---+---||---+---+---|
  2920. | |-1 | || | 0 | || |+1 | |
  2921. |---+---+---||---+---+---||---+---+---|
  2922. | | | || | | || | | |
  2923. +-----------++-----------++-----------+
  2924. |_n_| |_p_|
  2925. +---+ +---+
  2926. | |
  2927. ^ ^
  2928. | |
  2929. NEG POS
  2930.  
  2931. We wanted to do the math so tha the bounds
  2932. of the voxel were measured in our plank
  2933. unit of 1-pixel. But that doesn't work.
  2934.  
  2935. BAD__BOUNDS: _n_ & _p_
  2936. GOOD_BOUNDS: NEG & POS
  2937.  
  2938. The POSITIVE bounds work by co-incidence
  2939. when thinking of pixels as discrete
  2940. units without thickness because....
  2941.  
  2942. 0.0 <-- POS == _p_
  2943. |
  2944. +---|||---+
  2945. | |
  2946. | 0 |
  2947. | (_p_) |
  2948. +---|||---+
  2949. |
  2950. 1.0
  2951.  
  2952. However, with the NEGATIVE bounds,
  2953. the discrete math does not co-incidentially
  2954. line up like this.
  2955.  
  2956. 0.0
  2957. |
  2958. +---|||---+
  2959. | |
  2960. | 0 |
  2961. | (_n_) |
  2962. +---|||---+
  2963. |
  2964. 1.0 <-- NEG != _n_
  2965.  
  2966. So, while we would like to keep all of
  2967. our reasoning to conceptual pixels that
  2968. have no thickness and do this:
  2969. ( B == boudary where NEXT voxel is )
  2970.  
  2971. +---+---+---+---+---+ <---+
  2972. | B | B | B | B | B | |
  2973. +---+===========+---+ |
  2974. | B | | | | B | |
  2975. +---|- -+- -+- -|---+ |
  2976. | B | | 0 | | B | +---[WRONG]
  2977. +---|- -+- -+- -|---+ |
  2978. | B | | | | B | |
  2979. +---+===========+---+ |
  2980. | B | B | B | B | B | |
  2981. +---+---+---+---+---+ <---+
  2982.  
  2983. It is actually more like this:
  2984.  
  2985. +--BUT__HERE--+
  2986. | |
  2987. |+--NOTHERE--+|
  2988. || ||
  2989. VV VV
  2990. +---||---+---+---||---+
  2991. | B || B | B | B || B |
  2992. ----++-----------++---- <-- BUT_HERE
  2993. ----++-----------++---- <-- NOT_HERE
  2994. | B || | | || B |
  2995. +---||---+---+---||---+
  2996. | B || | 0 | || B |
  2997. +---||---+---+---||---+
  2998. | B || | | || B |
  2999. ----++-----------++---- <-- NOT_HERE
  3000. ----++-----------++---- <-- BUT_HERE
  3001. | B || B | B | B || B |
  3002. +---||---+---+---||---+
  3003.  
  3004.  
  3005. In other news, a perfect 45 degree angle
  3006. from the center of one voxel is NOT
  3007. an edge case. Because the math for that
  3008. only computes the distance to the next
  3009. voxel, not the VALUES(PLURAL) of the
  3010. next voxel. ( VALUES == VOX_000 instance )
  3011.  
  3012. +===========+
  3013. | B | B | B |
  3014. |---+---+---|
  3015. | B |V_2| B |
  3016. +---+---+---+---|---/---+---|
  3017. | B | B | B | B | / | B | B |
  3018. +---+===========/===========+
  3019. | B | / | B |
  3020. +---| / |---+
  3021. | B | V_1 | B |
  3022. +---| |---+
  3023. | B | | B |
  3024. +---+===========+---+
  3025. | B | B | B | B | B |
  3026. +---+---+---+---+---+
  3027. #DIAGONAL_IS_NOT_AN_EDGE_CASE#
  3028. ( V_1 to V_2 works fine)
  3029. ( V_1 == voxel #1 )
  3030. ( V_2 == voxel #2 )
  3031.  
  3032. ##################################MINUS_EPSILON#
  3033. #ITBIDKW########################################
  3034.  
  3035. ITBIDKW: It works, but I don't know why.
  3036.  
  3037. 1. EPS_X,EPS_Y,EPS_Z, exactly 0.0001
  3038. No smaller, no larger. No fucking clue
  3039. why this magic number works.
  3040.  
  3041. ########################################ITBIDKW#
  3042. #CASH_IN_INDEXES_AT_LAST_MOMENT#################
  3043.  
  3044. NOT:til_val_AND_pix_d3d_CTO_u32_bit
  3045. YES:til_d3d_AND_pix_d3d_CTO_u32_bit
  3046.  
  3047. Why? Because we cannot afford to
  3048. discard LOCATION information at any
  3049. level of nesting if we want the most
  3050. sophisticated levels of nested auto-tiling.
  3051. (NestedAutoTiling~=~FractalAutoTiling)
  3052.  
  3053. For example: If we want a PIXEL within
  3054. a voxel to intelligently
  3055. auto-tile OUTSIDE of it's
  3056. voxel with a pixel of an
  3057. adjacent voxel, we need
  3058. BOTH[ pix_d3d ]AND[ til_d3d ]
  3059.  
  3060. |<-- CURRENT ---->|<-- NEXT_VOXEL-->|
  3061. |<-- 3x3 voxel -->|<-- 3x3 voxel -->|
  3062. +-----+-----+-----+-----+-----+-----+
  3063. | | |
  3064. | | |
  3065. + +-----+-----+-----+-----+ +
  3066. | | AYE | BEE | CEE | DEE | |
  3067. | | --- | --- | --- | --- | |
  3068. + +-----+-----+-----+-----+ +
  3069. | | |
  3070. | | |
  3071. +-----+-----+-----+-----+-----+-----+
  3072.  
  3073. AYE & BEE can auto tile with each other
  3074. by just knowing what[ til_val/vox_val ]
  3075. they are inside of.
  3076.  
  3077. CEE & DEE can auto tile with each other
  3078. by just knowing what[ til_val/vox_val ]
  3079. they are inside of.
  3080.  
  3081. Voxel Value May Determine:
  3082.  
  3083. 1. Pixel Material Type
  3084. 2. Pixel Auto Tile Set
  3085. 3. Pixel Pallet Key
  3086. 4. Pixel Topology Within Voxel
  3087. 5. ETC.
  3088. (Some #'s may be synonymous)
  3089.  
  3090. BEE & CEE CANNOT AUTO TILE WITH EACH
  3091. OTHER WITH ONLY[ til_val ]AND[ pix_d3d ]!!!
  3092.  
  3093. REASON:
  3094. Tile value (til_val/vox_val)
  3095. can determine the material properties
  3096. of the pixels contained within it.
  3097.  
  3098. If we only have [til_val]AND[pix_d3d]
  3099. we can figure out CEE's location
  3100. by using BEE's location, but we cannot
  3101. figure out CEE's MATERIAL_TYPE.
  3102.  
  3103. Without knowing CEE's MATERIAL_TYPE
  3104. we cannot know if [ BEE ]AND[ CEE ]
  3105. should fuse with each other due to
  3106. using identical AUTO_TILE_SETS.
  3107.  
  3108. #################CASH_IN_INDEXES_AT_LAST_MOMENT#
  3109. #STACK_ADDRESS_WORKINGS#########################
  3110. /////// stack_pointer === stack_context ////////
  3111.  
  3112. von: VOlume_N (N == Nesting_Level)
  3113. ( Choose name based on origins of )
  3114. ( the word "voxel" from wikipedia )
  3115.  
  3116. KEY: (For Illustrative Purpose)
  3117.  
  3118. sta_add[ 0 ] ===> GALAXY (von_000)
  3119. sta_add[ 1 ] ===> PLANET (von_001)
  3120. sta_add[ 2 ] ===> CONTINENT (von_002)
  3121. sta_add[ 3 ] ===> STATE (von_003)
  3122. sta_add[ 4 ] ===> CITY (von_004)
  3123.  
  3124. I32 sta_add[ 5 ]=I32[ 5 ](
  3125.  
  3126. ENUM_VALUE_milky_way
  3127. , ENUM_VALUE_earth
  3128. , ENUM_VALUE_north_america
  3129. , ENUM_VALUE_michigan
  3130. , ENUM_VALUE_ann_arbor
  3131.  
  3132. )
  3133.  
  3134. VON
  3135. GET_von_USE_xyz_rwN_sta_add_sta_con(
  3136. V_3 xyz
  3137. , V_3 rwN
  3138. , V_3 sta_add[5]
  3139. , V_3 sta_con
  3140. ){
  3141.  
  3142. HERE:
  3143. Traverse nested data structure
  3144. using[ sta_add ]AND[ sta_con ]
  3145. and return generic[ VON ] struct
  3146. that could represent.
  3147.  
  3148. 1. Voxel (von_000)
  3149. 2. Pixel (von_001)
  3150. 3. Something nested deeper.
  3151. 4. Something nested even deeper.
  3152. 5. And deeper, etc. (von_###)
  3153.  
  3154. return( von );
  3155. };;
  3156.  
  3157. struct VON{
  3158.  
  3159. //: von_d3d===[til_d3d,pix_d3d,etc]
  3160. I32 von_d3d;
  3161.  
  3162. };
  3163.  
  3164.  
  3165. #########################STACK_ADDRESS_WORKINGS#
  3166. #LOOPTICK_FUNCTION##############################
  3167.  
  3168. A "loop tick" function is a function that
  3169. serves as the body of a loop.
  3170.  
  3171. I usually use loop tick functions to
  3172. abstract loop bodies with callbacks.
  3173.  
  3174. But, in the case of THIS GLSL SHADER,
  3175. looptick functions are for reducing
  3176. visual clutter and making the code easier
  3177. to follow.
  3178.  
  3179. The main benifit of a looptick function is
  3180. being able to RESET OUR INDENTATION.
  3181.  
  3182. Which, might not be wise since we are
  3183. adding more load (function call with
  3184. many arguments) , however, readability
  3185. comes first, optimizations come very last.
  3186.  
  3187. ##############################LOOPTICK_FUNCTION#
  3188. #INTO_THE_BLACK_VOID############################
  3189.  
  3190. The further the ray goes into
  3191. the void of space, the darker
  3192. the pixel. Just to give us
  3193. some useful feedback.
  3194.  
  3195. ############################INTO_THE_BLACK_VOID#
  3196. #BREAK##########################################
  3197.  
  3198. If you see #BREAK# it is probably near
  3199. a "return" statement that was once
  3200. a "break" before the loop body code was
  3201. extracted into it's own function.
  3202.  
  3203. ##########################################BREAK#
  3204.  
  3205.  
  3206.  
  3207. *** ************************************************ **/
  3208. //:====================================:DOCUMENTATION://
  3209. //:UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU://
  3210. /** U : Undefine Macros Section **/
  3211.  
  3212. #undef V_4
  3213. #undef V_3
  3214. #undef V_2
  3215. #undef F32
  3216. #undef I32
  3217. #undef U32
  3218.  
  3219. /** U : Undefine Macros Section **/
  3220. //:UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU://
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement