├── .gitignore ├── .vscode └── .gitignore ├── OpenPolyphorm.ipynb ├── README.md ├── bin ├── .gitignore ├── ShareTechMono-Regular.ttf ├── UbuntuMono-R.ttf ├── capture │ ├── .gitignore │ ├── _denoise │ │ ├── .gitignore │ │ ├── .ipynb_checkpoints │ │ │ └── .gitignore │ │ ├── OpenPhysarumFiles.ipynb │ │ ├── hdr2pfm.py │ │ └── tonemap_hdr.ipynb │ ├── _video_encode.bat │ └── _videos │ │ └── .gitignore ├── config.polyp ├── consola.ttf ├── cs_agents_sort.hlsl ├── data │ ├── .gitignore │ ├── BP │ │ └── .gitignore │ ├── Cathedrals │ │ ├── .gitignore │ │ └── pack_data_Cathedral.py │ ├── Conduits │ │ └── .gitignore │ ├── Embeddings │ │ └── .gitignore │ ├── FRB │ │ └── .gitignore │ ├── MassiveNuS │ │ ├── .gitignore │ │ └── pack_MassiveNuS.py │ ├── Poisson │ │ ├── pack_data_Poisson.py │ │ ├── poisson_256_2d.dat │ │ ├── poisson_256_2d_3d_flattened.bin │ │ ├── poisson_256_2d_3d_flattened_metadata.txt │ │ ├── poisson_4096_2d.dat │ │ ├── poisson_4096_2d_3d.bin │ │ ├── poisson_4096_2d_3d_bias=3.0.bin │ │ ├── poisson_4096_2d_3d_bias=3.0_metadata.txt │ │ ├── poisson_4096_2d_3d_bias=4.0.bin │ │ ├── poisson_4096_2d_3d_bias=4.0_metadata.txt │ │ ├── poisson_4096_2d_3d_flattened.bin │ │ ├── poisson_4096_2d_3d_flattened_metadata.txt │ │ ├── poisson_4096_2d_3d_metadata.txt │ │ ├── random_4096_3d.bin │ │ ├── random_4096_3d_bias=3.0.bin │ │ ├── random_4096_3d_bias=3.0_metadata.txt │ │ ├── random_4096_3d_bias=4.0.bin │ │ ├── random_4096_3d_bias=4.0_metadata.txt │ │ ├── random_4096_3d_metadata.txt │ │ ├── regular_4096_3d.bin │ │ ├── regular_4096_3d_bias=3.0.bin │ │ ├── regular_4096_3d_bias=3.0_metadata.txt │ │ ├── regular_4096_3d_bias=4.0.bin │ │ ├── regular_4096_3d_bias=4.0_metadata.txt │ │ └── regular_4096_3d_metadata.txt │ ├── SDSS │ │ ├── .gitignore │ │ ├── galaxiesInSdssSlice_viz_bigger_lumdist_t=0.0.bin │ │ └── galaxiesInSdssSlice_viz_bigger_lumdist_t=0.0_metadata.txt │ ├── Zoe │ │ ├── .gitignore │ │ ├── 64-clean-JT-3Dskan_nobottom.blend │ │ ├── 64-clean-JT-3Dskan_nobottom_n=38102.bin │ │ ├── 64-clean-JT-3Dskan_nobottom_n=38102_metadata.txt │ │ └── pack_data_Zoe.py │ ├── affect_palettes.png │ ├── palette_blue.tga │ ├── palette_cliff3.tga │ ├── palette_coldhot.tga │ ├── palette_eagle.tga │ ├── palette_eagle2.tga │ ├── palette_gogh_blue.tga │ ├── palette_gogh_green.tga │ ├── palette_hot.tga │ ├── palette_magma.tga │ ├── palette_magneto2.tga │ ├── palette_sunset2.tga │ ├── palette_sunset3.tga │ ├── palette_tropico.tga │ ├── palette_vaneyck_green.tga │ └── palette_vaneyck_red.tga ├── export │ └── .gitignore ├── freetype271MT.dll ├── obj │ └── .gitignore ├── ps_volume_halocolor.hlsl └── renner-book.otf ├── build_and_run.bat ├── builder ├── CMakeLists.txt ├── bin │ ├── .gitignore │ ├── build.exe │ └── obj │ │ └── main.obj ├── build.bat ├── config.h ├── environment.cpp ├── file_system.cpp ├── hasher.cpp ├── main.cpp ├── memory.cpp ├── microsoft_craziness.h ├── parser.cpp ├── setup.bat ├── string.cpp ├── structs.h └── sys_utils.cpp ├── cpplib ├── animation.cpp ├── animation.h ├── array.h ├── audio.cpp ├── audio.h ├── export.cpp ├── export.h ├── fbx_loader.cpp ├── fbx_loader.h ├── file_system.cpp ├── file_system.h ├── font.cpp ├── font.h ├── fonts │ ├── ShareTechMono-Regular.ttf │ ├── UbuntuMono-R.ttf │ ├── consola.ttf │ └── renner-book.otf ├── freetype │ ├── include │ │ ├── freetype │ │ │ ├── config │ │ │ │ ├── ftconfig.h │ │ │ │ ├── ftheader.h │ │ │ │ ├── ftmodule.h │ │ │ │ ├── ftoption.h │ │ │ │ └── ftstdlib.h │ │ │ ├── freetype.h │ │ │ ├── ftadvanc.h │ │ │ ├── ftautoh.h │ │ │ ├── ftbbox.h │ │ │ ├── ftbdf.h │ │ │ ├── ftbitmap.h │ │ │ ├── ftbzip2.h │ │ │ ├── ftcache.h │ │ │ ├── ftcffdrv.h │ │ │ ├── ftchapters.h │ │ │ ├── ftcid.h │ │ │ ├── fterrdef.h │ │ │ ├── fterrors.h │ │ │ ├── ftfntfmt.h │ │ │ ├── ftgasp.h │ │ │ ├── ftglyph.h │ │ │ ├── ftgxval.h │ │ │ ├── ftgzip.h │ │ │ ├── ftimage.h │ │ │ ├── ftincrem.h │ │ │ ├── ftlcdfil.h │ │ │ ├── ftlist.h │ │ │ ├── ftlzw.h │ │ │ ├── ftmac.h │ │ │ ├── ftmm.h │ │ │ ├── ftmodapi.h │ │ │ ├── ftmoderr.h │ │ │ ├── ftotval.h │ │ │ ├── ftoutln.h │ │ │ ├── ftpfr.h │ │ │ ├── ftrender.h │ │ │ ├── ftsizes.h │ │ │ ├── ftsnames.h │ │ │ ├── ftstroke.h │ │ │ ├── ftsynth.h │ │ │ ├── ftsystem.h │ │ │ ├── fttrigon.h │ │ │ ├── ftttdrv.h │ │ │ ├── fttypes.h │ │ │ ├── ftwinfnt.h │ │ │ ├── t1tables.h │ │ │ ├── ttnameid.h │ │ │ ├── tttables.h │ │ │ ├── tttags.h │ │ │ └── ttunpat.h │ │ └── ft2build.h │ ├── win32 │ │ ├── freetype271.dll │ │ ├── freetype271.lib │ │ ├── freetype271MT.dll │ │ └── freetype271MT.lib │ └── win64 │ │ ├── freetype271.dll │ │ ├── freetype271.lib │ │ ├── freetype271MT.dll │ │ └── freetype271MT.lib ├── graphics.cpp ├── graphics.h ├── input.cpp ├── input.h ├── logging.cpp ├── logging.h ├── maths.cpp ├── maths.h ├── memory.cpp ├── memory.h ├── oculus │ ├── Extras │ │ ├── OVR_CAPI_Util.h │ │ ├── OVR_Math.h │ │ └── OVR_StereoProjection.h │ ├── LibOVR_d.lib │ ├── LibOVR_r.lib │ ├── OVR_CAPI.h │ ├── OVR_CAPI_Audio.h │ ├── OVR_CAPI_D3D.h │ ├── OVR_CAPI_GL.h │ ├── OVR_CAPI_Keys.h │ ├── OVR_CAPI_Vk.h │ ├── OVR_ErrorCode.h │ └── OVR_Version.h ├── ovr.cpp ├── ovr.h ├── parsers.cpp ├── parsers.h ├── platform.cpp ├── platform.h ├── random.cpp ├── random.h ├── resources.cpp ├── resources.h ├── stack.h ├── stb_vorbis.c ├── ui.cpp └── ui.h ├── docs ├── energy.png ├── mode_combined.png ├── mode_particles.png ├── mode_segmentation.png ├── mode_trace.png ├── proxy_shells.png ├── proxy_sightline.png ├── pt_aniso_red.png ├── pt_cool_blue.png ├── pt_pointlight.png ├── repo_card.png ├── title.png ├── title_vis2020.png ├── title_vis2020_narrow.png ├── title_vis2020_play.png ├── trim_combined.png ├── trim_particles.png ├── trim_segmentation.png ├── trim_trace.png ├── uc1_mapping.png ├── uc2_regions.png ├── uc3_absorption.png ├── uc3_galaxies.png ├── vis_options.png └── vis_options_small.png ├── main.cpp ├── pack_data_celestial.py ├── polyphorm.build ├── polyphorm.code-workspace └── shaders ├── cs_agents_propagate.hlsl ├── cs_agents_sort.hlsl ├── cs_density_histo.hlsl ├── cs_field_decay.hlsl ├── cs_particles_blit.hlsl ├── cs_particles_transform.hlsl ├── cs_volpath.hlsl ├── ps_particles_color.hlsl ├── ps_volpath.hlsl ├── ps_volume_halocolor.hlsl ├── ps_volume_highlight.hlsl ├── ps_volume_overdensity.hlsl ├── ps_volume_trace.hlsl ├── ps_volume_velocity.hlsl ├── vs_2d.hlsl └── vs_3d.hlsl /.gitignore: -------------------------------------------------------------------------------- 1 | /main_pt.cpp 2 | /data/ 3 | *.code-workspace 4 | -------------------------------------------------------------------------------- /.vscode/.gitignore: -------------------------------------------------------------------------------- 1 | /settings.json 2 | -------------------------------------------------------------------------------- /OpenPolyphorm.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "id": "view-in-github", 7 | "colab_type": "text" 8 | }, 9 | "source": [ 10 | "\"Open" 11 | ] 12 | }, 13 | { 14 | "cell_type": "code", 15 | "execution_count": null, 16 | "metadata": { 17 | "id": "G3XLl8CHiUJV" 18 | }, 19 | "outputs": [], 20 | "source": [ 21 | "import numpy as np\n", 22 | "import matplotlib.pyplot as plt\n", 23 | "from ipywidgets import interact # For plotting\n", 24 | "\n", 25 | "# Source and dimensions of the data\n", 26 | "DATA_FILE = 'trace.bin'\n", 27 | "BRICK_SIZE = [1024, 784, 416] # Look up the grid resolution in the metadata file exported by Polyphorm\n", 28 | "N_CHANNELS = 1\n", 29 | "\n", 30 | "# Other settings\n", 31 | "VIS_GAMMA = 0.2\n", 32 | "FIGSIZE = 10.0\n", 33 | "\n", 34 | "# Load raw dataset from HDD\n", 35 | "raw_data = np.fromfile(DATA_FILE, dtype=np.float16)" 36 | ] 37 | }, 38 | { 39 | "cell_type": "code", 40 | "source": [ 41 | "# Reshape and convert data to suitable format for visualization\n", 42 | "voxels_f16 = raw_data.reshape((BRICK_SIZE[2], BRICK_SIZE[1], BRICK_SIZE[0], N_CHANNELS)) # Mind the order of dimensions\n", 43 | "voxels_u8 = voxels_f16.astype(np.uint8) ** VIS_GAMMA\n", 44 | "\n", 45 | "# Visualize a single slice of the voxel data\n", 46 | "def plot_voxels_slice(slice, channel):\n", 47 | " plt.figure(figsize = (FIGSIZE, FIGSIZE))\n", 48 | " plt.imshow(voxels_u8[:,:,slice,channel])\n", 49 | "interact(plot_voxels_slice, slice=(0, BRICK_SIZE[0]-1, 1), channel=(0, N_CHANNELS-1, 1));" 50 | ], 51 | "metadata": { 52 | "id": "sMNQFl-6i6My" 53 | }, 54 | "execution_count": null, 55 | "outputs": [] 56 | }, 57 | { 58 | "cell_type": "code", 59 | "execution_count": null, 60 | "metadata": { 61 | "id": "ICT9URmmiUJf" 62 | }, 63 | "outputs": [], 64 | "source": [ 65 | "# Threshold the data from below\n", 66 | "THRESHOLD = 5.0\n", 67 | "voxels_f16_thresholded = np.fmax(voxels_f16 - THRESHOLD, 0.0)\n", 68 | "voxels_u8_thresholded = voxels_f16_thresholded.astype(np.uint8) ** VIS_GAMMA\n", 69 | "\n", 70 | "def plot_voxels_slice_2(slice, channel):\n", 71 | " plt.figure(figsize = (FIGSIZE, FIGSIZE))\n", 72 | " plt.imshow(voxels_u8_thresholded[:,:,slice,channel])\n", 73 | "interact(plot_voxels_slice_2, slice=(0, BRICK_SIZE[0]-1, 1), channel=(0, N_CHANNELS-1, 1));" 74 | ] 75 | } 76 | ], 77 | "metadata": { 78 | "kernelspec": { 79 | "display_name": "Python 3", 80 | "language": "python", 81 | "name": "python3" 82 | }, 83 | "language_info": { 84 | "codemirror_mode": { 85 | "name": "ipython", 86 | "version": 3 87 | }, 88 | "file_extension": ".py", 89 | "mimetype": "text/x-python", 90 | "name": "python", 91 | "nbconvert_exporter": "python", 92 | "pygments_lexer": "ipython3", 93 | "version": "3.7.0" 94 | }, 95 | "colab": { 96 | "name": "OpenPolyphorm.ipynb", 97 | "provenance": [], 98 | "collapsed_sections": [], 99 | "include_colab_link": true 100 | } 101 | }, 102 | "nbformat": 4, 103 | "nbformat_minor": 0 104 | } -------------------------------------------------------------------------------- /bin/.gitignore: -------------------------------------------------------------------------------- 1 | /cs_agents_propagate.hlsl 2 | /cs_density_histo.hlsl 3 | /cs_field_decay.hlsl 4 | /cs_particles_blit.hlsl 5 | /cs_particles_transform.hlsl 6 | /polyphorm.exe 7 | /ps_particles_color.hlsl 8 | /ps_volume_highlight.hlsl 9 | /ps_volume_overdensity.hlsl 10 | /ps_volume_trace.hlsl 11 | /ps_volume_velocity.hlsl 12 | /vs_2d.hlsl 13 | /vs_3d.hlsl 14 | /cs_volpath.hlsl 15 | /ps_volpath.hlsl 16 | *.tmp 17 | -------------------------------------------------------------------------------- /bin/ShareTechMono-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/ShareTechMono-Regular.ttf -------------------------------------------------------------------------------- /bin/UbuntuMono-R.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/UbuntuMono-R.ttf -------------------------------------------------------------------------------- /bin/capture/.gitignore: -------------------------------------------------------------------------------- 1 | *.tga 2 | *.hdr 3 | *.png 4 | /final/ 5 | /rotating/ 6 | /tng_growth/ 7 | -------------------------------------------------------------------------------- /bin/capture/_denoise/.gitignore: -------------------------------------------------------------------------------- 1 | *.exr 2 | *.pfm 3 | -------------------------------------------------------------------------------- /bin/capture/_denoise/.ipynb_checkpoints/.gitignore: -------------------------------------------------------------------------------- 1 | /OpenPhysarumFiles-checkpoint.ipynb 2 | /tonemap_hdr-checkpoint.ipynb 3 | -------------------------------------------------------------------------------- /bin/capture/_denoise/OpenPhysarumFiles.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 4, 6 | "metadata": {}, 7 | "outputs": [ 8 | { 9 | "data": { 10 | "application/vnd.jupyter.widget-view+json": { 11 | "model_id": "9c3bf707e0af4e59adfe02ce3a4cab7f", 12 | "version_major": 2, 13 | "version_minor": 0 14 | }, 15 | "text/plain": [ 16 | "interactive(children=(IntSlider(value=327, description='slice', max=655), IntSlider(value=0, description='chan…" 17 | ] 18 | }, 19 | "metadata": {}, 20 | "output_type": "display_data" 21 | } 22 | ], 23 | "source": [ 24 | "import numpy as np\n", 25 | "import matplotlib.pyplot as plt\n", 26 | "from ipywidgets import interact\n", 27 | "\n", 28 | "# Source and the X/Y/Z resolution of the data\n", 29 | "DATA_FILE = 'trace.bin'\n", 30 | "BRICK_SIZE = [656,1200,680]\n", 31 | "N_CHANNELS = 1\n", 32 | "\n", 33 | "# Load raw dataset from HDD\n", 34 | "raw_data = np.fromfile(DATA_FILE, dtype=np.float16)\n", 35 | "\n", 36 | "# Reshape and convert data to suitable formats\n", 37 | "voxels_f16 = raw_data.reshape((BRICK_SIZE[2], BRICK_SIZE[1], BRICK_SIZE[0], N_CHANNELS)) # Mind the order of dimensions\n", 38 | "voxels_u8 = voxels_f16.astype(np.uint8)\n", 39 | "\n", 40 | "# Visualize a single slice of the voxel data\n", 41 | "GAMMA = 0.2\n", 42 | "FIGSIZE = 10.0\n", 43 | "def plot_voxels_slice(slice, channel):\n", 44 | " plt.figure(figsize = (FIGSIZE, FIGSIZE))\n", 45 | " plt.imshow(voxels_u8[:,:,slice,channel] ** GAMMA)\n", 46 | "interact(plot_voxels_slice, slice=(0, BRICK_SIZE[0]-1, 1), channel=(0, N_CHANNELS-1, 1));" 47 | ] 48 | }, 49 | { 50 | "cell_type": "code", 51 | "execution_count": null, 52 | "metadata": {}, 53 | "outputs": [], 54 | "source": [] 55 | } 56 | ], 57 | "metadata": { 58 | "kernelspec": { 59 | "display_name": "Python 3", 60 | "language": "python", 61 | "name": "python3" 62 | }, 63 | "language_info": { 64 | "codemirror_mode": { 65 | "name": "ipython", 66 | "version": 3 67 | }, 68 | "file_extension": ".py", 69 | "mimetype": "text/x-python", 70 | "name": "python", 71 | "nbconvert_exporter": "python", 72 | "pygments_lexer": "ipython3", 73 | "version": "3.6.12" 74 | } 75 | }, 76 | "nbformat": 4, 77 | "nbformat_minor": 2 78 | } 79 | -------------------------------------------------------------------------------- /bin/capture/_denoise/hdr2pfm.py: -------------------------------------------------------------------------------- 1 | ## needs the freeimage package installed to load/save high dynamic range images 2 | ## read more here: https://imageio.readthedocs.io/en/latest/formats.html 3 | 4 | import sys 5 | import imageio as iio 6 | 7 | for arg in sys.argv[1:]: 8 | hdr_image = iio.imread(arg + '.hdr', format='HDR-FI') 9 | iio.imwrite(arg + '.pfm', hdr_image, format='PFM-FI') -------------------------------------------------------------------------------- /bin/capture/_video_encode.bat: -------------------------------------------------------------------------------- 1 | ffmpeg -r 30 -f image2 -start_number 18 -i ./frame%%d.tga -vcodec libx264 -f mp4 -pix_fmt yuv420p _videos/xxx.mp4 2 | 3 | REM -b:v 2.0M ...video bitrate 4 | REM -i vis2020_fitting_session.mp3 5 | REM -c copy 6 | REM -i "concat:vis2020_title.ts|vis2020_body.ts" 7 | REM -filter:v "crop=out_w:out_h:x:y" 8 | REM -t 20 (encode X seconds of video) 9 | 10 | REM docu: https://ffmpeg.org/ffmpeg.html 11 | REM combining two mp4s: https://stackoverflow.com/questions/7567713/combining-two-video-from-ffmpeg 12 | REM add audio: https://superuser.com/questions/590201/add-audio-to-video-using-ffmpeg -------------------------------------------------------------------------------- /bin/capture/_videos/.gitignore: -------------------------------------------------------------------------------- 1 | *.mp4 2 | *.gif 3 | -------------------------------------------------------------------------------- /bin/config.polyp: -------------------------------------------------------------------------------- 1 | Agents number = 10000000 2 | Grid resolution = 1024 3 | Grid padding = 0.1 4 | Screen X = 1800 5 | Screen Y = 1000 6 | Camera FOV = 30.0 7 | Histogram base = 10.0 8 | 9 | ## Anything below this line is ingored ## 10 | 11 | Screen X = 2000 12 | Screen Y = 1100 13 | 14 | Screen X = 1800 15 | Screen Y = 1000 16 | 17 | Screen X = 1400 18 | Screen Y = 850 -------------------------------------------------------------------------------- /bin/consola.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/consola.ttf -------------------------------------------------------------------------------- /bin/cs_agents_sort.hlsl: -------------------------------------------------------------------------------- 1 | 2 | RWStructuredBuffer particles_x: register(u2); 3 | RWStructuredBuffer particles_y: register(u3); 4 | RWStructuredBuffer particles_z: register(u4); 5 | RWStructuredBuffer particles_phi: register(u5); 6 | RWStructuredBuffer particles_theta: register(u6); 7 | RWStructuredBuffer particles_weights: register(u7); 8 | 9 | cbuffer ConfigBuffer : register(b0) 10 | { 11 | float sense_spread; 12 | float sense_distance; 13 | float turn_angle; 14 | float move_distance; 15 | float deposit_value; 16 | float decay_factor; 17 | float center_attraction; 18 | int world_width; 19 | int world_height; 20 | int world_depth; 21 | float move_sense_coef; 22 | float normalization_factor; 23 | int n_data_points; 24 | int n_agents; 25 | int n_iteration; 26 | }; 27 | 28 | struct RNG { 29 | #define BAD_W 0x464fffffU 30 | #define BAD_Z 0x9068ffffU 31 | uint m_w; 32 | uint m_z; 33 | 34 | void set_seed(uint seed1, uint seed2) { 35 | m_w = seed1; 36 | m_z = seed2; 37 | if (m_w == 0U || m_w == BAD_W) ++m_w; 38 | if (m_w == 0U || m_z == BAD_Z) ++m_z; 39 | } 40 | 41 | void get_seed(out uint seed1, out uint seed2) { 42 | seed1 = m_w; 43 | seed2 = m_z; 44 | } 45 | 46 | uint random_uint() { 47 | m_z = 36969U * (m_z & 65535U) + (m_z >> 16U); 48 | m_w = 18000U * (m_w & 65535U) + (m_w >> 16U); 49 | return uint((m_z << 16U) + m_w); 50 | } 51 | 52 | float random_float() { 53 | return float(random_uint()) / float(0xFFFFFFFFU); 54 | } 55 | 56 | uint wang_hash(uint seed) { 57 | seed = (seed ^ 61) ^ (seed >> 16); 58 | seed *= 9; 59 | seed = seed ^ (seed >> 4); 60 | seed *= 0x27d4eb2d; 61 | seed = seed ^ (seed >> 15); 62 | return seed; 63 | } 64 | }; 65 | 66 | void swap_agents(uint idxA, uint idxB) { 67 | float tmp; 68 | tmp = particles_x[idxA]; particles_x[idxA] = particles_x[idxB]; particles_x[idxB] = tmp; 69 | tmp = particles_y[idxA]; particles_y[idxA] = particles_y[idxB]; particles_y[idxB] = tmp; 70 | tmp = particles_z[idxA]; particles_z[idxA] = particles_z[idxB]; particles_z[idxB] = tmp; 71 | tmp = particles_theta[idxA]; particles_theta[idxA] = particles_theta[idxB]; particles_theta[idxB] = tmp; 72 | tmp = particles_phi[idxA]; particles_phi[idxA] = particles_phi[idxB]; particles_phi[idxB] = tmp; 73 | tmp = particles_weights[idxA]; particles_weights[idxA] = particles_weights[idxB]; particles_weights[idxB] = tmp; 74 | } 75 | 76 | // Morton codes: https://fgiesen.wordpress.com/2009/12/13/decoding-morton-codes/ 77 | uint Part1By2(uint x_) { 78 | uint x = x_ & 0x000003ff; 79 | x = (x ^ (x << 16)) & 0xff0000ff; 80 | x = (x ^ (x << 8)) & 0x0300f00f; 81 | x = (x ^ (x << 4)) & 0x030c30c3; 82 | x = (x ^ (x << 2)) & 0x09249249; 83 | return x; 84 | } 85 | 86 | uint EncodeMorton3(uint x, uint y, uint z) { 87 | return (Part1By2(z) << 2) + (Part1By2(y) << 1) + Part1By2(x); 88 | } 89 | 90 | [numthreads(10,10,10)] 91 | void main(uint thread_index : SV_GroupIndex, uint3 group_id : SV_GroupID) { 92 | uint group_idx = group_id.x + group_id.y * 10 + group_id.z * 100; 93 | uint idx = thread_index + 1000 * group_idx; 94 | 95 | // uint idxA = 32 * idx + (n_iteration % 32); 96 | // if (idxA >= n_agents-1) 97 | // return; 98 | // uint idxB = idxA + 1; 99 | // idxA = idxA + (n_data_points-1); 100 | // idxB = idxB + (n_data_points-1); 101 | 102 | // float vA = particles_y[idxA]; 103 | // float vB = particles_y[idxB]; 104 | // if (vA > vB) { 105 | // swap_agents(idxA, idxB); 106 | // } 107 | 108 | RNG rng; 109 | rng.set_seed( 110 | rng.wang_hash(73*idx), 111 | rng.wang_hash(13*n_iteration) 112 | ); 113 | uint idxA = n_data_points + rng.random_uint() % n_agents; 114 | uint idxB = n_data_points + rng.random_uint() % n_agents; 115 | float3 posA = float3(particles_x[idxA], particles_y[idxA], particles_z[idxA]); 116 | float3 posAN = float3( 117 | 0.5 * (particles_x[idxA-1] + particles_x[idxA+1]), 118 | 0.5 * (particles_y[idxA-1] + particles_y[idxA+1]), 119 | 0.5 * (particles_z[idxA-1] + particles_z[idxA+1])); 120 | float3 posB = float3(particles_x[idxB], particles_y[idxB], particles_z[idxB]); 121 | float3 posBN = float3( 122 | 0.5 * (particles_x[idxB-1] + particles_x[idxB+1]), 123 | 0.5 * (particles_y[idxB-1] + particles_y[idxB+1]), 124 | 0.5 * (particles_z[idxB-1] + particles_z[idxB+1])); 125 | float dA = length(posA - posAN); 126 | float dB = length(posB - posBN); 127 | float dApot = length(posA - posBN); 128 | float dBpot = length(posB - posAN); 129 | if ((dApot + dBpot) < (dA + dB)) { 130 | swap_agents(idxA, idxB); 131 | } 132 | 133 | // RNG rng; 134 | // rng.set_seed( 135 | // rng.wang_hash(73*idx), 136 | // rng.wang_hash(13*n_iteration) 137 | // ); 138 | // uint idxA = (n_data_points - 1) + rng.random_uint() % n_agents; 139 | // uint idxB = (n_data_points - 1) + rng.random_uint() % n_agents; 140 | // // uint vA = EncodeMorton3(uint(particles_x[idxA]), uint(particles_y[idxA]), uint(particles_z[idxA])); 141 | // // uint vB = EncodeMorton3(uint(particles_x[idxB]), uint(particles_y[idxB]), uint(particles_z[idxB])); 142 | // float vA = particles_y[idxA]; 143 | // float vB = particles_y[idxB]; 144 | // if (idxA < idxB && vA > vB) { 145 | // swap_agents(idxA, idxB); 146 | // } 147 | 148 | // uint idxA = (n_data_points - 1) + idx; 149 | // uint idxB = idxA + n_agents / 2; 150 | // float vA = particles_z[idxA]; 151 | // float vB = particles_z[idxB]; 152 | // if (vA > vB) { 153 | // swap_agents(idxA, idxB); 154 | // } 155 | } 156 | -------------------------------------------------------------------------------- /bin/data/.gitignore: -------------------------------------------------------------------------------- 1 | /TNG/ 2 | /palette_electric.tga 3 | /palette_ignite.png 4 | /palette_ignite.tga 5 | /palette_plankton.png 6 | /palette_plankton.tga 7 | /palette_template.svg 8 | /sci_palettes.png 9 | /untitled.blend 10 | /untitled.blend1 11 | -------------------------------------------------------------------------------- /bin/data/BP/.gitignore: -------------------------------------------------------------------------------- 1 | /bpdat_boxDist_trimDist_trimMass_t=0.05_subrate=1_ROTATED.bin 2 | /bpdat_boxDist_trimDist_trimMass_t=0.05_subrate=1_ROTATED_metadata.txt 3 | -------------------------------------------------------------------------------- /bin/data/Cathedrals/.gitignore: -------------------------------------------------------------------------------- 1 | /AnkorWat.fbx 2 | /angkor_wat.blend 3 | /angkor_wat.mtl 4 | /angkor_wat.obj 5 | /angkor_wat_n=48207.bin 6 | /angkor_wat_n=48207_metadata.txt 7 | /angkor_wat_n=48259.bin 8 | /angkor_wat_n=48259_metadata.txt 9 | /notre_dame.blend 10 | /notre_dame.blend1 11 | /notre_dame.mtl 12 | /notre_dame.obj 13 | /notre_dame_n=44912.bin 14 | /notre_dame_n=44912_metadata.txt 15 | /pocillopora_eydouxi.blend 16 | /pocillopora_eydouxi.blend1 17 | /pocillopora_eydouxi.mtl 18 | /pocillopora_eydouxi.obj 19 | /pocillopora_eydouxi_n=22158.bin 20 | /pocillopora_eydouxi_n=22158_metadata.txt 21 | /pocillopora_eydouxi_n=222498.bin 22 | /pocillopora_eydouxi_n=222498_metadata.txt 23 | /pocillopora_eydouxi_n=74196.bin 24 | /pocillopora_eydouxi_n=74196_metadata.txt 25 | -------------------------------------------------------------------------------- /bin/data/Cathedrals/pack_data_Cathedral.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import math as math 3 | import random 4 | 5 | # fileName = 'notre_dame' 6 | # scale_multiplier = 10.0 7 | # fileName = 'pocillopora_eydouxi' 8 | # scale_multiplier = 10.0 9 | fileName = 'angkor_wat' 10 | scale_multiplier = 5.0 11 | subsampling_factor = 5.0 12 | 13 | valid_pt_number = 0 14 | with open(fileName + '.obj') as f: 15 | lines = f.readlines() 16 | data = np.zeros((len(lines)-1, 4), dtype=np.float32) 17 | for i, line in enumerate(lines): 18 | if not (line[0] == 'v' and line[1] == ' '): 19 | continue # not a valid point 20 | if random.uniform(0.0, 1.0) > 1.0/subsampling_factor: 21 | continue # randomly throw out vertices 22 | line = line.split(' ') 23 | x = scale_multiplier * float(line[1]) 24 | y = scale_multiplier * float(line[3]) 25 | z = -scale_multiplier * float(line[2]) 26 | weight = 1.0 27 | data[valid_pt_number, :] = [x, y, z, weight] 28 | valid_pt_number += 1 29 | 30 | if (valid_pt_number == 0): 31 | print('No points found') 32 | exit() 33 | 34 | filtered_data = np.zeros((valid_pt_number, 4), dtype=np.float32) 35 | filtered_data = data[0:valid_pt_number, :] 36 | 37 | print('Min/Max X: ' + str(np.min(filtered_data[:,0])) + ' ' + str(np.max(filtered_data[:,0]))) 38 | print('Min/Max Y: ' + str(np.min(filtered_data[:,1])) + ' ' + str(np.max(filtered_data[:,1]))) 39 | print('Min/Max Z: ' + str(np.min(filtered_data[:,2])) + ' ' + str(np.max(filtered_data[:,2]))) 40 | print('Min/Max/Avg/Med weight: ' + str(np.min(filtered_data[:,3])) + ' ' + str(np.max(filtered_data[:,3])) + ' ' + str(np.mean(filtered_data[:,3])) + ' ' + str(np.median(filtered_data[:,3]))) 41 | print('Sample record: ' + str(filtered_data[0,:])) 42 | print('Number of records: ' + str(valid_pt_number)) 43 | 44 | output_file_name = fileName + '_n=' + str(valid_pt_number) 45 | 46 | metadata_file = open(output_file_name + "_metadata.txt", "w") 47 | metadata_file.write("Number of points = " + str(valid_pt_number) + "\n") 48 | metadata_file.write("Min X = " + str(np.min(filtered_data[:,0])) + "\n") 49 | metadata_file.write("Max X = " + str(np.max(filtered_data[:,0])) + "\n") 50 | metadata_file.write("Min Y = " + str(np.min(filtered_data[:,1])) + "\n") 51 | metadata_file.write("Max Y = " + str(np.max(filtered_data[:,1])) + "\n") 52 | metadata_file.write("Min Z = " + str(np.min(filtered_data[:,2])) + "\n") 53 | metadata_file.write("Max Z = " + str(np.max(filtered_data[:,2])) + "\n") 54 | metadata_file.write("Mean weight = " + str(np.mean(filtered_data[:,3])) + "\n") 55 | metadata_file.close() 56 | 57 | filtered_data = filtered_data.tofile(output_file_name + '.bin') 58 | -------------------------------------------------------------------------------- /bin/data/Conduits/.gitignore: -------------------------------------------------------------------------------- 1 | /poisson_256_2d_conduits_n_levels=100_ratio=1.02.bin 2 | /poisson_256_2d_conduits_n_levels=100_ratio=1.02_metadata.txt 3 | /poisson_256_2d_conduits_n_levels=100_ratio=1.03.bin 4 | /poisson_256_2d_conduits_n_levels=100_ratio=1.03_metadata.txt 5 | /poisson_256_2d_conduits_n_levels=100_ratio=1.05.bin 6 | /poisson_256_2d_conduits_n_levels=100_ratio=1.05_metadata.txt 7 | /poisson_256_2d_conduits_n_levels=100_ratio=1.06.bin 8 | /poisson_256_2d_conduits_n_levels=100_ratio=1.06_metadata.txt 9 | /poisson_256_2d_conduits_n_levels=16_ratio=2.0.bin 10 | /poisson_256_2d_conduits_n_levels=16_ratio=2.0_metadata.txt 11 | /poisson_256_2d_conduits_n_levels=20_ratio=1.5.bin 12 | /poisson_256_2d_conduits_n_levels=20_ratio=1.5_metadata.txt 13 | /poisson_256_2d_conduits_n_levels=30_ratio=1.25.bin 14 | /poisson_256_2d_conduits_n_levels=30_ratio=1.25_metadata.txt 15 | /poisson_256_2d_conduits_n_levels=8_ratio=2.0.bin 16 | /poisson_256_2d_conduits_n_levels=8_ratio=2.0_metadata.txt 17 | -------------------------------------------------------------------------------- /bin/data/Embeddings/.gitignore: -------------------------------------------------------------------------------- 1 | /W2V_UMAP_params_100_n=296630.bin 2 | /W2V_UMAP_params_100_n=296630_metadata.txt 3 | /W2V_UMAP_params_15_n=296630.bin 4 | /W2V_UMAP_params_15_n=296630_metadata.txt 5 | /W2V_UMAP_params_200_n=296630.bin 6 | /W2V_UMAP_params_200_n=296630_metadata.txt 7 | /W2V_UMAP_params_50_n=296630.bin 8 | /W2V_UMAP_params_50_n=296630_metadata.txt 9 | /W2V_UMAP_params_5_n=296630.bin 10 | /W2V_UMAP_params_5_n=296630_metadata.txt 11 | /back_embed_n=18266.bin 12 | /back_embed_n=18266_metadata.txt 13 | /class_embed_n=9369.bin 14 | /class_embed_n=9369_metadata.txt 15 | /research_embed_n=10001.bin 16 | /research_embed_n=10001_metadata.txt 17 | /suit_embed_n=2163.bin 18 | /suit_embed_n=2163_metadata.txt 19 | /wind_embed_n=3834.bin 20 | /wind_embed_n=3834_metadata.txt 21 | -------------------------------------------------------------------------------- /bin/data/FRB/.gitignore: -------------------------------------------------------------------------------- 1 | /frb_field_cigaleMass_t=0.0_z=0.01-0.1.bin 2 | /frb_field_cigaleMass_t=0.0_z=0.01-0.1_metadata.txt 3 | /frb_field_cigaleMass_t=10.0.bin 4 | /frb_field_cigaleMass_t=10.0_metadata.txt 5 | /frb_field_cigaleMass_t=10.0_z=0.01-0.1.bin 6 | /frb_field_cigaleMass_t=10.0_z=0.01-0.1_metadata.txt 7 | /frb_field_cigaleMass_t=10.0_z=0.02-0.1.bin 8 | /frb_field_cigaleMass_t=10.0_z=0.02-0.1_metadata.txt 9 | /frb_field_cigaleMass_t=10.0_z=0.054-0.1.bin 10 | /frb_field_cigaleMass_t=10.0_z=0.054-0.1_metadata.txt 11 | /frb_field_t=10.3.bin 12 | /frb_field_t=10.3_metadata.txt 13 | -------------------------------------------------------------------------------- /bin/data/MassiveNuS/.gitignore: -------------------------------------------------------------------------------- 1 | /rockstar_mnv0.00000_om0.30000_As2.1000_out_66t=0.0roi=256.0.bin 2 | /rockstar_mnv0.00000_om0.30000_As2.1000_out_66t=0.0roi=256.0_metadata.txt 3 | /rockstar_mnv0.10000_om0.30000_As2.1000_out_66t=0.0roi=256.0.bin 4 | /rockstar_mnv0.10000_om0.30000_As2.1000_out_66t=0.0roi=256.0_metadata.txt 5 | /rockstar_mnv0.60000_om0.30000_As2.1000_out_66t=0.0roi=256.0.bin 6 | /rockstar_mnv0.60000_om0.30000_As2.1000_out_66t=0.0roi=256.0_metadata.txt 7 | -------------------------------------------------------------------------------- /bin/data/MassiveNuS/pack_MassiveNuS.py: -------------------------------------------------------------------------------- 1 | #ID DescID Mvir Vmax Vrms Rvir Rs Np X Y Z VX VY VZ JX JY JZ Spin rs_klypin Mvir_all M200b M200c M500c M2500c Xoff Voff spin_bullock b_to_a c_to_a A[x] A[y] A[z] b_to_a(500c) c_to_a(500c) A[x](500c) A[y](500c) A[z](500c) T/|U| M_pe_Behroozi M_pe_Diemer Halfmass_Radius 2 | #a = 1.000000 3 | #Om = 0.300000; Ol = 0.700000; h = 0.700000 4 | #FOF linking length: 0.280000 5 | #Unbound Threshold: 0.500000; FOF Refinement Threshold: 0.700000 6 | #Particle mass: 1.03289e+10 Msun/h 7 | #Box size: 512.000000 Mpc/h 8 | #Force resolution assumed: 0.009 Mpc/h 9 | #Units: Masses in Msun / h 10 | #Units: Positions in Mpc / h (comoving) 11 | #Units: Velocities in km / s (physical, peculiar) 12 | #Units: Halo Distances, Lengths, and Radii in kpc / h (comoving) 13 | #Units: Angular Momenta in (Msun/h) * (Mpc/h) * km/s (physical) 14 | #Units: Spins are dimensionless 15 | #Np is an internal debugging quantity. 16 | #Rockst 17 | 18 | import numpy as np 19 | 20 | # config 21 | dirName = 'rockstar_mnv0.60000_om0.30000_As2.1000' 22 | fileName = 'out_66' 23 | mass_threshold = 0.0 24 | roi = 256.0 25 | 26 | # convert 27 | nonzero_halos = 0 28 | with open(dirName + '/' + fileName + '.list') as f: 29 | lines = f.readlines() 30 | data = np.zeros((len(lines)-1, 4), dtype=np.float32) 31 | for i, line in enumerate(lines[16:]): 32 | line = line.split(' ') 33 | x = float(line[8]) 34 | y = float(line[9]) 35 | z = float(line[10]) 36 | mass = float(line[2]) / 1.0e12 37 | 38 | if ((mass > mass_threshold) & (x < roi) & (y < roi) & (z < roi)): 39 | data[nonzero_halos, :] = [x, y, z, mass] 40 | nonzero_halos += 1 41 | 42 | if (nonzero_halos == 0): 43 | print('No halos in selected ROI') 44 | exit() 45 | n_records = nonzero_halos 46 | filtered_data = np.zeros((n_records, 4), dtype=np.float32) 47 | filtered_data = data[0:n_records, :] 48 | 49 | print('Min/Max X: ' + str(np.min(filtered_data[:,0])) + ' ' + str(np.max(filtered_data[:,0]))) 50 | print('Min/Max Y: ' + str(np.min(filtered_data[:,1])) + ' ' + str(np.max(filtered_data[:,1]))) 51 | print('Min/Max Z: ' + str(np.min(filtered_data[:,2])) + ' ' + str(np.max(filtered_data[:,2]))) 52 | print('Min/Max/Avg/Med Mvir: ' + str(np.min(filtered_data[:,3])) + ' ' + str(np.max(filtered_data[:,3])) + ' ' + str(np.mean(filtered_data[:,3])) + ' ' + str(np.median(filtered_data[:,3]))) 53 | print('Sample record: ' + str(filtered_data[0,:])) 54 | print('Number of records: ' + str(n_records)) 55 | 56 | output_file_name = dirName + '_' + fileName + 't=' + str(mass_threshold) + 'roi=' + str(roi) 57 | 58 | metadata_file = open(output_file_name + "_metadata.txt", "w") 59 | metadata_file.write("Number of points = " + str(n_records) + "\n") 60 | metadata_file.write("Min X = " + str(np.min(filtered_data[:,0])) + "\n") 61 | metadata_file.write("Max X = " + str(np.max(filtered_data[:,0])) + "\n") 62 | metadata_file.write("Min Y = " + str(np.min(filtered_data[:,1])) + "\n") 63 | metadata_file.write("Max Y = " + str(np.max(filtered_data[:,1])) + "\n") 64 | metadata_file.write("Min Z = " + str(np.min(filtered_data[:,2])) + "\n") 65 | metadata_file.write("Max Z = " + str(np.max(filtered_data[:,2])) + "\n") 66 | metadata_file.write("Mean weight = " + str(np.mean(filtered_data[:,3])) + "\n") 67 | metadata_file.close() 68 | 69 | filtered_data = filtered_data.tofile(output_file_name + '.bin') -------------------------------------------------------------------------------- /bin/data/Poisson/poisson_256_2d.dat: -------------------------------------------------------------------------------- 1 | 0.08724 0.00700 2 | 0.57183 0.01091 3 | 0.79850 0.00309 4 | 0.02080 0.02068 5 | 0.02471 0.07148 6 | 0.13413 0.06171 7 | 0.19666 0.04608 8 | 0.25919 0.04999 9 | 0.32953 0.04217 10 | 0.39206 0.05390 11 | 0.44678 0.02654 12 | 0.50931 0.01873 13 | 0.54839 0.07344 14 | 0.63046 0.03045 15 | 0.68517 0.05781 16 | 0.74770 0.03827 17 | 0.82195 0.06562 18 | 0.88057 0.02263 19 | 0.93528 0.03436 20 | 0.07942 0.07930 21 | 0.09114 0.13206 22 | 0.17712 0.10470 23 | 0.24356 0.11252 24 | 0.30218 0.10080 25 | 0.36862 0.09689 26 | 0.43114 0.11643 27 | 0.48586 0.07735 28 | 0.56402 0.13597 29 | 0.61873 0.08907 30 | 0.67735 0.12815 31 | 0.73988 0.09298 32 | 0.79069 0.12424 33 | 0.85321 0.12034 34 | 0.90793 0.08516 35 | 0.97436 0.08125 36 | 0.03448 0.15355 37 | 0.14781 0.15942 38 | 0.20643 0.17505 39 | 0.26896 0.17114 40 | 0.32758 0.18286 41 | 0.37839 0.16332 42 | 0.45655 0.18677 43 | 0.49954 0.13988 44 | 0.53862 0.19459 45 | 0.62459 0.15551 46 | 0.68321 0.19068 47 | 0.74183 0.16723 48 | 0.81609 0.17896 49 | 0.87471 0.19850 50 | 0.90988 0.14769 51 | 0.97632 0.15160 52 | 0.04229 0.22390 53 | 0.09701 0.20240 54 | 0.15563 0.22194 55 | 0.22597 0.22976 56 | 0.29632 0.23758 57 | 0.35494 0.24539 58 | 0.41356 0.21804 59 | 0.48781 0.24149 60 | 0.56597 0.24930 61 | 0.61287 0.21413 62 | 0.66758 0.26103 63 | 0.73402 0.23367 64 | 0.79655 0.22585 65 | 0.87080 0.25712 66 | 0.94896 0.21022 67 | 0.01884 0.28252 68 | 0.07356 0.31769 69 | 0.10091 0.26884 70 | 0.18689 0.28057 71 | 0.24551 0.30011 72 | 0.30022 0.30792 73 | 0.36275 0.30401 74 | 0.42528 0.27666 75 | 0.51908 0.28838 76 | 0.58160 0.31574 77 | 0.62850 0.29620 78 | 0.69103 0.31965 79 | 0.75356 0.29229 80 | 0.82000 0.28447 81 | 0.88252 0.31183 82 | 0.93724 0.27275 83 | 0.99977 0.26493 84 | 0.06574 0.38413 85 | 0.11655 0.37045 86 | 0.15172 0.32746 87 | 0.21816 0.34700 88 | 0.31976 0.36263 89 | 0.37057 0.38608 90 | 0.41747 0.33528 91 | 0.48000 0.33919 92 | 0.54252 0.35873 93 | 0.60896 0.37436 94 | 0.67931 0.37827 95 | 0.74574 0.35482 96 | 0.81218 0.34309 97 | 0.89425 0.36654 98 | 0.95678 0.33137 99 | 0.99586 0.38218 100 | 0.02666 0.38804 101 | 0.12827 0.43689 102 | 0.18298 0.39781 103 | 0.25724 0.38999 104 | 0.32367 0.42907 105 | 0.39793 0.44861 106 | 0.43701 0.39390 107 | 0.49172 0.41735 108 | 0.55034 0.42126 109 | 0.60114 0.44080 110 | 0.66367 0.43298 111 | 0.73011 0.42516 112 | 0.79264 0.41344 113 | 0.84735 0.40172 114 | 0.93333 0.40953 115 | 0.97241 0.44470 116 | 0.01494 0.49746 117 | 0.07747 0.45838 118 | 0.14390 0.49551 119 | 0.21034 0.49942 120 | 0.21425 0.45252 121 | 0.27678 0.46424 122 | 0.34321 0.48769 123 | 0.40965 0.51114 124 | 0.46436 0.47206 125 | 0.53080 0.47597 126 | 0.64413 0.49160 127 | 0.71057 0.48378 128 | 0.77310 0.46815 129 | 0.83172 0.47988 130 | 0.88643 0.45643 131 | 0.92551 0.50332 132 | 0.08528 0.52482 133 | 0.13609 0.56195 134 | 0.19471 0.54631 135 | 0.24942 0.56976 136 | 0.28850 0.51896 137 | 0.34712 0.55804 138 | 0.40574 0.57367 139 | 0.47609 0.52677 140 | 0.56988 0.51505 141 | 0.63241 0.53850 142 | 0.69885 0.54241 143 | 0.76528 0.53068 144 | 0.82390 0.55413 145 | 0.87862 0.53459 146 | 0.94505 0.56585 147 | 0.98413 0.52287 148 | 0.00712 0.62643 149 | 0.03838 0.57562 150 | 0.08919 0.60103 151 | 0.16344 0.61666 152 | 0.22206 0.63229 153 | 0.30804 0.59321 154 | 0.36666 0.63620 155 | 0.42919 0.62447 156 | 0.48390 0.58149 157 | 0.54643 0.57758 158 | 0.59333 0.59712 159 | 0.65195 0.60884 160 | 0.73793 0.58930 161 | 0.78092 0.61275 162 | 0.85517 0.60493 163 | 0.92161 0.62057 164 | 0.04620 0.67333 165 | 0.10873 0.65574 166 | 0.17126 0.68700 167 | 0.23770 0.69091 168 | 0.28459 0.64792 169 | 0.38229 0.69873 170 | 0.44091 0.68310 171 | 0.50344 0.64402 172 | 0.55816 0.65965 173 | 0.62069 0.66746 174 | 0.70275 0.65183 175 | 0.75747 0.67528 176 | 0.82781 0.66356 177 | 0.89034 0.67137 178 | 0.95287 0.69482 179 | 0.98804 0.64011 180 | 0.05402 0.73585 181 | 0.11264 0.71436 182 | 0.19862 0.74953 183 | 0.26114 0.74562 184 | 0.31586 0.70264 185 | 0.33931 0.75344 186 | 0.46045 0.73390 187 | 0.51517 0.71045 188 | 0.57770 0.72218 189 | 0.60505 0.76126 190 | 0.65977 0.70654 191 | 0.72229 0.72608 192 | 0.80436 0.71827 193 | 0.86689 0.72999 194 | 0.94115 0.75735 195 | 0.05793 0.79448 196 | 0.12045 0.76907 197 | 0.16735 0.80425 198 | 0.24160 0.81206 199 | 0.30413 0.80034 200 | 0.39402 0.77298 201 | 0.44873 0.78861 202 | 0.49563 0.82379 203 | 0.53471 0.78080 204 | 0.64023 0.81988 205 | 0.67540 0.76516 206 | 0.72620 0.79252 207 | 0.80046 0.77689 208 | 0.86298 0.78471 209 | 0.92942 0.81597 210 | 0.99195 0.80815 211 | 0.03057 0.86091 212 | 0.10482 0.84333 213 | 0.17517 0.85896 214 | 0.22988 0.87850 215 | 0.29241 0.86287 216 | 0.35103 0.83551 217 | 0.42137 0.84723 218 | 0.52298 0.88631 219 | 0.57379 0.83160 220 | 0.59724 0.88241 221 | 0.68712 0.85114 222 | 0.74965 0.87459 223 | 0.77701 0.82769 224 | 0.83954 0.83942 225 | 0.90597 0.86677 226 | 0.98023 0.87068 227 | 0.00321 0.92344 228 | 0.08137 0.89999 229 | 0.13999 0.90195 230 | 0.17907 0.94494 231 | 0.27287 0.92930 232 | 0.33149 0.92149 233 | 0.37448 0.89413 234 | 0.43310 0.92540 235 | 0.47218 0.89022 236 | 0.58551 0.94103 237 | 0.64804 0.91758 238 | 0.70666 0.90976 239 | 0.76919 0.94884 240 | 0.80827 0.89804 241 | 0.85908 0.90585 242 | 0.91379 0.93712 243 | 0.96850 0.93321 244 | 0.01103 0.98597 245 | 0.06965 0.95471 246 | 0.12436 0.97620 247 | 0.23379 0.95666 248 | 0.31195 0.99183 249 | 0.38620 0.96057 250 | 0.45264 0.98402 251 | 0.51126 0.95275 252 | 0.56206 0.98792 253 | 0.63632 0.99965 254 | 0.69494 0.96838 255 | 0.83563 0.96448 256 | 0.89816 0.99574 -------------------------------------------------------------------------------- /bin/data/Poisson/poisson_256_2d_3d_flattened.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/data/Poisson/poisson_256_2d_3d_flattened.bin -------------------------------------------------------------------------------- /bin/data/Poisson/poisson_256_2d_3d_flattened_metadata.txt: -------------------------------------------------------------------------------- 1 | Number of points = 256 2 | Min X = 0.321 3 | Max X = 99.977 4 | Min Y = 0.309 5 | Max Y = 99.965 6 | Min Z = 50.0 7 | Max Z = 50.0 8 | Mean weight = 0.5 9 | -------------------------------------------------------------------------------- /bin/data/Poisson/poisson_4096_2d_3d.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/data/Poisson/poisson_4096_2d_3d.bin -------------------------------------------------------------------------------- /bin/data/Poisson/poisson_4096_2d_3d_bias=3.0.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/data/Poisson/poisson_4096_2d_3d_bias=3.0.bin -------------------------------------------------------------------------------- /bin/data/Poisson/poisson_4096_2d_3d_bias=3.0_metadata.txt: -------------------------------------------------------------------------------- 1 | Number of points = 4096 2 | Min X = 0.009 3 | Max X = 99.985 4 | Min Y = 0.009 5 | Max Y = 99.985 6 | Min Z = 2.8390361e-11 7 | Max Z = 99.95091 8 | Mean weight = 0.24719092 9 | -------------------------------------------------------------------------------- /bin/data/Poisson/poisson_4096_2d_3d_bias=4.0.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/data/Poisson/poisson_4096_2d_3d_bias=4.0.bin -------------------------------------------------------------------------------- /bin/data/Poisson/poisson_4096_2d_3d_bias=4.0_metadata.txt: -------------------------------------------------------------------------------- 1 | Number of points = 4096 2 | Min X = 0.009 3 | Max X = 99.985 4 | Min Y = 0.009 5 | Max Y = 99.985 6 | Min Z = 3.0046722e-14 7 | Max Z = 99.89874 8 | Mean weight = 0.19968694 9 | -------------------------------------------------------------------------------- /bin/data/Poisson/poisson_4096_2d_3d_flattened.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/data/Poisson/poisson_4096_2d_3d_flattened.bin -------------------------------------------------------------------------------- /bin/data/Poisson/poisson_4096_2d_3d_flattened_metadata.txt: -------------------------------------------------------------------------------- 1 | Number of points = 4096 2 | Min X = 0.009 3 | Max X = 99.985 4 | Min Y = 0.009 5 | Max Y = 99.985 6 | Min Z = 50.0 7 | Max Z = 50.0 8 | Mean weight = 0.5 9 | -------------------------------------------------------------------------------- /bin/data/Poisson/poisson_4096_2d_3d_metadata.txt: -------------------------------------------------------------------------------- 1 | Number of points = 4096 2 | Min X = 0.009 3 | Max X = 99.985 4 | Min Y = 0.009 5 | Max Y = 99.985 6 | Min Z = 0.05045948 7 | Max Z = 99.99182 8 | Mean weight = 1.0 9 | -------------------------------------------------------------------------------- /bin/data/Poisson/random_4096_3d.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/data/Poisson/random_4096_3d.bin -------------------------------------------------------------------------------- /bin/data/Poisson/random_4096_3d_bias=3.0.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/data/Poisson/random_4096_3d_bias=3.0.bin -------------------------------------------------------------------------------- /bin/data/Poisson/random_4096_3d_bias=3.0_metadata.txt: -------------------------------------------------------------------------------- 1 | Number of points = 4096 2 | Min X = 0.09651001 3 | Max X = 99.92619 4 | Min Y = 0.022577174 5 | Max Y = 99.99224 6 | Min Z = 2.9920244e-12 7 | Max Z = 99.99497 8 | Mean weight = 0.24974537 9 | -------------------------------------------------------------------------------- /bin/data/Poisson/random_4096_3d_bias=4.0.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/data/Poisson/random_4096_3d_bias=4.0.bin -------------------------------------------------------------------------------- /bin/data/Poisson/random_4096_3d_bias=4.0_metadata.txt: -------------------------------------------------------------------------------- 1 | Number of points = 4096 2 | Min X = 0.0027847835 3 | Max X = 99.973785 4 | Min Y = 0.032550775 5 | Max Y = 99.91945 6 | Min Z = 1.9194192e-13 7 | Max Z = 99.99042 8 | Mean weight = 0.1962329 9 | -------------------------------------------------------------------------------- /bin/data/Poisson/random_4096_3d_metadata.txt: -------------------------------------------------------------------------------- 1 | Number of points = 4096 2 | Min X = 0.048511274 3 | Max X = 99.985306 4 | Min Y = 0.020293586 5 | Max Y = 99.99692 6 | Min Z = 0.042331498 7 | Max Z = 99.97783 8 | Mean weight = 1.0 9 | -------------------------------------------------------------------------------- /bin/data/Poisson/regular_4096_3d.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/data/Poisson/regular_4096_3d.bin -------------------------------------------------------------------------------- /bin/data/Poisson/regular_4096_3d_bias=3.0.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/data/Poisson/regular_4096_3d_bias=3.0.bin -------------------------------------------------------------------------------- /bin/data/Poisson/regular_4096_3d_bias=3.0_metadata.txt: -------------------------------------------------------------------------------- 1 | Number of points = 4096 2 | Min X = 0.0 3 | Max X = 100.0 4 | Min Y = 0.0 5 | Max Y = 100.0 6 | Min Z = 0.0 7 | Max Z = 100.0 8 | Mean weight = 0.26666668 9 | -------------------------------------------------------------------------------- /bin/data/Poisson/regular_4096_3d_bias=4.0.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/data/Poisson/regular_4096_3d_bias=4.0.bin -------------------------------------------------------------------------------- /bin/data/Poisson/regular_4096_3d_bias=4.0_metadata.txt: -------------------------------------------------------------------------------- 1 | Number of points = 4096 2 | Min X = 0.0 3 | Max X = 100.0 4 | Min Y = 0.0 5 | Max Y = 100.0 6 | Min Z = 0.0 7 | Max Z = 100.0 8 | Mean weight = 0.22013828 9 | -------------------------------------------------------------------------------- /bin/data/Poisson/regular_4096_3d_metadata.txt: -------------------------------------------------------------------------------- 1 | Number of points = 4096 2 | Min X = 0.0 3 | Max X = 100.0 4 | Min Y = 0.0 5 | Max Y = 100.0 6 | Min Z = 0.0 7 | Max Z = 100.0 8 | Mean weight = 1.0 9 | -------------------------------------------------------------------------------- /bin/data/SDSS/.gitignore: -------------------------------------------------------------------------------- 1 | /sdssGalaxy_rsdCorr_dbscan_e2p0ms3_dz0p001_m10p0_t=10.3.bin 2 | /sdssGalaxy_rsdCorr_dbscan_e2p0ms3_dz0p001_m10p0_t=10.3_metadata.txt 3 | -------------------------------------------------------------------------------- /bin/data/SDSS/galaxiesInSdssSlice_viz_bigger_lumdist_t=0.0.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/data/SDSS/galaxiesInSdssSlice_viz_bigger_lumdist_t=0.0.bin -------------------------------------------------------------------------------- /bin/data/SDSS/galaxiesInSdssSlice_viz_bigger_lumdist_t=0.0_metadata.txt: -------------------------------------------------------------------------------- 1 | Number of points = 37655 2 | Min X = -148.27219 3 | Max X = -7.0655794 4 | Min Y = -143.3676 5 | Max Y = 139.92603 6 | Min Z = -11.804932 7 | Max Z = 136.47922 8 | Mean weight = 0.013950215 9 | -------------------------------------------------------------------------------- /bin/data/Zoe/.gitignore: -------------------------------------------------------------------------------- 1 | /64-clean-JT-3Dskan.blend 2 | /64-clean-JT-3Dskan.blend1 3 | /64-clean-JT-3Dskan.obj 4 | /64-clean-JT-3Dskan_clean.mtl 5 | /64-clean-JT-3Dskan_clean.obj 6 | /64-clean-JT-3Dskan_clean_n=492891.bin 7 | /64-clean-JT-3Dskan_clean_n=492891_metadata.txt 8 | /64-clean-JT-3Dskan_n=492892.bin 9 | /64-clean-JT-3Dskan_n=492892_metadata.txt 10 | /64-clean-JT-3Dskan_nobottom.mtl 11 | /64-clean-JT-3Dskan_nobottom.obj 12 | /64-clean-JT-3Dskan_nobottom_n=18654.bin 13 | /64-clean-JT-3Dskan_nobottom_n=18654_metadata.txt 14 | /64-clean-JT-3Dskan_nobottom_n=9480.bin 15 | /64-clean-JT-3Dskan_nobottom_n=9480_metadata.txt 16 | -------------------------------------------------------------------------------- /bin/data/Zoe/64-clean-JT-3Dskan_nobottom.blend: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/data/Zoe/64-clean-JT-3Dskan_nobottom.blend -------------------------------------------------------------------------------- /bin/data/Zoe/64-clean-JT-3Dskan_nobottom_n=38102.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/data/Zoe/64-clean-JT-3Dskan_nobottom_n=38102.bin -------------------------------------------------------------------------------- /bin/data/Zoe/64-clean-JT-3Dskan_nobottom_n=38102_metadata.txt: -------------------------------------------------------------------------------- 1 | Number of points = 38102 2 | Min X = -90.60128 3 | Max X = 70.68778 4 | Min Y = -61.6432 5 | Max Y = 56.95748 6 | Min Z = -57.95948 7 | Max Z = -2.43354 8 | Mean weight = 1.0 9 | -------------------------------------------------------------------------------- /bin/data/Zoe/pack_data_Zoe.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import math as math 3 | import random 4 | 5 | fileName = '64-clean-JT-3Dskan_nobottom' 6 | scale_multiplier = 20.0 7 | subsampling_factor = 5.0 8 | 9 | valid_pt_number = 0 10 | with open(fileName + '.obj') as f: 11 | lines = f.readlines() 12 | data = np.zeros((len(lines)-1, 4), dtype=np.float32) 13 | for i, line in enumerate(lines): 14 | if not (line[0] == 'v' and line[1] == ' '): 15 | continue # not a valid point 16 | if random.uniform(0.0, 1.0) > 1.0/subsampling_factor: 17 | continue # randomly throw out vertices 18 | line = line.split(' ') 19 | x = scale_multiplier * float(line[1]) 20 | y = scale_multiplier * float(line[3]) 21 | z = -scale_multiplier * float(line[2]) 22 | # weight = float(line[4]) + float(line[5]) + float(line[6]) 23 | weight = 1.0 24 | data[valid_pt_number, :] = [x, y, z, weight] 25 | valid_pt_number += 1 26 | 27 | if (valid_pt_number == 0): 28 | print('No points found') 29 | exit() 30 | 31 | filtered_data = np.zeros((valid_pt_number, 4), dtype=np.float32) 32 | filtered_data = data[0:valid_pt_number, :] 33 | 34 | print('Min/Max X: ' + str(np.min(filtered_data[:,0])) + ' ' + str(np.max(filtered_data[:,0]))) 35 | print('Min/Max Y: ' + str(np.min(filtered_data[:,1])) + ' ' + str(np.max(filtered_data[:,1]))) 36 | print('Min/Max Z: ' + str(np.min(filtered_data[:,2])) + ' ' + str(np.max(filtered_data[:,2]))) 37 | print('Min/Max/Avg/Med weight: ' + str(np.min(filtered_data[:,3])) + ' ' + str(np.max(filtered_data[:,3])) + ' ' + str(np.mean(filtered_data[:,3])) + ' ' + str(np.median(filtered_data[:,3]))) 38 | print('Sample record: ' + str(filtered_data[0,:])) 39 | print('Number of records: ' + str(valid_pt_number)) 40 | 41 | output_file_name = fileName + '_n=' + str(valid_pt_number) 42 | 43 | metadata_file = open(output_file_name + "_metadata.txt", "w") 44 | metadata_file.write("Number of points = " + str(valid_pt_number) + "\n") 45 | metadata_file.write("Min X = " + str(np.min(filtered_data[:,0])) + "\n") 46 | metadata_file.write("Max X = " + str(np.max(filtered_data[:,0])) + "\n") 47 | metadata_file.write("Min Y = " + str(np.min(filtered_data[:,1])) + "\n") 48 | metadata_file.write("Max Y = " + str(np.max(filtered_data[:,1])) + "\n") 49 | metadata_file.write("Min Z = " + str(np.min(filtered_data[:,2])) + "\n") 50 | metadata_file.write("Max Z = " + str(np.max(filtered_data[:,2])) + "\n") 51 | metadata_file.write("Mean weight = " + str(np.mean(filtered_data[:,3])) + "\n") 52 | metadata_file.close() 53 | 54 | filtered_data = filtered_data.tofile(output_file_name + '.bin') 55 | -------------------------------------------------------------------------------- /bin/data/affect_palettes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/data/affect_palettes.png -------------------------------------------------------------------------------- /bin/data/palette_blue.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/data/palette_blue.tga -------------------------------------------------------------------------------- /bin/data/palette_cliff3.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/data/palette_cliff3.tga -------------------------------------------------------------------------------- /bin/data/palette_coldhot.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/data/palette_coldhot.tga -------------------------------------------------------------------------------- /bin/data/palette_eagle.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/data/palette_eagle.tga -------------------------------------------------------------------------------- /bin/data/palette_eagle2.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/data/palette_eagle2.tga -------------------------------------------------------------------------------- /bin/data/palette_gogh_blue.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/data/palette_gogh_blue.tga -------------------------------------------------------------------------------- /bin/data/palette_gogh_green.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/data/palette_gogh_green.tga -------------------------------------------------------------------------------- /bin/data/palette_hot.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/data/palette_hot.tga -------------------------------------------------------------------------------- /bin/data/palette_magma.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/data/palette_magma.tga -------------------------------------------------------------------------------- /bin/data/palette_magneto2.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/data/palette_magneto2.tga -------------------------------------------------------------------------------- /bin/data/palette_sunset2.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/data/palette_sunset2.tga -------------------------------------------------------------------------------- /bin/data/palette_sunset3.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/data/palette_sunset3.tga -------------------------------------------------------------------------------- /bin/data/palette_tropico.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/data/palette_tropico.tga -------------------------------------------------------------------------------- /bin/data/palette_vaneyck_green.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/data/palette_vaneyck_green.tga -------------------------------------------------------------------------------- /bin/data/palette_vaneyck_red.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/data/palette_vaneyck_red.tga -------------------------------------------------------------------------------- /bin/export/.gitignore: -------------------------------------------------------------------------------- 1 | /rerouting=0_deposit=linear/ 2 | /rerouting=0_deposit=log/ 3 | /rerouting=1_deposit=log/ 4 | /rerouting=1_deposit=linear/ 5 | -------------------------------------------------------------------------------- /bin/freetype271MT.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/freetype271MT.dll -------------------------------------------------------------------------------- /bin/obj/.gitignore: -------------------------------------------------------------------------------- 1 | /file_system.obj 2 | /font.obj 3 | /graphics.obj 4 | /input.obj 5 | /logging.obj 6 | /main.obj 7 | /maths.obj 8 | /memory.obj 9 | /platform.obj 10 | /random.obj 11 | /ui.obj 12 | -------------------------------------------------------------------------------- /bin/ps_volume_halocolor.hlsl: -------------------------------------------------------------------------------- 1 | struct PixelInput 2 | { 3 | float4 position_out: SV_POSITION; 4 | float3 texcoord_out: TEXCOORD; 5 | }; 6 | 7 | Texture3D tex_trace : register(t0); 8 | SamplerState tex_trace_sampler : register(s0); 9 | Texture3D tex_deposit : register(t1); 10 | SamplerState tex_deposit_sampler : register(s1); 11 | 12 | cbuffer ConfigBuffer : register(b4) 13 | { 14 | float4x4 projection_matrix; 15 | float4x4 view_matrix; 16 | float4x4 model_matrix; 17 | int texcoord_map; 18 | float trim_x_min; 19 | float trim_x_max; 20 | float trim_y_min; 21 | float trim_y_max; 22 | float trim_z_min; 23 | float trim_z_max; 24 | float trim_density; 25 | float world_width; 26 | float world_height; 27 | float world_depth; 28 | float screen_width; 29 | float screen_height; 30 | float sample_weight; 31 | float optical_thickness; 32 | float highlight_density; 33 | float galaxy_weight; 34 | float histogram_base; 35 | }; 36 | 37 | float remap(float val, float slope) 38 | { 39 | return 1.0 - exp(-slope * val); 40 | } 41 | 42 | float4 main(PixelInput input) : SV_TARGET 43 | { 44 | float4 fragment; 45 | if (input.texcoord_out.x < trim_x_min || input.texcoord_out.x > trim_x_max || 46 | input.texcoord_out.y < trim_y_min || input.texcoord_out.y > trim_y_max || 47 | input.texcoord_out.z < trim_z_min || input.texcoord_out.z > trim_z_max) { 48 | fragment = 0.0.xxxx; 49 | } 50 | else { 51 | float trace = 2.0 * tex_trace.Sample(tex_trace_sampler, input.texcoord_out.xyz); 52 | trace -= 0.166 * tex_trace.Sample(tex_trace_sampler, input.texcoord_out.xyz + float3( 1./world_width, 0, 0)); 53 | trace -= 0.166 * tex_trace.Sample(tex_trace_sampler, input.texcoord_out.xyz + float3(-1./world_width, 0, 0)); 54 | trace -= 0.166 * tex_trace.Sample(tex_trace_sampler, input.texcoord_out.xyz + float3(0, 1./world_height, 0)); 55 | trace -= 0.166 * tex_trace.Sample(tex_trace_sampler, input.texcoord_out.xyz + float3(0,-1./world_height, 0)); 56 | trace -= 0.166 * tex_trace.Sample(tex_trace_sampler, input.texcoord_out.xyz + float3(0, 0, 1./world_depth)); 57 | trace -= 0.166 * tex_trace.Sample(tex_trace_sampler, input.texcoord_out.xyz + float3(0, 0, -1./world_depth)); 58 | float t = sample_weight * (trace - trim_density); 59 | float2 deposit = tex_deposit.Sample(tex_deposit_sampler, input.texcoord_out.xyz).xy; 60 | float2 d = galaxy_weight * deposit; 61 | 62 | fragment.rgb = remap(t, 0.6) * float3(0.5, 0.5, 0.5); 63 | if (d.y > 0.0) 64 | fragment.rgb += remap(d.x, 0.1) * float3(0.0, 0.0, 0.8); 65 | else// if (d.y < 0.0) 66 | fragment.rgb += remap(d.x, 0.1) * float3(0.7, 0.0, 0.0); 67 | // else 68 | // fragment.rgb += remap(d.x, 0.1) * float3(0.0, 0.6, 0.0); 69 | 70 | fragment.a = (0.3*t + 0.15*d.x) * optical_thickness; 71 | } 72 | 73 | fragment.rgb *= 2.0; // Compensate for the drawing 1 stack of meta-quads instead of 3 74 | return fragment; 75 | } -------------------------------------------------------------------------------- /bin/renner-book.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/bin/renner-book.otf -------------------------------------------------------------------------------- /build_and_run.bat: -------------------------------------------------------------------------------- 1 | build run polyphorm.build --release 2 | cd bin 3 | polyphorm.exe 4 | cd .. -------------------------------------------------------------------------------- /builder/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project (builder) 2 | 3 | add_executable(builder main.cpp) 4 | 5 | target_link_libraries(builder Shlwapi.lib) -------------------------------------------------------------------------------- /builder/bin/.gitignore: -------------------------------------------------------------------------------- 1 | /build.pdb 2 | /vc140.pdb 3 | -------------------------------------------------------------------------------- /builder/bin/build.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/builder/bin/build.exe -------------------------------------------------------------------------------- /builder/bin/obj/main.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/builder/bin/obj/main.obj -------------------------------------------------------------------------------- /builder/build.bat: -------------------------------------------------------------------------------- 1 | if not exist "bin" mkdir bin 2 | if not exist "bin\\obj" mkdir bin\\obj 3 | call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" x64 4 | call cl.exe main.cpp /nologo /W3 /Od /RTC1 /MTd /EHsc /Zc:inline /Gm- /MP /Fo:bin\\obj\\ /Fd:bin\\ /Zi /DDEBUG /link /INCREMENTAL:NO /subsystem:console /MACHINE:X64 /debug:fastlink /CGTHREADS:4 Shlwapi.lib Advapi32.lib ole32.lib oleaut32.lib /OUT:bin\\build.exe -------------------------------------------------------------------------------- /builder/config.h: -------------------------------------------------------------------------------- 1 | #include "microsoft_craziness.h" 2 | 3 | namespace config 4 | { 5 | // NEW ENVIRONMENTAL VARS 6 | char *env_var_new_info[3]; 7 | const uint32_t env_var_new_info_count = ARRAYSIZE(env_var_new_info); 8 | 9 | char *args_debug = "--debug"; 10 | char *args_release = "--release"; 11 | char *args_clean = "--clean"; 12 | char *args_run = "run"; 13 | 14 | #define CONFIG_BIN_DIR_VAR "bin" 15 | 16 | // OPTIMIZATION - /EHsc /fp:fast 17 | // MISC - MTd (static) Zc:inline? 18 | char *compiler_path = NULL; 19 | char *compiler_options_debug = "/nologo /W3 /Od /RTC1 /MDd /EHsc /Zc:inline /Gm- /MP /Fo:" CONFIG_BIN_DIR_VAR "\\obj\\ /Fd" CONFIG_BIN_DIR_VAR "\\ /Zi /DDEBUG /link /INCREMENTAL:NO /subsystem:console /MACHINE:X64 /debug:fastlink /CGTHREADS:4"; 20 | char *compiler_options_release = "/nologo /W3 /O2 /MD /EHsc /Zc:inline /Gm- /MP /Fo:" CONFIG_BIN_DIR_VAR "\\obj\\ /link /INCREMENTAL:NO /subsystem:console /MACHINE:X64 /debug:none /CGTHREADS:4"; 21 | char *exe_file_prefix = " /OUT:" CONFIG_BIN_DIR_VAR "\\"; 22 | 23 | void setup_paths() { 24 | Find_Result result = find_visual_studio_and_windows_sdk(); 25 | 26 | // Set CL.exe path. 27 | wchar_t *compiler_path_new = concat(result.vs_exe_path, L"\\cl.exe"); defer {free(compiler_path_new);}; 28 | int compiler_path_length = wcslen(compiler_path_new) + 1; 29 | compiler_path = (char *)malloc(compiler_path_length); 30 | wcstombs(compiler_path, compiler_path_new, compiler_path_length); 31 | 32 | // Set LIBPATH variable. 33 | wchar_t *libpath_new = concat(L"LIBPATH=", result.vs_library_path); defer {free(libpath_new);}; 34 | int libpath_length = wcslen(libpath_new) + 1; 35 | char *libpath = (char *)malloc(libpath_length); 36 | wcstombs(libpath, libpath_new, libpath_length); 37 | 38 | // Set LIB variable. 39 | wchar_t *lib_new1 = concat(L"LIB=", result.windows_sdk_ucrt_library_path, L";"); defer {free(lib_new1);}; 40 | wchar_t *lib_new2 = concat(lib_new1, result.windows_sdk_um_library_path, L";"); defer {free(lib_new2);}; 41 | wchar_t *lib_new3 = concat(lib_new2, result.vs_library_path, L";"); defer {free(lib_new3);}; 42 | int lib_length = wcslen(lib_new3) + 1; 43 | char *lib = (char *)malloc(lib_length); 44 | wcstombs(lib, lib_new3, lib_length); 45 | 46 | // Set INCLUDE variable. 47 | wchar_t *include_new1 = concat(L"INCLUDE=", result.vs_include_path, L";"); defer {free(include_new1);}; 48 | wchar_t *include_new2 = concat(include_new1, result.windows_sdk_um_include_path, L";"); defer {free(include_new2);}; 49 | wchar_t *include_new3 = concat(include_new2, result.windows_sdk_ucrt_include_path, L";"); defer {free(include_new3);}; 50 | wchar_t *include_new4 = concat(include_new3, result.windows_sdk_shared_include_path, L";"); defer {free(include_new4);}; 51 | int include_length = wcslen(include_new4) + 1; 52 | char *include = (char *)malloc(include_length); 53 | wcstombs(include, include_new4, include_length); 54 | 55 | // Update array with new env variables. 56 | env_var_new_info[0] = include; 57 | env_var_new_info[1] = libpath; 58 | env_var_new_info[2] = lib; 59 | 60 | // Clean up. 61 | free_resources(&result); 62 | }; 63 | } 64 | -------------------------------------------------------------------------------- /builder/environment.cpp: -------------------------------------------------------------------------------- 1 | uint32_t get_env_additional_info_length(char **env_additional_info, uint32_t env_additional_info_count) 2 | { 3 | uint32_t env_additional_info_length = 0; 4 | 5 | for(uint32_t i = 0; i < env_additional_info_count; ++i) 6 | { 7 | env_additional_info_length += string::length(env_additional_info[i]); 8 | } 9 | 10 | return env_additional_info_length; 11 | } 12 | 13 | uint32_t get_env_new_info_length(char **env_new_info, uint32_t env_new_info_count) 14 | { 15 | uint32_t env_new_info_length = 0; 16 | 17 | for(uint32_t i = 0; i < env_new_info_count; ++i) 18 | { 19 | env_new_info_length += string::length(env_new_info[i]) + 1; 20 | } 21 | 22 | return env_new_info_length; 23 | } 24 | 25 | uint32_t get_env_block_length(char *env_block) 26 | { 27 | // Counting also the last NULL terminating character (There are two NTCs at the end of the env block) 28 | uint32_t env_block_length = 1; 29 | while(true) 30 | { 31 | uint32_t env_var_length = string::length(env_block) + 1; 32 | env_block_length += env_var_length; 33 | env_block += env_var_length; 34 | if (*env_block == 0) break; 35 | } 36 | return env_block_length; 37 | } 38 | 39 | uint32_t get_var_name_length(char *var) 40 | { 41 | uint32_t length = 0; 42 | 43 | while(true) 44 | { 45 | if(*(var++) == '=') break; 46 | length++; 47 | } 48 | 49 | return length; 50 | } 51 | 52 | 53 | 54 | namespace environment 55 | { 56 | char *update_env_block(char *old_env_block, 57 | char **env_new_info, uint32_t env_new_info_count, 58 | AllocatorType allocator_type = PERSISTENT) 59 | { 60 | // Compute new env block length 61 | uint32_t old_env_block_length = get_env_block_length(old_env_block); 62 | uint32_t new_info_length = get_env_new_info_length(env_new_info, env_new_info_count); 63 | uint32_t new_env_block_length = old_env_block_length + new_info_length; 64 | 65 | // Allocate and prepare pointers 66 | char * new_env_block = memory::allocate(new_env_block_length, PERSISTENT); 67 | char *new_env_block_ptr = new_env_block; 68 | char *old_env_block_ptr = old_env_block; 69 | 70 | while(true) 71 | { 72 | // Get current variable and variable name lengths 73 | uint32_t var_name_length = get_var_name_length(old_env_block_ptr); 74 | uint32_t old_var_length = string::length(old_env_block_ptr); 75 | uint32_t new_var_length = old_var_length; 76 | 77 | // Copy over old content 78 | memcpy(new_env_block_ptr, old_env_block_ptr, old_var_length); 79 | 80 | // Add ntc to the end of the var 81 | new_env_block_ptr[new_var_length] = 0; 82 | 83 | // Move pointers and check for end 84 | new_env_block_ptr += new_var_length + 1; 85 | old_env_block_ptr += old_var_length + 1; // Skip NTC 86 | if (*old_env_block_ptr == 0) break; 87 | } 88 | 89 | // Add new info 90 | for (uint32_t i = 0; i < env_new_info_count; ++i) 91 | { 92 | uint32_t new_info_length = string::length(env_new_info[i]); 93 | memcpy(new_env_block_ptr, env_new_info[i], new_info_length); 94 | new_env_block_ptr[new_info_length] = 0; 95 | 96 | new_env_block_ptr += new_info_length + 1; 97 | } 98 | 99 | // Add final ntc 100 | new_env_block[new_env_block_length - 1] = 0; 101 | 102 | return new_env_block; 103 | } 104 | 105 | char *get_current_env_block() 106 | { 107 | return GetEnvironmentStrings(); 108 | } 109 | 110 | void free_env_block(char *env_block) 111 | { 112 | FreeEnvironmentStrings(env_block); 113 | } 114 | 115 | void print_env_block(char *env_block) 116 | { 117 | while(true) 118 | { 119 | printf("%s\n", env_block); 120 | env_block += string::length(env_block) + 1; 121 | if(*env_block == 0) break; 122 | } 123 | } 124 | } -------------------------------------------------------------------------------- /builder/memory.cpp: -------------------------------------------------------------------------------- 1 | struct Allocator 2 | { 3 | void *data; 4 | uint32_t size; 5 | uint32_t top; 6 | }; 7 | 8 | typedef uint32_t AllocatorState; 9 | 10 | enum AllocatorType 11 | { 12 | TEMPORARY, 13 | PERSISTENT 14 | }; 15 | 16 | namespace memory 17 | { 18 | static Allocator allocator_temporary; 19 | static Allocator allocator_persistent; 20 | 21 | static const uint32_t init_memory_size = 1000000; 22 | static void init() 23 | { 24 | allocator_temporary.data = malloc(init_memory_size); 25 | allocator_temporary.size = init_memory_size; 26 | allocator_temporary.top = 0; 27 | 28 | allocator_persistent.data = malloc(init_memory_size); 29 | allocator_persistent.size = init_memory_size; 30 | allocator_persistent.top = 0; 31 | } 32 | 33 | template 34 | static T *allocate(uint32_t count, AllocatorType type = TEMPORARY) 35 | { 36 | Allocator *allocator = type == TEMPORARY ? &allocator_temporary : &allocator_persistent; 37 | 38 | if(allocator->top + count > allocator->size) 39 | { 40 | allocator->size *= 2; 41 | allocator->data = realloc(allocator->data, allocator->size); 42 | } 43 | 44 | T *result = (T *)((char *)allocator->data + allocator->top); 45 | allocator->top += sizeof(T) * count; 46 | 47 | return result; 48 | } 49 | 50 | static AllocatorState set(AllocatorType type = TEMPORARY) 51 | { 52 | Allocator *allocator = type == TEMPORARY ? &allocator_temporary : &allocator_persistent; 53 | return allocator->top; 54 | } 55 | 56 | static void reset(AllocatorState state, AllocatorType type = TEMPORARY) 57 | { 58 | Allocator *allocator = type == TEMPORARY ? &allocator_temporary : &allocator_persistent; 59 | allocator->top = state; 60 | } 61 | }; 62 | -------------------------------------------------------------------------------- /builder/setup.bat: -------------------------------------------------------------------------------- 1 | echo off 2 | setx "path=%PATH%;%cd%\bin" -------------------------------------------------------------------------------- /builder/string.cpp: -------------------------------------------------------------------------------- 1 | namespace string 2 | { 3 | uint32_t length(char *string) 4 | { 5 | return (uint32_t) strlen(string); 6 | } 7 | 8 | char *create_null_terminated(char *string, uint32_t string_length, AllocatorType allocator_type = PERSISTENT) 9 | { 10 | char *nt_string = memory::allocate(string_length + 1, allocator_type); 11 | memcpy(nt_string, string, string_length); 12 | nt_string[string_length] = 0; 13 | return nt_string; 14 | } 15 | 16 | bool equals(char *string1, char *string2, uint32_t max_length) 17 | { 18 | return strncmp(string1, string2, max_length) == 0; 19 | } 20 | 21 | bool equals(char *string1, char *string2) 22 | { 23 | return strcmp(string1, string2) == 0; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /builder/structs.h: -------------------------------------------------------------------------------- 1 | // TODO: Switch to general expandable arrays 2 | struct FileList 3 | { 4 | char *file_path; 5 | FileList *next_file; 6 | }; 7 | 8 | struct CopyFileBatch 9 | { 10 | FileList *source_files; 11 | char *target_directory; 12 | 13 | CopyFileBatch *next_batch; 14 | }; 15 | 16 | struct BuildSettings 17 | { 18 | FileList *source_files; 19 | FileList *pre_hash_files; 20 | FileList *libraries; 21 | FileList *include_directories; 22 | char *target_exe_name; 23 | 24 | CopyFileBatch *copy_files; 25 | }; 26 | -------------------------------------------------------------------------------- /builder/sys_utils.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | typedef LARGE_INTEGER Ticks; 4 | 5 | namespace sys_utils 6 | { 7 | Ticks get_ticks() 8 | { 9 | LARGE_INTEGER ticks; 10 | 11 | QueryPerformanceCounter(&ticks); 12 | 13 | return (Ticks)ticks; 14 | } 15 | 16 | Ticks get_tick_frequency() 17 | { 18 | LARGE_INTEGER frequency; 19 | 20 | QueryPerformanceFrequency(&frequency); 21 | 22 | return (Ticks)frequency; 23 | } 24 | 25 | float get_dt_from_tick_difference(Ticks t1, Ticks t2, Ticks frequency) 26 | { 27 | float dt = (float)((t2.QuadPart - t1.QuadPart) / (double)frequency.QuadPart); 28 | return dt; 29 | } 30 | 31 | char *get_current_time_and_date_string(char *date_format, char *time_format, bool date_first = true, AllocatorType allocator_type = PERSISTENT) 32 | { 33 | SYSTEMTIME current_time; 34 | GetLocalTime(¤t_time); 35 | 36 | uint32_t bytes_needed_date = GetDateFormat(LOCALE_USER_DEFAULT, NULL, ¤t_time, date_format, NULL, 0); 37 | if (bytes_needed_date == 0) 38 | { 39 | printf("Error obtaining date format string.\n"); 40 | return NULL; 41 | } 42 | 43 | uint32_t bytes_needed_time = GetTimeFormat(LOCALE_USER_DEFAULT, NULL, ¤t_time, time_format, NULL, 0); 44 | if (bytes_needed_time == 0) 45 | { 46 | printf("Error obtaining time format string.\n"); 47 | return NULL; 48 | } 49 | 50 | uint32_t bytes_needed_total = bytes_needed_date + bytes_needed_time - 1; // Don't count ntc twice 51 | auto mem_state_temp = memory::set(allocator_type); 52 | char *time_date_string_buffer = memory::allocate(bytes_needed_total, allocator_type); 53 | char *date_part = date_first ? time_date_string_buffer : time_date_string_buffer + bytes_needed_time - 1; 54 | char *time_part = date_first ? time_date_string_buffer + bytes_needed_date - 1 : time_date_string_buffer; 55 | 56 | if(date_first) 57 | { 58 | uint32_t bytes_written_date = GetDateFormat(LOCALE_USER_DEFAULT, NULL, ¤t_time, date_format, date_part, bytes_needed_date); 59 | if (bytes_written_date == 0) 60 | { 61 | printf("Error obtaining date format string.\n"); 62 | memory::reset(mem_state_temp, allocator_type); 63 | return NULL; 64 | } 65 | } 66 | 67 | uint32_t bytes_written_time = GetTimeFormat(LOCALE_USER_DEFAULT, NULL, ¤t_time, time_format, time_part, bytes_needed_time); 68 | if (bytes_written_time == 0) 69 | { 70 | printf("Error obtaining time format string.\n"); 71 | memory::reset(mem_state_temp, allocator_type); 72 | return NULL; 73 | } 74 | 75 | if(!date_first) 76 | { 77 | uint32_t bytes_written_date = GetDateFormat(LOCALE_USER_DEFAULT, NULL, ¤t_time, date_format, date_part, bytes_needed_date); 78 | if (bytes_written_date == 0) 79 | { 80 | printf("Error obtaining date format string.\n"); 81 | memory::reset(mem_state_temp, allocator_type); 82 | return NULL; 83 | } 84 | } 85 | 86 | return time_date_string_buffer; 87 | } 88 | } 89 | 90 | struct Timer 91 | { 92 | Ticks frequency; 93 | Ticks start; 94 | }; 95 | 96 | namespace timer 97 | { 98 | Timer get() 99 | { 100 | Timer timer = {}; 101 | timer.frequency = sys_utils::get_tick_frequency(); 102 | return timer; 103 | } 104 | 105 | void start(Timer *timer) 106 | { 107 | timer->start = sys_utils::get_ticks(); 108 | } 109 | 110 | float end(Timer *timer) 111 | { 112 | Ticks current = sys_utils::get_ticks(); 113 | float dt = sys_utils::get_dt_from_tick_difference(timer->start, current, timer->frequency); 114 | return dt; 115 | } 116 | 117 | float checkpoint(Timer *timer) 118 | { 119 | Ticks current = sys_utils::get_ticks(); 120 | float dt = sys_utils::get_dt_from_tick_difference(timer->start, current, timer->frequency); 121 | timer->start = current; 122 | 123 | return dt; 124 | } 125 | } -------------------------------------------------------------------------------- /cpplib/animation.cpp: -------------------------------------------------------------------------------- 1 | #include "animation.h" 2 | #include "memory.h" 3 | 4 | Matrix4x4 matrix_from_transform(Transform transform) 5 | { 6 | Matrix4x4 scale_matrix = math::get_scale(transform.scale); 7 | Matrix4x4 translation_matrix = math::get_translation(transform.translation); 8 | Matrix4x4 rotation_matrix = math::get_rotation(transform.rotation); 9 | 10 | Matrix4x4 result = translation_matrix * rotation_matrix * scale_matrix; 11 | return result; 12 | } 13 | 14 | Transform interpolate(Transform t1, Transform t2, float t) 15 | { 16 | Transform result = {}; 17 | result.scale = math::lerp(t1.scale, t2.scale, t); 18 | result.translation = math::lerp(t1.translation, t2.translation, t); 19 | if (math::dot(t1.rotation, t2.rotation) < 0.0f) 20 | { 21 | result.rotation = math::nlerp(-t1.rotation, t2.rotation, t); 22 | } 23 | else 24 | { 25 | result.rotation = math::nlerp(t1.rotation, t2.rotation, t); 26 | } 27 | return result; 28 | } 29 | 30 | AnimationPlayer animation::get(Skeleton skeleton, Animation *animations, uint32_t animation_count) 31 | { 32 | AnimationPlayer player = {}; 33 | 34 | player.skeleton = skeleton; 35 | player.animations = animations; 36 | player.animation_count = animation_count; 37 | player.output_matrices = memory::alloc_heap(skeleton.bones.count); 38 | 39 | return player; 40 | } 41 | 42 | void animation::update(AnimationPlayer *player, float dt) 43 | { 44 | player->current_time += dt; 45 | Animation *current_animation = &player->animations[player->current_animation]; 46 | if(player->current_time >= current_animation->duration) 47 | { 48 | player->current_time = 0.0f; 49 | player->current_animation = 1 - player->current_animation; 50 | } 51 | } 52 | 53 | void animation::evaluate(AnimationPlayer *player) 54 | { 55 | Animation *animation = &player->animations[player->current_animation]; 56 | Skeleton *skeleton = &player->skeleton; 57 | float current_part = player->current_time / animation->duration * (animation->frame_count - 1); 58 | uint32_t current_frame = (uint32_t)math::floor(current_part); 59 | float fraction = current_part - (float)current_frame; 60 | current_frame = math::clamp(current_frame, (uint32_t)0, animation->frame_count - 1); 61 | 62 | for (uint32_t i = 0; i < skeleton->bones.count; ++i) 63 | { 64 | Transform local_transform_current = animation->key_frames[current_frame].bone_transforms[i]; 65 | Transform local_transform_next = animation->key_frames[current_frame + 1].bone_transforms[i]; 66 | Transform local_transform = interpolate(local_transform_current, local_transform_next, fraction); 67 | Matrix4x4 local_mat = matrix_from_transform(local_transform); 68 | Matrix4x4 local_mat2 = local_transform.matrix; 69 | int32_t parent_index = skeleton->bones.data[i].parent_idx; 70 | Matrix4x4 parent_mat = math::get_identity(); 71 | if(parent_index >= 0) 72 | { 73 | parent_mat = player->output_matrices[parent_index]; 74 | } 75 | player->output_matrices[i] = parent_mat * local_mat; 76 | } 77 | for (uint32_t i = 0; i < skeleton->bones.count; ++i) 78 | { 79 | Bone *bone = &skeleton->bones.data[i]; 80 | Matrix4x4 mat = bone->world_from_bind_pose; 81 | player->output_matrices[i] = player->output_matrices[i] * bone->bind_pose_from_world; 82 | //player->output_matrices[i] = bone->world_from_bind_pose * bone->bind_pose_from_world; 83 | } 84 | } -------------------------------------------------------------------------------- /cpplib/animation.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "array.h" 3 | #include "maths.h" 4 | 5 | struct Bone 6 | { 7 | const char *name; 8 | int32_t parent_idx; 9 | 10 | Matrix4x4 world_from_bind_pose; 11 | Matrix4x4 bind_pose_from_world; 12 | }; 13 | 14 | struct ControlPoint 15 | { 16 | int32_t bone_indices[4]; 17 | float bone_weights[4]; 18 | 19 | uint32_t bone_count = 0; 20 | }; 21 | 22 | struct Skeleton 23 | { 24 | Array bones; 25 | 26 | ControlPoint *control_points; 27 | uint32_t control_point_count; 28 | int32_t *vertex_to_control_point; 29 | uint32_t vertex_count; 30 | }; 31 | 32 | struct Transform 33 | { 34 | Quaternion rotation; 35 | Vector3 scale; 36 | Vector3 translation; 37 | Matrix4x4 matrix; 38 | }; 39 | 40 | struct KeyFrame 41 | { 42 | Transform *bone_transforms; 43 | }; 44 | 45 | struct Animation 46 | { 47 | KeyFrame *key_frames; 48 | uint32_t frame_count; 49 | uint32_t bone_count; 50 | 51 | char *name; 52 | float duration; 53 | uint32_t fps; 54 | }; 55 | 56 | struct AnimationPlayer 57 | { 58 | Skeleton skeleton; 59 | Animation *animations; 60 | uint32_t animation_count; 61 | 62 | uint32_t current_animation = 0; 63 | float current_time = 0; 64 | 65 | Matrix4x4 *output_matrices; 66 | }; 67 | 68 | namespace animation 69 | { 70 | AnimationPlayer get(Skeleton skeleton, Animation *animations, uint32_t animation_count); 71 | void update(AnimationPlayer *player, float dt); 72 | void evaluate(AnimationPlayer *player); 73 | } -------------------------------------------------------------------------------- /cpplib/array.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include "memory.h" 6 | 7 | // Array is a data struct used as a dynamically allocated list. 8 | template 9 | struct Array 10 | { 11 | T *data; 12 | uint32_t count; 13 | uint32_t size; 14 | 15 | T& operator[](uint32_t index) 16 | { 17 | return (this->data[index]); 18 | } 19 | }; 20 | 21 | 22 | // `array` namespace handles operations on Array. 23 | namespace array 24 | { 25 | // array_expansion_ratio defines the ratio of new array size to old array size when reallocating. 26 | const uint32_t array_expansion_ratio = 2; 27 | 28 | // Initialize Array 29 | template 30 | void init(Array *array, uint32_t size) 31 | { 32 | array->size = size; 33 | array->count = 0; 34 | array->data = memory::alloc_heap(size); 35 | assert(array->data); 36 | } 37 | 38 | // Returns initialized Array 39 | template 40 | Array get(uint32_t size) 41 | { 42 | Array array; 43 | array::init(&array, size); 44 | return array; 45 | } 46 | 47 | // Reset the array, does not deallocate allocated memory 48 | template 49 | void reset(Array *array) 50 | { 51 | array->count = 0; 52 | } 53 | 54 | // Add an element into array, possibly reallocate and move all the contents 55 | template 56 | void add(Array *array, T item) 57 | { 58 | // In case the array is full, reallocate 59 | if(array->size == array->count) 60 | { 61 | T *new_mem = memory::alloc_heap(array->size * array_expansion_ratio); 62 | assert(new_mem); 63 | memcpy(new_mem, array->data, sizeof(T) * array->size); 64 | memory::free_heap(array->data); 65 | array->data = new_mem; 66 | array->size *= array_expansion_ratio; 67 | } 68 | 69 | array->data[array->count++] = item; 70 | } 71 | 72 | // Completely release the array, freeing all the memory 73 | template 74 | void release(Array *array) 75 | { 76 | memory::free_heap(array->data); 77 | array->size = 0; 78 | array->count = 0; 79 | } 80 | } -------------------------------------------------------------------------------- /cpplib/audio.cpp: -------------------------------------------------------------------------------- 1 | #define _CRT_SECURE_NO_WARNINGS 2 | #include "audio.h" 3 | #include 4 | #include "stb_vorbis.c" 5 | 6 | #ifdef CPPLIB_DEBUG_PRINTS 7 | #include "logging.h" 8 | #define PRINT_DEBUG(message, ...) logging::print_error(message, ##__VA_ARGS__) 9 | #else 10 | #define PRINT_DEBUG(message, ...) 11 | #endif 12 | 13 | static AudioContext audio_context_; 14 | static AudioContext *audio_context = &audio_context_; 15 | 16 | // NOTE: Audio module releasing facilities aren't tested, so there may be some issues here 17 | bool audio::init() 18 | { 19 | CoInitialize(NULL); 20 | 21 | HRESULT hr = XAudio2Create(&audio_context->engine, 0, XAUDIO2_DEFAULT_PROCESSOR); 22 | if (FAILED(hr)) { 23 | PRINT_DEBUG("Failed to create XAudio2 engine."); 24 | return false; 25 | } 26 | hr = audio_context->engine->CreateMasteringVoice(&audio_context->master_voice); 27 | if (FAILED(hr)) { 28 | PRINT_DEBUG("Failed to create IXAudio2MasteringVoice."); 29 | return false; 30 | } 31 | 32 | #ifdef DEBUG 33 | XAUDIO2_DEBUG_CONFIGURATION debug_config = {}; 34 | debug_config.TraceMask = XAUDIO2_LOG_ERRORS | XAUDIO2_LOG_WARNINGS | XAUDIO2_LOG_MEMORY; 35 | audio_context->engine->SetDebugConfiguration(&debug_config, NULL); 36 | #endif 37 | 38 | return true; 39 | } 40 | 41 | Sound audio::get_sound_ogg(void *data, uint32_t data_size) 42 | { 43 | Sound sound = {}; 44 | sound.sample_count = stb_vorbis_decode_memory((uint8_t *)data, data_size, &sound.channels, &sound.sample_rate, &sound.samples); 45 | 46 | WAVEFORMATEX wfx = {}; 47 | wfx.wFormatTag = WAVE_FORMAT_PCM; 48 | wfx.nChannels = sound.channels; 49 | wfx.nSamplesPerSec = sound.sample_rate; 50 | wfx.nBlockAlign = 4; 51 | wfx.wBitsPerSample = 16; 52 | wfx.nAvgBytesPerSec = sound.sample_rate * 4; 53 | 54 | XAUDIO2_BUFFER buffer = {}; 55 | buffer.AudioBytes = sound.sample_count * sound.channels * 2; 56 | buffer.pAudioData = (uint8_t *)sound.samples; 57 | buffer.PlayBegin = 0; 58 | buffer.PlayLength = sound.sample_count; 59 | buffer.LoopBegin = 0; 60 | buffer.LoopLength = sound.sample_count; 61 | buffer.LoopCount = XAUDIO2_LOOP_INFINITE; 62 | 63 | HRESULT hr = audio_context->engine->CreateSourceVoice(&sound.source_voice, &wfx); 64 | if(FAILED(hr)) { 65 | PRINT_DEBUG("Failed to create IXAudio2SourceVoice."); 66 | return Sound{}; 67 | } 68 | 69 | hr = sound.source_voice->SubmitSourceBuffer(&buffer); 70 | if(FAILED(hr)) { 71 | sound.source_voice->DestroyVoice(); 72 | PRINT_DEBUG("Failed to submit a source buffer."); 73 | return Sound{}; 74 | } 75 | 76 | return sound; 77 | } 78 | 79 | bool audio::play_sound(Sound *sound) 80 | { 81 | HRESULT hr = sound->source_voice->Start(0); 82 | if(FAILED(hr)) { 83 | PRINT_DEBUG("Failed to start a source voice."); 84 | return false; 85 | } 86 | return true; 87 | } 88 | 89 | float audio::get_playback_position(Sound *sound) 90 | { 91 | XAUDIO2_VOICE_STATE voice_state; 92 | sound->source_voice->GetState(&voice_state, 0); 93 | double samples_played = (double)voice_state.SamplesPlayed; 94 | double total_samples = (double)sound->sample_count; 95 | double duration = (double)sound->sample_count / (double)sound->sample_rate; 96 | double position = duration * samples_played / total_samples; 97 | return (float)position; 98 | } 99 | 100 | void audio::release(Sound *sound) 101 | { 102 | sound->source_voice->DestroyVoice(); 103 | free(sound->samples); 104 | *sound = {}; 105 | } -------------------------------------------------------------------------------- /cpplib/audio.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | struct IXAudio2; 5 | struct IXAudio2MasteringVoice; 6 | struct IXAudio2SourceVoice; 7 | 8 | struct Sound 9 | { 10 | int32_t channels; 11 | int32_t sample_rate; 12 | int32_t sample_count; 13 | int16_t *samples; 14 | IXAudio2SourceVoice *source_voice; 15 | }; 16 | 17 | struct AudioContext 18 | { 19 | IXAudio2 *engine; 20 | IXAudio2MasteringVoice *master_voice; 21 | }; 22 | 23 | namespace audio 24 | { 25 | bool init(); 26 | 27 | Sound get_sound_ogg(void *data, uint32_t data_size); 28 | bool play_sound(Sound *sound); 29 | float get_playback_position(Sound *sound); 30 | void release(Sound *sound); 31 | } -------------------------------------------------------------------------------- /cpplib/export.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "export.h" 4 | #include "file_system.h" 5 | #include "memory.h" 6 | #ifdef CPPLIB_DEBUG_PRINTS 7 | #include "logging.h" 8 | #define PRINT_DEBUG(message, ...) logging::print_error(message, ##__VA_ARGS__) 9 | #else 10 | #define PRINT_DEBUG(message, ...) 11 | #endif 12 | 13 | #define print_to_string sprintf_s 14 | 15 | bool exports::export_to_obj(char *filename, Vector4 *vertices, uint32_t vertex_count, uint32_t vertex_stride, uint16_t *indices, uint32_t index_count) 16 | { 17 | uint32_t number_of_lines = vertex_count * 2 + index_count / 3; 18 | uint32_t max_line_length = 50; // Should suffice for +-10000 19 | 20 | uint32_t total_file_size = number_of_lines * max_line_length; 21 | 22 | char *file_memory = memory::alloc_heap(total_file_size); 23 | char *file_ptr = file_memory; 24 | 25 | int32_t size_left = total_file_size; 26 | for (uint32_t i = 0; i < vertex_count; ++i) 27 | { 28 | Vector4 vertex_position = vertices[i * 2]; 29 | uint32_t bytes_written = print_to_string(file_ptr, size_left, "v %.4f %.4f %.4f %.4f\n", vertex_position.x, vertex_position.y, vertex_position.z, vertex_position.w); 30 | if (bytes_written > max_line_length) 31 | { 32 | PRINT_DEBUG("export_to_obj: expected maximum output line length was %d, actual was %d. This may or may not cause errors.", max_line_length, bytes_written); 33 | } 34 | file_ptr += bytes_written; 35 | size_left -= bytes_written; 36 | if (size_left <= 0) 37 | { 38 | PRINT_DEBUG("Buffer overflow while exporting to OBJ!"); 39 | } 40 | } 41 | for (uint32_t i = 0; i < vertex_count; ++i) 42 | { 43 | Vector4 vertex_normal = vertices[i * 2 + 1]; 44 | uint32_t bytes_written = print_to_string(file_ptr, size_left, "vn %.4f %.4f %.4f %.4f\n", vertex_normal.x, vertex_normal.y, vertex_normal.z, vertex_normal.w); 45 | file_ptr += bytes_written; 46 | size_left -= bytes_written; 47 | if (size_left <= 0) 48 | { 49 | PRINT_DEBUG("Buffer overflow while exporting to OBJ!"); 50 | } 51 | } 52 | 53 | for (uint32_t i = 0; i < index_count; i += 3) 54 | { 55 | uint16_t i1 = indices[i] + 1; 56 | uint16_t i2 = indices[i + 1] + 1; 57 | uint16_t i3 = indices[i + 2] + 1; 58 | uint32_t bytes_written = print_to_string(file_ptr, size_left, "f %d//%d %d//%d %d//%d\n", i1, i1, i2, i2, i3, i3); 59 | file_ptr += bytes_written; 60 | size_left -= bytes_written; 61 | if (size_left <= 0) 62 | { 63 | PRINT_DEBUG("Buffer overflow while exporting to OBJ!"); 64 | } 65 | } 66 | 67 | if (!file_system::write_file(filename, file_memory, total_file_size - size_left)) 68 | { 69 | PRINT_DEBUG("Could not write mesh to %s.", filename); 70 | return false; 71 | } 72 | memory::free_heap(file_memory); 73 | return true; 74 | } -------------------------------------------------------------------------------- /cpplib/export.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "maths.h" 3 | 4 | namespace exports 5 | { 6 | bool export_to_obj(char *filename, Vector4 *vertices, uint32_t vertex_count, uint32_t vertex_stride, uint16_t *indices, uint32_t index_count); 7 | } -------------------------------------------------------------------------------- /cpplib/fbx_loader.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include "array.h" 3 | #include "maths.h" 4 | struct Animation; 5 | struct Skeleton; 6 | 7 | struct MeshData 8 | { 9 | Vector4 *vertices; 10 | uint16_t *indices; 11 | uint32_t vertex_count; 12 | uint32_t index_count; 13 | }; 14 | 15 | namespace fbx 16 | { 17 | MeshData get_mesh(char *fbx_filename); 18 | MeshData get_animated_mesh(char *fbx_filename, Skeleton *skeleton, Animation **animations, uint32_t *animation_count); 19 | } 20 | 21 | 22 | -------------------------------------------------------------------------------- /cpplib/file_system.cpp: -------------------------------------------------------------------------------- 1 | #include "file_system.h" 2 | #include 3 | 4 | #ifdef CPPLIB_DEBUG_PRINTS 5 | #include "logging.h" 6 | #define PRINT_DEBUG(message, ...) logging::print_error(message, ##__VA_ARGS__) 7 | #else 8 | #define PRINT_DEBUG(message, ...) 9 | #endif 10 | 11 | 12 | File file_system::read_file(const char* path) 13 | { 14 | File file = {}; 15 | 16 | // Open handle to a file 17 | HANDLE file_handle = CreateFileA(path, GENERIC_READ, NULL, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); 18 | if (file_handle == INVALID_HANDLE_VALUE) 19 | { 20 | PRINT_DEBUG("Unable to open read handle to file %s.", path); 21 | return file; 22 | } 23 | 24 | // Get file attributes, these are necessary to know how much data to allocate for reading 25 | WIN32_FILE_ATTRIBUTE_DATA file_attributes; 26 | if (!GetFileAttributesExA(path, GetFileExInfoStandard, &file_attributes)) 27 | { 28 | PRINT_DEBUG("Unable to get attributes of file %s.", path); 29 | CloseHandle(file_handle); 30 | return File{}; 31 | } 32 | 33 | // Allocate memory for reading the file contents 34 | uint32_t file_size = file_attributes.nFileSizeLow; 35 | HANDLE heap = GetProcessHeap(); 36 | file.data = HeapAlloc(heap, HEAP_ZERO_MEMORY, file_size); 37 | 38 | // Read the file into allocated memory 39 | DWORD bytes_read_from_file = 0; 40 | if (ReadFile(file_handle, file.data, file_size, &bytes_read_from_file, NULL) && 41 | bytes_read_from_file == file_size) 42 | { 43 | file.size = bytes_read_from_file; 44 | } 45 | else 46 | { 47 | // In case of read error, deallocate memory and close handle 48 | PRINT_DEBUG("Unable to read opened file %s.", path); 49 | HeapFree(heap, 0, file.data); 50 | CloseHandle(file_handle); 51 | return File{}; 52 | } 53 | 54 | // Succesfull file reading, close the handle and return the data 55 | CloseHandle(file_handle); 56 | return file; 57 | } 58 | 59 | void file_system::release_file(File file) 60 | { 61 | // Release allocated memory from the heap 62 | HANDLE heap = GetProcessHeap(); 63 | HeapFree(heap, 0, file.data); 64 | } 65 | 66 | uint32_t file_system::write_file(const char* path, void *data, uint32_t size) 67 | { 68 | // Open handle to a file 69 | HANDLE file_handle = 0; 70 | file_handle = CreateFileA(path, GENERIC_WRITE, NULL, NULL, CREATE_ALWAYS, 71 | FILE_ATTRIBUTE_NORMAL, NULL); 72 | if (file_handle == INVALID_HANDLE_VALUE) 73 | { 74 | PRINT_DEBUG("Unable to open write handle to file %s.", path); 75 | return 0; 76 | } 77 | 78 | // Write to a file 79 | DWORD bytes_written = 0; 80 | if(!WriteFile(file_handle, data, size, &bytes_written, NULL)) 81 | { 82 | PRINT_DEBUG("Unable to write to file %s.", path); 83 | return 0; 84 | } 85 | 86 | // Wrote sucessfully, close the handle 87 | CloseHandle(file_handle); 88 | return bytes_written; 89 | } 90 | -------------------------------------------------------------------------------- /cpplib/file_system.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | // File encapsulates data loaded from the file and its size. 5 | struct File 6 | { 7 | void *data; 8 | uint32_t size; 9 | }; 10 | 11 | // file_system namespace enables interfacing with the Windows file system 12 | namespace file_system 13 | { 14 | // Read file at path 15 | File read_file(const char* path); 16 | 17 | // Release read file 18 | void release_file(File file); 19 | 20 | // Write data to file at path 21 | uint32_t write_file(const char* path, void *data, uint32_t size); 22 | } 23 | 24 | -------------------------------------------------------------------------------- /cpplib/font.cpp: -------------------------------------------------------------------------------- 1 | #include "font.h" 2 | #include "memory.h" 3 | 4 | #ifdef CPPLIB_DEBUG_PRINTS 5 | #include "logging.h" 6 | #define PRINT_DEBUG(message, ...) logging::print_error(message, ##__VA_ARGS__) 7 | #else 8 | #define PRINT_DEBUG(message, ...) 9 | #endif 10 | 11 | // Globally unique objects 12 | FT_Library ft_library; 13 | 14 | bool font::init() 15 | { 16 | int32_t error = FT_Init_FreeType(&ft_library); 17 | if (error) { 18 | PRINT_DEBUG("Error initializing FreeType library!"); 19 | return false; 20 | } 21 | return true; 22 | } 23 | 24 | Font font::get(uint8_t *data, int32_t data_size, int32_t size, int32_t texture_size) 25 | { 26 | Font font = {}; 27 | 28 | // Store temp allocator stack state 29 | memory::push_temp_state(); 30 | 31 | // Allocate memory for the texture 32 | uint8_t *font_buffer = memory::alloc_temp(texture_size * texture_size); 33 | FT_Face face; 34 | int32_t error = FT_New_Memory_Face(ft_library, data, data_size, 0, &face); 35 | if (error) { 36 | PRINT_DEBUG("Error creating font face!"); 37 | return Font{}; 38 | } 39 | 40 | int32_t supersampling = 1; 41 | error = FT_Set_Pixel_Sizes(face, 0, size); 42 | if (error) 43 | { 44 | PRINT_DEBUG("Error setting pixel size!"); 45 | return Font{}; 46 | } 47 | 48 | int32_t row_height = face->size->metrics.height / 64; 49 | int32_t ascender = face->size->metrics.ascender / 64; 50 | int32_t descender = face->size->metrics.descender / 64; 51 | int32_t x = 0, y = 0; 52 | 53 | font.row_height = (float)row_height; 54 | font.top_pad = (float)(row_height - (ascender - descender)); 55 | font.scale = 1.0f; 56 | font.face = face; 57 | 58 | for (unsigned char c = 32; c < 128; ++c) 59 | { 60 | // Load character c 61 | error = FT_Load_Char(face, c, FT_LOAD_RENDER | FT_LOAD_TARGET_LIGHT); 62 | if(error) 63 | { 64 | PRINT_DEBUG("Error loading character %c!", c); 65 | return Font{}; 66 | } 67 | 68 | // Get glyph specific metrics 69 | int x_offset = face->glyph->bitmap_left; 70 | int y_offset = ascender - face->glyph->bitmap_top; 71 | int advance = face->glyph->advance.x >> 6; 72 | 73 | // Get bitmap parameters 74 | int bitmap_width = face->glyph->bitmap.width, bitmap_height = face->glyph->bitmap.rows; 75 | int pitch = face->glyph->bitmap.pitch; 76 | 77 | // In case we don't fit in the row, let's move to next row 78 | if(x > texture_size - bitmap_width) 79 | { 80 | x = 0; 81 | y += row_height; 82 | } 83 | 84 | // Copy over bitmap 85 | for(int32_t r = 0; r < bitmap_height; ++r) 86 | { 87 | uint8_t *source = face->glyph->bitmap.buffer + pitch * r; 88 | uint8_t *dest = font_buffer + (y + r) * texture_size + x; 89 | memcpy(dest, source, bitmap_width); 90 | } 91 | 92 | // Store glyph settings 93 | font.glyphs[c - 32] = {x, y, bitmap_width, bitmap_height, x_offset, y_offset, advance}; 94 | 95 | // Move in the bitmap 96 | x += bitmap_width; 97 | } 98 | 99 | // Initialize D3D texture for the Font 100 | font.texture = graphics::get_texture2D(font_buffer, texture_size, texture_size, DXGI_FORMAT_R8_UNORM, 1); 101 | if(!graphics::is_ready(&font.texture)) 102 | { 103 | PRINT_DEBUG("Could not create texture for font."); 104 | return Font{}; 105 | } 106 | 107 | // Restore memory state of the temp allocator 108 | memory::pop_temp_state(); 109 | 110 | return font; 111 | } 112 | 113 | float font::get_kerning(Font *font, char c1, char c2) 114 | { 115 | FT_Vector kerning; 116 | int32_t left_glyph_index = FT_Get_Char_Index(font->face, c1); 117 | int32_t right_glyph_index = FT_Get_Char_Index(font->face, c2); 118 | FT_Get_Kerning(font->face, left_glyph_index, right_glyph_index, FT_KERNING_DEFAULT, &kerning); 119 | return (float)kerning.x; 120 | } 121 | 122 | float font::get_string_width(const char *string, Font *font) 123 | { 124 | float width = 0; 125 | int i = 0; 126 | while(string[i]) 127 | { 128 | // Get a glyph for the current character 129 | char c = string[i]; 130 | Glyph glyph = font->glyphs[c - 32]; 131 | 132 | // Increment width by character's advance. This should be more precise than taking it's bitmap's width. 133 | width += glyph.advance; 134 | 135 | // Take kerning into consideration 136 | if (string[i+1]) 137 | width += font::get_kerning(font, c, string[i+1]); 138 | 139 | // Next letter 140 | i++; 141 | } 142 | 143 | return width; 144 | } 145 | 146 | float font::get_row_height(Font *font) 147 | { 148 | return font->row_height; 149 | } 150 | 151 | void font::release(Font *font) 152 | { 153 | graphics::release(&font->texture); 154 | } 155 | -------------------------------------------------------------------------------- /cpplib/font.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "graphics.h" 3 | #include "ft2build.h" 4 | #include FT_FREETYPE_H 5 | 6 | // TODO: do floats 7 | // Glyph specifies information aobut a single letter at a single scale 8 | struct Glyph 9 | { 10 | int bitmap_x, bitmap_y; 11 | int bitmap_width, bitmap_height; 12 | int x_offset, y_offset; 13 | int advance; 14 | }; 15 | 16 | // Font contains data for rendering text at specific scale 17 | struct Font 18 | { 19 | Glyph glyphs[96]; 20 | float row_height; 21 | float top_pad; 22 | float scale; 23 | Texture2D texture; 24 | FT_Face face; 25 | }; 26 | 27 | // font namespace handles loading Fonts and extracting information from it 28 | namespace font 29 | { 30 | /* 31 | Return initialized Font object 32 | 33 | Args: 34 | - data: binary data from .ttf/.otf file 35 | - data_size: size of data block in bytes 36 | - size: height of the font in pixels 37 | - texture_size: size of a side of texture that stores font bitmap, in pixels 38 | */ 39 | Font get(uint8_t *data, int32_t data_size, int32_t size, int32_t texture_size); 40 | 41 | // Initialize font rasterization code (FreeType2) 42 | bool init(); 43 | 44 | // Return height of a single row for a Font 45 | float get_row_height(Font *font); 46 | 47 | // Return width of a string 48 | float get_string_width(const char *string, Font *font); 49 | 50 | // Get kerning between two letters of a Font 51 | float get_kerning(Font *font, char c1, char c2); 52 | 53 | // Release a Font object 54 | void release(Font *font); 55 | } -------------------------------------------------------------------------------- /cpplib/fonts/ShareTechMono-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/cpplib/fonts/ShareTechMono-Regular.ttf -------------------------------------------------------------------------------- /cpplib/fonts/UbuntuMono-R.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/cpplib/fonts/UbuntuMono-R.ttf -------------------------------------------------------------------------------- /cpplib/fonts/consola.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/cpplib/fonts/consola.ttf -------------------------------------------------------------------------------- /cpplib/fonts/renner-book.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/cpplib/fonts/renner-book.otf -------------------------------------------------------------------------------- /cpplib/freetype/include/freetype/config/ftmodule.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file registers the FreeType modules compiled into the library. 3 | * 4 | * If you use GNU make, this file IS NOT USED! Instead, it is created in 5 | * the objects directory (normally `/objs/') based on information 6 | * from `/modules.cfg'. 7 | * 8 | * Please read `docs/INSTALL.ANY' and `docs/CUSTOMIZE' how to compile 9 | * FreeType without GNU make. 10 | * 11 | */ 12 | 13 | FT_USE_MODULE( FT_Module_Class, autofit_module_class ) 14 | FT_USE_MODULE( FT_Driver_ClassRec, tt_driver_class ) 15 | FT_USE_MODULE( FT_Driver_ClassRec, t1_driver_class ) 16 | FT_USE_MODULE( FT_Driver_ClassRec, cff_driver_class ) 17 | FT_USE_MODULE( FT_Driver_ClassRec, t1cid_driver_class ) 18 | FT_USE_MODULE( FT_Driver_ClassRec, pfr_driver_class ) 19 | FT_USE_MODULE( FT_Driver_ClassRec, t42_driver_class ) 20 | FT_USE_MODULE( FT_Driver_ClassRec, winfnt_driver_class ) 21 | FT_USE_MODULE( FT_Driver_ClassRec, pcf_driver_class ) 22 | FT_USE_MODULE( FT_Module_Class, psaux_module_class ) 23 | FT_USE_MODULE( FT_Module_Class, psnames_module_class ) 24 | FT_USE_MODULE( FT_Module_Class, pshinter_module_class ) 25 | FT_USE_MODULE( FT_Renderer_Class, ft_raster1_renderer_class ) 26 | FT_USE_MODULE( FT_Module_Class, sfnt_module_class ) 27 | FT_USE_MODULE( FT_Renderer_Class, ft_smooth_renderer_class ) 28 | FT_USE_MODULE( FT_Renderer_Class, ft_smooth_lcd_renderer_class ) 29 | FT_USE_MODULE( FT_Renderer_Class, ft_smooth_lcdv_renderer_class ) 30 | FT_USE_MODULE( FT_Driver_ClassRec, bdf_driver_class ) 31 | 32 | /* EOF */ 33 | -------------------------------------------------------------------------------- /cpplib/freetype/include/freetype/ftbbox.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************/ 2 | /* */ 3 | /* ftbbox.h */ 4 | /* */ 5 | /* FreeType exact bbox computation (specification). */ 6 | /* */ 7 | /* Copyright 1996-2016 by */ 8 | /* David Turner, Robert Wilhelm, and Werner Lemberg. */ 9 | /* */ 10 | /* This file is part of the FreeType project, and may only be used, */ 11 | /* modified, and distributed under the terms of the FreeType project */ 12 | /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ 13 | /* this file you indicate that you have read the license and */ 14 | /* understand and accept it fully. */ 15 | /* */ 16 | /***************************************************************************/ 17 | 18 | 19 | /*************************************************************************/ 20 | /* */ 21 | /* This component has a _single_ role: to compute exact outline bounding */ 22 | /* boxes. */ 23 | /* */ 24 | /* It is separated from the rest of the engine for various technical */ 25 | /* reasons. It may well be integrated in `ftoutln' later. */ 26 | /* */ 27 | /*************************************************************************/ 28 | 29 | 30 | #ifndef FTBBOX_H_ 31 | #define FTBBOX_H_ 32 | 33 | 34 | #include 35 | #include FT_FREETYPE_H 36 | 37 | #ifdef FREETYPE_H 38 | #error "freetype.h of FreeType 1 has been loaded!" 39 | #error "Please fix the directory search order for header files" 40 | #error "so that freetype.h of FreeType 2 is found first." 41 | #endif 42 | 43 | 44 | FT_BEGIN_HEADER 45 | 46 | 47 | /*************************************************************************/ 48 | /* */ 49 | /*
*/ 50 | /* outline_processing */ 51 | /* */ 52 | /*************************************************************************/ 53 | 54 | 55 | /*************************************************************************/ 56 | /* */ 57 | /* */ 58 | /* FT_Outline_Get_BBox */ 59 | /* */ 60 | /* */ 61 | /* Compute the exact bounding box of an outline. This is slower */ 62 | /* than computing the control box. However, it uses an advanced */ 63 | /* algorithm that returns _very_ quickly when the two boxes */ 64 | /* coincide. Otherwise, the outline Bézier arcs are traversed to */ 65 | /* extract their extrema. */ 66 | /* */ 67 | /* */ 68 | /* outline :: A pointer to the source outline. */ 69 | /* */ 70 | /* */ 71 | /* abbox :: The outline's exact bounding box. */ 72 | /* */ 73 | /* */ 74 | /* FreeType error code. 0~means success. */ 75 | /* */ 76 | /* */ 77 | /* If the font is tricky and the glyph has been loaded with */ 78 | /* @FT_LOAD_NO_SCALE, the resulting BBox is meaningless. To get */ 79 | /* reasonable values for the BBox it is necessary to load the glyph */ 80 | /* at a large ppem value (so that the hinting instructions can */ 81 | /* properly shift and scale the subglyphs), then extracting the BBox, */ 82 | /* which can be eventually converted back to font units. */ 83 | /* */ 84 | FT_EXPORT( FT_Error ) 85 | FT_Outline_Get_BBox( FT_Outline* outline, 86 | FT_BBox *abbox ); 87 | 88 | /* */ 89 | 90 | 91 | FT_END_HEADER 92 | 93 | #endif /* FTBBOX_H_ */ 94 | 95 | 96 | /* END */ 97 | 98 | 99 | /* Local Variables: */ 100 | /* coding: utf-8 */ 101 | /* End: */ 102 | -------------------------------------------------------------------------------- /cpplib/freetype/include/freetype/ftbzip2.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************/ 2 | /* */ 3 | /* ftbzip2.h */ 4 | /* */ 5 | /* Bzip2-compressed stream support. */ 6 | /* */ 7 | /* Copyright 2010-2016 by */ 8 | /* Joel Klinghed. */ 9 | /* */ 10 | /* This file is part of the FreeType project, and may only be used, */ 11 | /* modified, and distributed under the terms of the FreeType project */ 12 | /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ 13 | /* this file you indicate that you have read the license and */ 14 | /* understand and accept it fully. */ 15 | /* */ 16 | /***************************************************************************/ 17 | 18 | 19 | #ifndef FTBZIP2_H_ 20 | #define FTBZIP2_H_ 21 | 22 | #include 23 | #include FT_FREETYPE_H 24 | 25 | #ifdef FREETYPE_H 26 | #error "freetype.h of FreeType 1 has been loaded!" 27 | #error "Please fix the directory search order for header files" 28 | #error "so that freetype.h of FreeType 2 is found first." 29 | #endif 30 | 31 | 32 | FT_BEGIN_HEADER 33 | 34 | /*************************************************************************/ 35 | /* */ 36 | /*
*/ 37 | /* bzip2 */ 38 | /* */ 39 | /* */ 40 | /* BZIP2 Streams */ 41 | /* */ 42 | /* <Abstract> */ 43 | /* Using bzip2-compressed font files. */ 44 | /* */ 45 | /* <Description> */ 46 | /* This section contains the declaration of Bzip2-specific functions. */ 47 | /* */ 48 | /*************************************************************************/ 49 | 50 | 51 | /************************************************************************ 52 | * 53 | * @function: 54 | * FT_Stream_OpenBzip2 55 | * 56 | * @description: 57 | * Open a new stream to parse bzip2-compressed font files. This is 58 | * mainly used to support the compressed `*.pcf.bz2' fonts that come 59 | * with XFree86. 60 | * 61 | * @input: 62 | * stream :: 63 | * The target embedding stream. 64 | * 65 | * source :: 66 | * The source stream. 67 | * 68 | * @return: 69 | * FreeType error code. 0~means success. 70 | * 71 | * @note: 72 | * The source stream must be opened _before_ calling this function. 73 | * 74 | * Calling the internal function `FT_Stream_Close' on the new stream will 75 | * *not* call `FT_Stream_Close' on the source stream. None of the stream 76 | * objects will be released to the heap. 77 | * 78 | * The stream implementation is very basic and resets the decompression 79 | * process each time seeking backwards is needed within the stream. 80 | * 81 | * In certain builds of the library, bzip2 compression recognition is 82 | * automatically handled when calling @FT_New_Face or @FT_Open_Face. 83 | * This means that if no font driver is capable of handling the raw 84 | * compressed file, the library will try to open a bzip2 compressed stream 85 | * from it and re-open the face with it. 86 | * 87 | * This function may return `FT_Err_Unimplemented_Feature' if your build 88 | * of FreeType was not compiled with bzip2 support. 89 | */ 90 | FT_EXPORT( FT_Error ) 91 | FT_Stream_OpenBzip2( FT_Stream stream, 92 | FT_Stream source ); 93 | 94 | /* */ 95 | 96 | 97 | FT_END_HEADER 98 | 99 | #endif /* FTBZIP2_H_ */ 100 | 101 | 102 | /* END */ 103 | -------------------------------------------------------------------------------- /cpplib/freetype/include/freetype/ftfntfmt.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************/ 2 | /* */ 3 | /* ftfntfmt.h */ 4 | /* */ 5 | /* Support functions for font formats. */ 6 | /* */ 7 | /* Copyright 2002-2016 by */ 8 | /* David Turner, Robert Wilhelm, and Werner Lemberg. */ 9 | /* */ 10 | /* This file is part of the FreeType project, and may only be used, */ 11 | /* modified, and distributed under the terms of the FreeType project */ 12 | /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ 13 | /* this file you indicate that you have read the license and */ 14 | /* understand and accept it fully. */ 15 | /* */ 16 | /***************************************************************************/ 17 | 18 | 19 | #ifndef FTFNTFMT_H_ 20 | #define FTFNTFMT_H_ 21 | 22 | #include <ft2build.h> 23 | #include FT_FREETYPE_H 24 | 25 | #ifdef FREETYPE_H 26 | #error "freetype.h of FreeType 1 has been loaded!" 27 | #error "Please fix the directory search order for header files" 28 | #error "so that freetype.h of FreeType 2 is found first." 29 | #endif 30 | 31 | 32 | FT_BEGIN_HEADER 33 | 34 | 35 | /*************************************************************************/ 36 | /* */ 37 | /* <Section> */ 38 | /* font_formats */ 39 | /* */ 40 | /* <Title> */ 41 | /* Font Formats */ 42 | /* */ 43 | /* <Abstract> */ 44 | /* Getting the font format. */ 45 | /* */ 46 | /* <Description> */ 47 | /* The single function in this section can be used to get the font */ 48 | /* format. Note that this information is not needed normally; */ 49 | /* however, there are special cases (like in PDF devices) where it is */ 50 | /* important to differentiate, in spite of FreeType's uniform API. */ 51 | /* */ 52 | /*************************************************************************/ 53 | 54 | 55 | /*************************************************************************/ 56 | /* */ 57 | /* <Function> */ 58 | /* FT_Get_Font_Format */ 59 | /* */ 60 | /* <Description> */ 61 | /* Return a string describing the format of a given face. Possible */ 62 | /* values are `TrueType', `Type~1', `BDF', `PCF', `Type~42', */ 63 | /* `CID~Type~1', `CFF', `PFR', and `Windows~FNT'. */ 64 | /* */ 65 | /* The return value is suitable to be used as an X11 FONT_PROPERTY. */ 66 | /* */ 67 | /* <Input> */ 68 | /* face :: */ 69 | /* Input face handle. */ 70 | /* */ 71 | /* <Return> */ 72 | /* Font format string. NULL in case of error. */ 73 | /* */ 74 | /* <Note> */ 75 | /* A deprecated name for the same function is */ 76 | /* `FT_Get_X11_Font_Format'. */ 77 | /* */ 78 | FT_EXPORT( const char* ) 79 | FT_Get_Font_Format( FT_Face face ); 80 | 81 | 82 | /* deprecated */ 83 | FT_EXPORT( const char* ) 84 | FT_Get_X11_Font_Format( FT_Face face ); 85 | 86 | 87 | /* */ 88 | 89 | 90 | FT_END_HEADER 91 | 92 | #endif /* FTFNTFMT_H_ */ 93 | 94 | 95 | /* END */ 96 | -------------------------------------------------------------------------------- /cpplib/freetype/include/freetype/ftgasp.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************/ 2 | /* */ 3 | /* ftgasp.h */ 4 | /* */ 5 | /* Access of TrueType's `gasp' table (specification). */ 6 | /* */ 7 | /* Copyright 2007-2016 by */ 8 | /* David Turner, Robert Wilhelm, and Werner Lemberg. */ 9 | /* */ 10 | /* This file is part of the FreeType project, and may only be used, */ 11 | /* modified, and distributed under the terms of the FreeType project */ 12 | /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ 13 | /* this file you indicate that you have read the license and */ 14 | /* understand and accept it fully. */ 15 | /* */ 16 | /***************************************************************************/ 17 | 18 | 19 | #ifndef FTGASP_H_ 20 | #define FTGASP_H_ 21 | 22 | #include <ft2build.h> 23 | #include FT_FREETYPE_H 24 | 25 | #ifdef FREETYPE_H 26 | #error "freetype.h of FreeType 1 has been loaded!" 27 | #error "Please fix the directory search order for header files" 28 | #error "so that freetype.h of FreeType 2 is found first." 29 | #endif 30 | 31 | 32 | /*************************************************************************** 33 | * 34 | * @section: 35 | * gasp_table 36 | * 37 | * @title: 38 | * Gasp Table 39 | * 40 | * @abstract: 41 | * Retrieving TrueType `gasp' table entries. 42 | * 43 | * @description: 44 | * The function @FT_Get_Gasp can be used to query a TrueType or OpenType 45 | * font for specific entries in its `gasp' table, if any. This is 46 | * mainly useful when implementing native TrueType hinting with the 47 | * bytecode interpreter to duplicate the Windows text rendering results. 48 | */ 49 | 50 | /************************************************************************* 51 | * 52 | * @enum: 53 | * FT_GASP_XXX 54 | * 55 | * @description: 56 | * A list of values and/or bit-flags returned by the @FT_Get_Gasp 57 | * function. 58 | * 59 | * @values: 60 | * FT_GASP_NO_TABLE :: 61 | * This special value means that there is no GASP table in this face. 62 | * It is up to the client to decide what to do. 63 | * 64 | * FT_GASP_DO_GRIDFIT :: 65 | * Grid-fitting and hinting should be performed at the specified ppem. 66 | * This *really* means TrueType bytecode interpretation. If this bit 67 | * is not set, no hinting gets applied. 68 | * 69 | * FT_GASP_DO_GRAY :: 70 | * Anti-aliased rendering should be performed at the specified ppem. 71 | * If not set, do monochrome rendering. 72 | * 73 | * FT_GASP_SYMMETRIC_SMOOTHING :: 74 | * If set, smoothing along multiple axes must be used with ClearType. 75 | * 76 | * FT_GASP_SYMMETRIC_GRIDFIT :: 77 | * Grid-fitting must be used with ClearType's symmetric smoothing. 78 | * 79 | * @note: 80 | * The bit-flags `FT_GASP_DO_GRIDFIT' and `FT_GASP_DO_GRAY' are to be 81 | * used for standard font rasterization only. Independently of that, 82 | * `FT_GASP_SYMMETRIC_SMOOTHING' and `FT_GASP_SYMMETRIC_GRIDFIT' are to 83 | * be used if ClearType is enabled (and `FT_GASP_DO_GRIDFIT' and 84 | * `FT_GASP_DO_GRAY' are consequently ignored). 85 | * 86 | * `ClearType' is Microsoft's implementation of LCD rendering, partly 87 | * protected by patents. 88 | * 89 | * @since: 90 | * 2.3.0 91 | */ 92 | #define FT_GASP_NO_TABLE -1 93 | #define FT_GASP_DO_GRIDFIT 0x01 94 | #define FT_GASP_DO_GRAY 0x02 95 | #define FT_GASP_SYMMETRIC_SMOOTHING 0x08 96 | #define FT_GASP_SYMMETRIC_GRIDFIT 0x10 97 | 98 | 99 | /************************************************************************* 100 | * 101 | * @func: 102 | * FT_Get_Gasp 103 | * 104 | * @description: 105 | * Read the `gasp' table from a TrueType or OpenType font file and 106 | * return the entry corresponding to a given character pixel size. 107 | * 108 | * @input: 109 | * face :: The source face handle. 110 | * ppem :: The vertical character pixel size. 111 | * 112 | * @return: 113 | * Bit flags (see @FT_GASP_XXX), or @FT_GASP_NO_TABLE if there is no 114 | * `gasp' table in the face. 115 | * 116 | * @since: 117 | * 2.3.0 118 | */ 119 | FT_EXPORT( FT_Int ) 120 | FT_Get_Gasp( FT_Face face, 121 | FT_UInt ppem ); 122 | 123 | /* */ 124 | 125 | 126 | #endif /* FTGASP_H_ */ 127 | 128 | 129 | /* END */ 130 | -------------------------------------------------------------------------------- /cpplib/freetype/include/freetype/ftlzw.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************/ 2 | /* */ 3 | /* ftlzw.h */ 4 | /* */ 5 | /* LZW-compressed stream support. */ 6 | /* */ 7 | /* Copyright 2004-2016 by */ 8 | /* David Turner, Robert Wilhelm, and Werner Lemberg. */ 9 | /* */ 10 | /* This file is part of the FreeType project, and may only be used, */ 11 | /* modified, and distributed under the terms of the FreeType project */ 12 | /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ 13 | /* this file you indicate that you have read the license and */ 14 | /* understand and accept it fully. */ 15 | /* */ 16 | /***************************************************************************/ 17 | 18 | 19 | #ifndef FTLZW_H_ 20 | #define FTLZW_H_ 21 | 22 | #include <ft2build.h> 23 | #include FT_FREETYPE_H 24 | 25 | #ifdef FREETYPE_H 26 | #error "freetype.h of FreeType 1 has been loaded!" 27 | #error "Please fix the directory search order for header files" 28 | #error "so that freetype.h of FreeType 2 is found first." 29 | #endif 30 | 31 | 32 | FT_BEGIN_HEADER 33 | 34 | /*************************************************************************/ 35 | /* */ 36 | /* <Section> */ 37 | /* lzw */ 38 | /* */ 39 | /* <Title> */ 40 | /* LZW Streams */ 41 | /* */ 42 | /* <Abstract> */ 43 | /* Using LZW-compressed font files. */ 44 | /* */ 45 | /* <Description> */ 46 | /* This section contains the declaration of LZW-specific functions. */ 47 | /* */ 48 | /*************************************************************************/ 49 | 50 | /************************************************************************ 51 | * 52 | * @function: 53 | * FT_Stream_OpenLZW 54 | * 55 | * @description: 56 | * Open a new stream to parse LZW-compressed font files. This is 57 | * mainly used to support the compressed `*.pcf.Z' fonts that come 58 | * with XFree86. 59 | * 60 | * @input: 61 | * stream :: The target embedding stream. 62 | * 63 | * source :: The source stream. 64 | * 65 | * @return: 66 | * FreeType error code. 0~means success. 67 | * 68 | * @note: 69 | * The source stream must be opened _before_ calling this function. 70 | * 71 | * Calling the internal function `FT_Stream_Close' on the new stream will 72 | * *not* call `FT_Stream_Close' on the source stream. None of the stream 73 | * objects will be released to the heap. 74 | * 75 | * The stream implementation is very basic and resets the decompression 76 | * process each time seeking backwards is needed within the stream 77 | * 78 | * In certain builds of the library, LZW compression recognition is 79 | * automatically handled when calling @FT_New_Face or @FT_Open_Face. 80 | * This means that if no font driver is capable of handling the raw 81 | * compressed file, the library will try to open a LZW stream from it 82 | * and re-open the face with it. 83 | * 84 | * This function may return `FT_Err_Unimplemented_Feature' if your build 85 | * of FreeType was not compiled with LZW support. 86 | */ 87 | FT_EXPORT( FT_Error ) 88 | FT_Stream_OpenLZW( FT_Stream stream, 89 | FT_Stream source ); 90 | 91 | /* */ 92 | 93 | 94 | FT_END_HEADER 95 | 96 | #endif /* FTLZW_H_ */ 97 | 98 | 99 | /* END */ 100 | -------------------------------------------------------------------------------- /cpplib/freetype/include/freetype/ftsynth.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************/ 2 | /* */ 3 | /* ftsynth.h */ 4 | /* */ 5 | /* FreeType synthesizing code for emboldening and slanting */ 6 | /* (specification). */ 7 | /* */ 8 | /* Copyright 2000-2016 by */ 9 | /* David Turner, Robert Wilhelm, and Werner Lemberg. */ 10 | /* */ 11 | /* This file is part of the FreeType project, and may only be used, */ 12 | /* modified, and distributed under the terms of the FreeType project */ 13 | /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ 14 | /* this file you indicate that you have read the license and */ 15 | /* understand and accept it fully. */ 16 | /* */ 17 | /***************************************************************************/ 18 | 19 | 20 | /*************************************************************************/ 21 | /*************************************************************************/ 22 | /*************************************************************************/ 23 | /*************************************************************************/ 24 | /*************************************************************************/ 25 | /********* *********/ 26 | /********* WARNING, THIS IS ALPHA CODE! THIS API *********/ 27 | /********* IS DUE TO CHANGE UNTIL STRICTLY NOTIFIED BY THE *********/ 28 | /********* FREETYPE DEVELOPMENT TEAM *********/ 29 | /********* *********/ 30 | /*************************************************************************/ 31 | /*************************************************************************/ 32 | /*************************************************************************/ 33 | /*************************************************************************/ 34 | /*************************************************************************/ 35 | 36 | 37 | /* Main reason for not lifting the functions in this module to a */ 38 | /* `standard' API is that the used parameters for emboldening and */ 39 | /* slanting are not configurable. Consider the functions as a */ 40 | /* code resource that should be copied into the application and */ 41 | /* adapted to the particular needs. */ 42 | 43 | 44 | #ifndef FTSYNTH_H_ 45 | #define FTSYNTH_H_ 46 | 47 | 48 | #include <ft2build.h> 49 | #include FT_FREETYPE_H 50 | 51 | #ifdef FREETYPE_H 52 | #error "freetype.h of FreeType 1 has been loaded!" 53 | #error "Please fix the directory search order for header files" 54 | #error "so that freetype.h of FreeType 2 is found first." 55 | #endif 56 | 57 | 58 | FT_BEGIN_HEADER 59 | 60 | /* Embolden a glyph by a `reasonable' value (which is highly a matter of */ 61 | /* taste). This function is actually a convenience function, providing */ 62 | /* a wrapper for @FT_Outline_Embolden and @FT_Bitmap_Embolden. */ 63 | /* */ 64 | /* For emboldened outlines the height, width, and advance metrics are */ 65 | /* increased by the strength of the emboldening -- this even affects */ 66 | /* mono-width fonts! */ 67 | /* */ 68 | /* You can also call @FT_Outline_Get_CBox to get precise values. */ 69 | FT_EXPORT( void ) 70 | FT_GlyphSlot_Embolden( FT_GlyphSlot slot ); 71 | 72 | /* Slant an outline glyph to the right by about 12 degrees. */ 73 | FT_EXPORT( void ) 74 | FT_GlyphSlot_Oblique( FT_GlyphSlot slot ); 75 | 76 | /* */ 77 | 78 | 79 | FT_END_HEADER 80 | 81 | #endif /* FTSYNTH_H_ */ 82 | 83 | 84 | /* END */ 85 | -------------------------------------------------------------------------------- /cpplib/freetype/include/freetype/ttunpat.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************/ 2 | /* */ 3 | /* ttunpat.h */ 4 | /* */ 5 | /* Definitions for the unpatented TrueType hinting system. */ 6 | /* Obsolete, retained for backwards compatibility. */ 7 | /* */ 8 | /* Copyright 2003-2016 by */ 9 | /* David Turner, Robert Wilhelm, and Werner Lemberg. */ 10 | /* */ 11 | /* Written by Graham Asher <graham.asher@btinternet.com> */ 12 | /* */ 13 | /* This file is part of the FreeType project, and may only be used, */ 14 | /* modified, and distributed under the terms of the FreeType project */ 15 | /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ 16 | /* this file you indicate that you have read the license and */ 17 | /* understand and accept it fully. */ 18 | /* */ 19 | /***************************************************************************/ 20 | 21 | 22 | #ifndef TTUNPAT_H_ 23 | #define TTUNPAT_H_ 24 | 25 | 26 | #include <ft2build.h> 27 | #include FT_FREETYPE_H 28 | 29 | #ifdef FREETYPE_H 30 | #error "freetype.h of FreeType 1 has been loaded!" 31 | #error "Please fix the directory search order for header files" 32 | #error "so that freetype.h of FreeType 2 is found first." 33 | #endif 34 | 35 | 36 | FT_BEGIN_HEADER 37 | 38 | 39 | /*************************************************************************** 40 | * 41 | * @constant: 42 | * FT_PARAM_TAG_UNPATENTED_HINTING 43 | * 44 | * @description: 45 | * Deprecated. 46 | * 47 | * Previously: A constant used as the tag of an @FT_Parameter structure to 48 | * indicate that unpatented methods only should be used by the TrueType 49 | * bytecode interpreter for a typeface opened by @FT_Open_Face. 50 | * 51 | */ 52 | #define FT_PARAM_TAG_UNPATENTED_HINTING FT_MAKE_TAG( 'u', 'n', 'p', 'a' ) 53 | 54 | /* */ 55 | 56 | 57 | FT_END_HEADER 58 | 59 | 60 | #endif /* TTUNPAT_H_ */ 61 | 62 | 63 | /* END */ 64 | -------------------------------------------------------------------------------- /cpplib/freetype/include/ft2build.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************/ 2 | /* */ 3 | /* ft2build.h */ 4 | /* */ 5 | /* FreeType 2 build and setup macros. */ 6 | /* */ 7 | /* Copyright 1996-2016 by */ 8 | /* David Turner, Robert Wilhelm, and Werner Lemberg. */ 9 | /* */ 10 | /* This file is part of the FreeType project, and may only be used, */ 11 | /* modified, and distributed under the terms of the FreeType project */ 12 | /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ 13 | /* this file you indicate that you have read the license and */ 14 | /* understand and accept it fully. */ 15 | /* */ 16 | /***************************************************************************/ 17 | 18 | 19 | /*************************************************************************/ 20 | /* */ 21 | /* This is the `entry point' for FreeType header file inclusions. It is */ 22 | /* the only header file which should be included directly; all other */ 23 | /* FreeType header files should be accessed with macro names (after */ 24 | /* including `ft2build.h'). */ 25 | /* */ 26 | /* A typical example is */ 27 | /* */ 28 | /* #include <ft2build.h> */ 29 | /* #include FT_FREETYPE_H */ 30 | /* */ 31 | /*************************************************************************/ 32 | 33 | 34 | #ifndef FT2BUILD_H_ 35 | #define FT2BUILD_H_ 36 | 37 | #include <freetype/config/ftheader.h> 38 | 39 | #endif /* FT2BUILD_H_ */ 40 | 41 | 42 | /* END */ 43 | -------------------------------------------------------------------------------- /cpplib/freetype/win32/freetype271.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/cpplib/freetype/win32/freetype271.dll -------------------------------------------------------------------------------- /cpplib/freetype/win32/freetype271.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/cpplib/freetype/win32/freetype271.lib -------------------------------------------------------------------------------- /cpplib/freetype/win32/freetype271MT.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/cpplib/freetype/win32/freetype271MT.dll -------------------------------------------------------------------------------- /cpplib/freetype/win32/freetype271MT.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/cpplib/freetype/win32/freetype271MT.lib -------------------------------------------------------------------------------- /cpplib/freetype/win64/freetype271.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/cpplib/freetype/win64/freetype271.dll -------------------------------------------------------------------------------- /cpplib/freetype/win64/freetype271.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/cpplib/freetype/win64/freetype271.lib -------------------------------------------------------------------------------- /cpplib/freetype/win64/freetype271MT.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/cpplib/freetype/win64/freetype271MT.dll -------------------------------------------------------------------------------- /cpplib/freetype/win64/freetype271MT.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/cpplib/freetype/win64/freetype271MT.lib -------------------------------------------------------------------------------- /cpplib/input.cpp: -------------------------------------------------------------------------------- 1 | #include "input.h" 2 | 3 | // Input state variables 4 | bool mouse_lbutton_pressed = false; 5 | bool mouse_lbutton_down = false; 6 | bool mouse_rbutton_pressed = false; 7 | bool mouse_rbutton_down = false; 8 | Vector2 mouse_position_ = Vector2(-1,-1); 9 | Vector2 mouse_delta_position_ = Vector2(0.0f,0.0f); 10 | 11 | float mouse_scroll_delta_ = 0.0f; 12 | 13 | static bool key_down_[100]; 14 | static bool key_pressed_[100]; 15 | 16 | bool ui_active_ = false; 17 | 18 | //////////////////////////// 19 | /// PUBLIC API 20 | //////////////////////////// 21 | 22 | void input::reset() 23 | { 24 | mouse_lbutton_pressed = false; 25 | mouse_delta_position_ = Vector2(0.0f, 0.0f); 26 | mouse_scroll_delta_ = 0.0f; 27 | memset(key_pressed_, 0, sizeof(bool) * 100); 28 | } 29 | 30 | bool input::mouse_left_button_pressed() 31 | { 32 | return mouse_lbutton_pressed; 33 | } 34 | 35 | bool input::mouse_left_button_down() 36 | { 37 | return mouse_lbutton_down; 38 | } 39 | 40 | bool input::mouse_right_button_pressed() 41 | { 42 | return mouse_rbutton_pressed; 43 | } 44 | 45 | bool input::mouse_right_button_down() 46 | { 47 | return mouse_rbutton_down; 48 | } 49 | 50 | Vector2 input::mouse_position() 51 | { 52 | return mouse_position_; 53 | } 54 | 55 | Vector2 input::mouse_delta_position() 56 | { 57 | return mouse_delta_position_; 58 | } 59 | 60 | void input::set_mouse_left_button_down() 61 | { 62 | if(!mouse_lbutton_down) mouse_lbutton_pressed = true; 63 | mouse_lbutton_down = true; 64 | } 65 | 66 | void input::set_mouse_left_button_up() 67 | { 68 | mouse_lbutton_down = false; 69 | } 70 | 71 | void input::set_mouse_right_button_down() 72 | { 73 | if(!mouse_rbutton_down) mouse_rbutton_pressed = true; 74 | mouse_rbutton_down = true; 75 | } 76 | 77 | void input::set_mouse_right_button_up() 78 | { 79 | mouse_rbutton_down = false; 80 | } 81 | 82 | void input::set_mouse_position(Vector2 position) 83 | { 84 | // Don't update delta on the first frame (initial position (-1, -1)) 85 | if(mouse_position_.x > 0.0f && mouse_position_.y > 0.0f) 86 | { 87 | mouse_delta_position_ = position - mouse_position_; 88 | } 89 | mouse_position_ = position; 90 | } 91 | 92 | void input::set_mouse_scroll_delta(float delta) 93 | { 94 | mouse_scroll_delta_ = delta; 95 | } 96 | 97 | float input::mouse_scroll_delta() 98 | { 99 | return mouse_scroll_delta_; 100 | } 101 | 102 | void input::set_key_down(KeyCode code) 103 | { 104 | if(!key_down_[code]) key_pressed_[code] = true; 105 | key_down_[code] = true; 106 | } 107 | 108 | void input::set_key_up(KeyCode code) 109 | { 110 | key_down_[code] = false; 111 | } 112 | 113 | bool input::key_pressed(KeyCode code) 114 | { 115 | return key_pressed_[code]; 116 | } 117 | 118 | void input::register_event(Event *event) 119 | { 120 | switch(event->type) 121 | { 122 | case MOUSE_MOVE: 123 | { 124 | MouseMoveData *data = (MouseMoveData *)event->data; 125 | input::set_mouse_position(Vector2(data->x, data->y)); 126 | } 127 | break; 128 | case MOUSE_LBUTTON_DOWN: 129 | { 130 | input::set_mouse_left_button_down(); 131 | } 132 | break; 133 | case MOUSE_LBUTTON_UP: 134 | { 135 | input::set_mouse_left_button_up(); 136 | } 137 | break; 138 | case MOUSE_RBUTTON_DOWN: 139 | { 140 | input::set_mouse_right_button_down(); 141 | } 142 | break; 143 | case MOUSE_RBUTTON_UP: 144 | { 145 | input::set_mouse_right_button_up(); 146 | } 147 | break; 148 | case MOUSE_WHEEL: 149 | { 150 | MouseWheelData *data = (MouseWheelData *)event->data; 151 | input::set_mouse_scroll_delta(data->delta); 152 | } 153 | break; 154 | case KEY_DOWN: 155 | { 156 | KeyPressedData *key_data = (KeyPressedData *)event->data; 157 | input::set_key_down(key_data->code); 158 | } 159 | break; 160 | case KEY_UP: 161 | { 162 | KeyPressedData *key_data = (KeyPressedData *)event->data; 163 | input::set_key_up(key_data->code); 164 | } 165 | break; 166 | } 167 | 168 | } -------------------------------------------------------------------------------- /cpplib/input.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "maths.h" 3 | #include "platform.h" 4 | 5 | // Input namespace handles input state 6 | // 7 | // Usage: 8 | // Call `register_event` on all the events from `platform::get_event` each frame 9 | namespace input 10 | { 11 | // Reset input states that are dependent on state change 12 | // e.g. - pressed event, mouse delta position.... 13 | void reset(); 14 | 15 | // Return if left mouse button has been pressed this frame (now down, previous frame up) 16 | bool mouse_left_button_pressed(); 17 | 18 | // Return if left mouse button is down 19 | bool mouse_left_button_down(); 20 | 21 | // Return if right mouse button has been pressed this frame (now down, previous frame up) 22 | bool mouse_right_button_pressed(); 23 | 24 | // Return if right mouse button is down 25 | bool mouse_right_button_down(); 26 | 27 | // Get last mouse position registered 28 | Vector2 mouse_position(); 29 | 30 | // Get difference between last registered position and the one before 31 | // NOTE: this is zeroed after calling reset() 32 | Vector2 mouse_delta_position(); 33 | 34 | // Get current movement of mouse scroll wheel 35 | // NOTE: this is zeroed after calling reset() 36 | float mouse_scroll_delta(); 37 | 38 | // Registered left mouse button as being down 39 | void set_mouse_left_button_down(); 40 | 41 | // Registered left mouse button as being u 42 | void set_mouse_left_button_up(); 43 | 44 | // Registered right mouse button as being down 45 | void set_mouse_right_button_down(); 46 | 47 | // Registered right mouse button as being u 48 | void set_mouse_right_button_up(); 49 | 50 | // Registered mouse position 51 | void set_mouse_position(Vector2 position); 52 | 53 | // Register mouse wheel scroll delta 54 | void set_mouse_scroll_delta(float delta); 55 | 56 | // Registered key with specific KeyCode as being down 57 | void set_key_down(KeyCode code); 58 | 59 | // Registered key with specific KeyCode as being up 60 | void set_key_up(KeyCode code); 61 | 62 | // Return if key with specific KeyCode was pressed this frame 63 | bool key_pressed(KeyCode code); 64 | 65 | // Process Event, disregards events irrelevant to input 66 | void register_event(Event *event); 67 | } -------------------------------------------------------------------------------- /cpplib/logging.cpp: -------------------------------------------------------------------------------- 1 | #include "logging.h" 2 | #include <cstdarg> 3 | #include <stdio.h> 4 | #include <string> 5 | 6 | void logging::print(char *fmt, ...) 7 | { 8 | va_list args; 9 | va_start(args, fmt); 10 | int32_t chars_written = vprintf(fmt, args); 11 | va_end(args); 12 | printf("\n"); 13 | } 14 | 15 | void logging::print_error_with_location(char *format, char *filename, uint32_t line, ...) 16 | { 17 | printf("ERROR in file %s on line %d: ", filename, line); 18 | 19 | va_list args; 20 | va_start(args, line); 21 | logging::print(format, args); 22 | va_end(args); 23 | } 24 | -------------------------------------------------------------------------------- /cpplib/logging.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include <stdint.h> 3 | 4 | #define __FILENAME__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__) 5 | 6 | #define print_error(format, ...) print_error_with_location(format, __FILENAME__, __LINE__, __VA_ARGS__) 7 | 8 | namespace logging 9 | { 10 | // General purpose print 11 | void print(char *format, ...); 12 | 13 | // Prints error message along with filename and line number. 14 | // Example: 15 | // "ERROR in file %FILENAME on line %LINE_NUMBER: " 16 | // %ERROR_MESSAGE 17 | void print_error_with_location(char *format, char *filename, uint32_t line, ...); 18 | } -------------------------------------------------------------------------------- /cpplib/memory.cpp: -------------------------------------------------------------------------------- 1 | #include "memory.h" 2 | #include "stack.h" 3 | 4 | static StackAllocator allocator_temp = memory::get_stack_allocator(MEGABYTES(10)); 5 | static Stack<StackAllocatorState> temp_state_stack = stack::get<StackAllocatorState>(10); 6 | 7 | StackAllocator memory::get_stack_allocator(uint32_t size) 8 | { 9 | StackAllocator allocator = {}; 10 | allocator.storage = malloc(size); 11 | assert(allocator.storage); 12 | allocator.size = size; 13 | return allocator; 14 | } 15 | 16 | StackAllocatorState memory::save_stack_state(StackAllocator *allocator) 17 | { 18 | return allocator->top; 19 | } 20 | 21 | void memory::load_stack_state(StackAllocator *allocator, StackAllocatorState state) 22 | { 23 | allocator->top = state; 24 | } 25 | 26 | StackAllocator *memory::get_temp_stack() 27 | { 28 | return &allocator_temp; 29 | } 30 | 31 | void memory::push_temp_state() 32 | { 33 | StackAllocatorState temp_state = memory::save_stack_state(get_temp_stack()); 34 | stack::push(&temp_state_stack, temp_state); 35 | } 36 | 37 | void memory::pop_temp_state() 38 | { 39 | StackAllocatorState temp_state = stack::pop(&temp_state_stack); 40 | memory::load_stack_state(memory::get_temp_stack(), temp_state); 41 | } 42 | 43 | void memory::free_temp() 44 | { 45 | memory::get_temp_stack()->top = 0; 46 | } 47 | 48 | void memory::free_heap(void *ptr) 49 | { 50 | free(ptr); 51 | } 52 | -------------------------------------------------------------------------------- /cpplib/memory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include <stdint.h> 3 | #include <cstdlib> 4 | 5 | #define KILOBYTES(kB) (kB * 1024) 6 | #define MEGABYTES(mB) (mB * 1024 * 1024) 7 | 8 | struct StackAllocator 9 | { 10 | void *storage; 11 | uint32_t size; 12 | uint32_t top = 0; 13 | }; 14 | 15 | typedef uint32_t StackAllocatorState; 16 | 17 | extern StackAllocator allocator_temp; 18 | 19 | namespace memory 20 | { 21 | template <typename T> 22 | T *alloc_heap(uint32_t count) 23 | { 24 | T *mem = (T *)malloc(count * sizeof(T)); 25 | return mem; 26 | } 27 | 28 | void free_heap(void *ptr); 29 | 30 | StackAllocator get_stack_allocator(uint32_t size); 31 | StackAllocatorState save_stack_state(StackAllocator *allocator); 32 | void load_stack_state(StackAllocator *allocator, StackAllocatorState state); 33 | 34 | template <typename T> 35 | T *alloc_stack(StackAllocator *allocator, uint32_t count) 36 | { 37 | T *result = (T *)((char *)allocator->storage + allocator->top); 38 | if(allocator->top + count > allocator->size) return NULL; 39 | allocator->top += count * sizeof(T); 40 | return result; 41 | } 42 | 43 | StackAllocator *get_temp_stack(); 44 | 45 | void push_temp_state(); 46 | void pop_temp_state(); 47 | 48 | template <typename T> 49 | T *alloc_temp(uint32_t count) 50 | { 51 | return memory::alloc_stack<T>(memory::get_temp_stack(), count); 52 | } 53 | 54 | void free_temp(); 55 | } -------------------------------------------------------------------------------- /cpplib/oculus/Extras/OVR_StereoProjection.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************ 2 | 3 | Filename : OVR_StereoProjection.h 4 | Content : Stereo projection functions 5 | Created : November 30, 2013 6 | Authors : Tom Fosyth 7 | 8 | Copyright : Copyright 2014-2016 Oculus VR, LLC All Rights reserved. 9 | 10 | Licensed under the Oculus VR Rift SDK License Version 3.3 (the "License"); 11 | you may not use the Oculus VR Rift SDK except in compliance with the License, 12 | which is provided at the time of installation or download, or which 13 | otherwise accompanies this software in either electronic or hard copy form. 14 | 15 | You may obtain a copy of the License at 16 | 17 | http://www.oculusvr.com/licenses/LICENSE-3.3 18 | 19 | Unless required by applicable law or agreed to in writing, the Oculus VR SDK 20 | distributed under the License is distributed on an "AS IS" BASIS, 21 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 | See the License for the specific language governing permissions and 23 | limitations under the License. 24 | 25 | *************************************************************************************/ 26 | 27 | #ifndef OVR_StereoProjection_h 28 | #define OVR_StereoProjection_h 29 | 30 | #include "Extras/OVR_Math.h" 31 | 32 | namespace OVR { 33 | 34 | //----------------------------------------------------------------------------------- 35 | // ***** Stereo Enumerations 36 | 37 | // StereoEye specifies which eye we are rendering for; it is used to 38 | // retrieve StereoEyeParams. 39 | enum StereoEye { StereoEye_Left, StereoEye_Right, StereoEye_Center }; 40 | 41 | //----------------------------------------------------------------------------------- 42 | // ***** Propjection functions 43 | 44 | Matrix4f CreateProjection( 45 | bool rightHanded, 46 | bool isOpenGL, 47 | FovPort fov, 48 | StereoEye eye, 49 | float zNear = 0.01f, 50 | float zFar = 10000.0f, 51 | bool flipZ = false, 52 | bool farAtInfinity = false); 53 | 54 | Matrix4f CreateOrthoSubProjection( 55 | bool rightHanded, 56 | StereoEye eyeType, 57 | float tanHalfFovX, 58 | float tanHalfFovY, 59 | float unitsX, 60 | float unitsY, 61 | float distanceFromCamera, 62 | float interpupillaryDistance, 63 | Matrix4f const& projection, 64 | float zNear = 0.0f, 65 | float zFar = 0.0f, 66 | bool flipZ = false, 67 | bool farAtInfinity = false); 68 | 69 | ScaleAndOffset2D CreateNDCScaleAndOffsetFromFov(FovPort fov); 70 | 71 | } // namespace OVR 72 | 73 | #endif // OVR_StereoProjection_h 74 | -------------------------------------------------------------------------------- /cpplib/oculus/LibOVR_d.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/cpplib/oculus/LibOVR_d.lib -------------------------------------------------------------------------------- /cpplib/oculus/LibOVR_r.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/cpplib/oculus/LibOVR_r.lib -------------------------------------------------------------------------------- /cpplib/oculus/OVR_CAPI_Audio.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************/ /** 2 | \file OVR_CAPI_Audio.h 3 | \brief CAPI audio functions. 4 | \copyright Copyright 2015 Oculus VR, LLC. All Rights reserved. 5 | ************************************************************************************/ 6 | 7 | #ifndef OVR_CAPI_Audio_h 8 | #define OVR_CAPI_Audio_h 9 | 10 | #ifdef _WIN32 11 | // Prevents <Windows.h> from defining min() and max() macro symbols. 12 | #ifndef NOMINMAX 13 | #define NOMINMAX 14 | #endif 15 | #include <windows.h> 16 | #include "OVR_CAPI.h" 17 | #define OVR_AUDIO_MAX_DEVICE_STR_SIZE 128 18 | 19 | #if !defined(OVR_EXPORTING_CAPI) 20 | 21 | /// Gets the ID of the preferred VR audio output device. 22 | /// 23 | /// \param[out] deviceOutId The ID of the user's preferred VR audio device to use, 24 | /// which will be valid upon a successful return value, else it will be WAVE_MAPPER. 25 | /// 26 | /// \return Returns an ovrResult indicating success or failure. In the case of failure, use 27 | /// ovr_GetLastErrorInfo to get more information. 28 | /// 29 | OVR_PUBLIC_FUNCTION(ovrResult) ovr_GetAudioDeviceOutWaveId(UINT* deviceOutId); 30 | 31 | /// Gets the ID of the preferred VR audio input device. 32 | /// 33 | /// \param[out] deviceInId The ID of the user's preferred VR audio device to use, 34 | /// which will be valid upon a successful return value, else it will be WAVE_MAPPER. 35 | /// 36 | /// \return Returns an ovrResult indicating success or failure. In the case of failure, use 37 | /// ovr_GetLastErrorInfo to get more information. 38 | /// 39 | OVR_PUBLIC_FUNCTION(ovrResult) ovr_GetAudioDeviceInWaveId(UINT* deviceInId); 40 | 41 | /// Gets the GUID of the preferred VR audio device as a string. 42 | /// 43 | /// \param[out] deviceOutStrBuffer A buffer where the GUID string for the device will copied to. 44 | /// 45 | /// \return Returns an ovrResult indicating success or failure. In the case of failure, use 46 | /// ovr_GetLastErrorInfo to get more information. 47 | /// 48 | OVR_PUBLIC_FUNCTION(ovrResult) 49 | ovr_GetAudioDeviceOutGuidStr(WCHAR deviceOutStrBuffer[OVR_AUDIO_MAX_DEVICE_STR_SIZE]); 50 | 51 | /// Gets the GUID of the preferred VR audio device. 52 | /// 53 | /// \param[out] deviceOutGuid The GUID of the user's preferred VR audio device to use, 54 | /// which will be valid upon a successful return value, else it will be NULL. 55 | /// 56 | /// \return Returns an ovrResult indicating success or failure. In the case of failure, use 57 | /// ovr_GetLastErrorInfo to get more information. 58 | /// 59 | OVR_PUBLIC_FUNCTION(ovrResult) ovr_GetAudioDeviceOutGuid(GUID* deviceOutGuid); 60 | 61 | /// Gets the GUID of the preferred VR microphone device as a string. 62 | /// 63 | /// \param[out] deviceInStrBuffer A buffer where the GUID string for the device will copied to. 64 | /// 65 | /// \return Returns an ovrResult indicating success or failure. In the case of failure, use 66 | /// ovr_GetLastErrorInfo to get more information. 67 | /// 68 | OVR_PUBLIC_FUNCTION(ovrResult) 69 | ovr_GetAudioDeviceInGuidStr(WCHAR deviceInStrBuffer[OVR_AUDIO_MAX_DEVICE_STR_SIZE]); 70 | 71 | /// Gets the GUID of the preferred VR microphone device. 72 | /// 73 | /// \param[out] deviceInGuid The GUID of the user's preferred VR audio device to use, 74 | /// which will be valid upon a successful return value, else it will be NULL. 75 | /// 76 | /// \return Returns an ovrResult indicating success or failure. In the case of failure, use 77 | /// ovr_GetLastErrorInfo to get more information. 78 | /// 79 | OVR_PUBLIC_FUNCTION(ovrResult) ovr_GetAudioDeviceInGuid(GUID* deviceInGuid); 80 | 81 | #endif // !defined(OVR_EXPORTING_CAPI) 82 | 83 | #endif // OVR_OS_MS 84 | 85 | #endif // OVR_CAPI_Audio_h 86 | -------------------------------------------------------------------------------- /cpplib/oculus/OVR_CAPI_Keys.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************/ /** 2 | \file OVR_CAPI.h 3 | \brief Keys for CAPI proprty function calls 4 | \copyright Copyright 2015 Oculus VR, LLC All Rights reserved. 5 | ************************************************************************************/ 6 | 7 | #ifndef OVR_CAPI_Keys_h 8 | #define OVR_CAPI_Keys_h 9 | 10 | #include "OVR_Version.h" 11 | 12 | 13 | 14 | #define OVR_KEY_USER "User" // string 15 | 16 | #define OVR_KEY_NAME "Name" // string 17 | 18 | #define OVR_KEY_GENDER "Gender" // string "Male", "Female", or "Unknown" 19 | #define OVR_DEFAULT_GENDER "Unknown" 20 | 21 | #define OVR_KEY_PLAYER_HEIGHT "PlayerHeight" // float meters 22 | #define OVR_DEFAULT_PLAYER_HEIGHT 1.778f 23 | 24 | #define OVR_KEY_EYE_HEIGHT "EyeHeight" // float meters 25 | #define OVR_DEFAULT_EYE_HEIGHT 1.675f 26 | 27 | #define OVR_KEY_NECK_TO_EYE_DISTANCE "NeckEyeDistance" // float[2] meters 28 | #define OVR_DEFAULT_NECK_TO_EYE_HORIZONTAL 0.0805f 29 | #define OVR_DEFAULT_NECK_TO_EYE_VERTICAL 0.075f 30 | 31 | #define OVR_KEY_EYE_TO_NOSE_DISTANCE "EyeToNoseDist" // float[2] meters 32 | 33 | 34 | 35 | #define OVR_PERF_HUD_MODE "PerfHudMode" // int, allowed values are defined in enum ovrPerfHudMode 36 | 37 | #define OVR_LAYER_HUD_MODE "LayerHudMode" // int, allowed values are defined in enum ovrLayerHudMode 38 | #define OVR_LAYER_HUD_CURRENT_LAYER "LayerHudCurrentLayer" // int, The layer to show 39 | #define OVR_LAYER_HUD_SHOW_ALL_LAYERS "LayerHudShowAll" // bool, Hide other layers when hud enabled 40 | 41 | #define OVR_DEBUG_HUD_STEREO_MODE "DebugHudStereoMode" // int, see enum ovrDebugHudStereoMode 42 | #define OVR_DEBUG_HUD_STEREO_GUIDE_INFO_ENABLE "DebugHudStereoGuideInfoEnable" // bool 43 | #define OVR_DEBUG_HUD_STEREO_GUIDE_SIZE "DebugHudStereoGuideSize2f" // float[2] 44 | #define OVR_DEBUG_HUD_STEREO_GUIDE_POSITION "DebugHudStereoGuidePosition3f" // float[3] 45 | #define OVR_DEBUG_HUD_STEREO_GUIDE_YAWPITCHROLL "DebugHudStereoGuideYawPitchRoll3f" // float[3] 46 | #define OVR_DEBUG_HUD_STEREO_GUIDE_COLOR "DebugHudStereoGuideColor4f" // float[4] 47 | 48 | #endif // OVR_CAPI_Keys_h 49 | -------------------------------------------------------------------------------- /cpplib/oculus/OVR_Version.h: -------------------------------------------------------------------------------- 1 | /************************************************************************************* 2 | \file OVR_Version.h 3 | \brief This header provides LibOVR version identification. 4 | \copyright Copyright 2014-2016 Oculus VR, LLC All Rights reserved. 5 | *************************************************************************************/ 6 | 7 | #ifndef OVR_Version_h 8 | #define OVR_Version_h 9 | 10 | 11 | /// Conventional string-ification macro. 12 | #if !defined(OVR_STRINGIZE) 13 | #define OVR_STRINGIZEIMPL(x) #x 14 | #define OVR_STRINGIZE(x) OVR_STRINGIZEIMPL(x) 15 | #endif 16 | 17 | // Master version numbers 18 | #define OVR_PRODUCT_VERSION 1 // Product version doesn't participate in semantic versioning. 19 | #define OVR_MAJOR_VERSION 1 // If you change these values then you need to also make sure to change 20 | // LibOVR/Projects/Windows/LibOVR.props in parallel. 21 | #define OVR_MINOR_VERSION 16 // 22 | #define OVR_PATCH_VERSION 0 23 | #define OVR_BUILD_NUMBER 0 24 | 25 | // This is the ((product * 100) + major) version of the service that the DLL is compatible with. 26 | // When we backport changes to old versions of the DLL we update the old DLLs 27 | // to move this version number up to the latest version. 28 | // The DLL is responsible for checking that the service is the version it supports 29 | // and returning an appropriate error message if it has not been made compatible. 30 | #define OVR_DLL_COMPATIBLE_VERSION 101 31 | 32 | #define OVR_FEATURE_VERSION 0 33 | 34 | /// "Major.Minor.Patch" 35 | #if !defined(OVR_VERSION_STRING) 36 | #define OVR_VERSION_STRING OVR_STRINGIZE(OVR_MAJOR_VERSION.OVR_MINOR_VERSION.OVR_PATCH_VERSION) 37 | #endif 38 | 39 | /// "Major.Minor.Patch.Build" 40 | #if !defined(OVR_DETAILED_VERSION_STRING) 41 | #define OVR_DETAILED_VERSION_STRING \ 42 | OVR_STRINGIZE(OVR_MAJOR_VERSION.OVR_MINOR_VERSION.OVR_PATCH_VERSION.OVR_BUILD_NUMBER) 43 | #endif 44 | 45 | /// \brief file description for version info 46 | /// This appears in the user-visible file properties. It is intended to convey publicly 47 | /// available additional information such as feature builds. 48 | #if !defined(OVR_FILE_DESCRIPTION_STRING) 49 | #if defined(_DEBUG) 50 | #define OVR_FILE_DESCRIPTION_STRING "dev build debug" 51 | #else 52 | #define OVR_FILE_DESCRIPTION_STRING "dev build" 53 | #endif 54 | #endif 55 | 56 | #endif // OVR_Version_h 57 | -------------------------------------------------------------------------------- /cpplib/ovr.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "oculus/OVR_CAPI.h" 3 | #include "oculus/OVR_CAPI_D3D.h" 4 | #include "graphics.h" 5 | #include "maths.h" 6 | 7 | struct OVRContext 8 | { 9 | ovrSession session; 10 | LUID adapter_luid; 11 | 12 | ovrTextureSwapChain swap_chain; 13 | ID3D11RenderTargetView **rts; 14 | DepthBuffer depth_buffer; 15 | int32_t rts_count; 16 | 17 | ovrLayerEyeFov layer; 18 | ovrVector3f hmd_to_eye[2]; 19 | ovrPosef hand_positions[2]; 20 | }; 21 | #define OVR_VALID_CONTEXT(context) (context.session) 22 | 23 | typedef uint32_t Eye; 24 | typedef uint32_t Hand; 25 | #define EYE_LEFT 0 26 | #define EYE_RIGHT 1 27 | #define HAND_LEFT 0 28 | #define HAND_RIGHT 1 29 | 30 | namespace ovr 31 | { 32 | bool init(LUID **adapter_luid); 33 | bool init_swap_chain(); 34 | RenderTarget get_current_target_buffer(); 35 | DepthBuffer get_depth_buffer(); 36 | 37 | Viewport get_current_viewport(Eye eye); 38 | Vector3 get_current_eye_position(Eye eye); 39 | Quaternion get_current_eye_orientation(Eye eye); 40 | Vector3 get_current_hand_position(Hand hand); 41 | Quaternion get_current_hand_orientation(Hand hand); 42 | Matrix4x4 projection_matrix(Eye eye, float near, float far); 43 | 44 | void update_tracking(); 45 | void swap_frames(); 46 | 47 | float get_trigger_state(Hand hand); 48 | 49 | void release(); 50 | } 51 | 52 | -------------------------------------------------------------------------------- /cpplib/parsers.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "graphics.h" 3 | #include "file_system.h" 4 | #include "resources.h" 5 | 6 | struct StackAllocator; 7 | 8 | struct MeshData 9 | { 10 | float *vertices; 11 | uint16_t *indices; 12 | uint32_t index_count; 13 | uint32_t vertex_count; 14 | uint32_t vertex_stride; 15 | }; 16 | 17 | namespace parsers 18 | { 19 | MeshData get_mesh_from_obj(File obj_file, StackAllocator *stack_allocator); 20 | AssetDatabase get_assets_db_from_adf(File adfFile, StackAllocator *stack_allocator); 21 | } -------------------------------------------------------------------------------- /cpplib/platform.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include <Windows.h> 3 | #include <stdint.h> 4 | 5 | #define IS_WINDOW_VALID(window) (!(window.window_handle == INVALID_HANDLE_VALUE)) 6 | 7 | // Represents current window 8 | struct Window 9 | { 10 | HWND window_handle; 11 | uint32_t window_width; 12 | uint32_t window_height; 13 | }; 14 | 15 | ///////////////////////////////////////// 16 | // Event system specific structures 17 | ///////////////////////////////////////// 18 | /* 19 | Example of usage of the event system: 20 | 21 | // Each frame 22 | Event event; 23 | while(platform::get_event(&event)) // Get all the events accumulated since the last frame 24 | { 25 | // Check for event type 26 | switch(event.type) 27 | { 28 | case MOUSE_MOVE: 29 | // Since we now know that event is of MOUSE_MOVE type, we can just cast 30 | // Event's data member into MouseMoveData structure and read it that way. 31 | MouseMoveData *mouse_data = (MouseMoveData *)event.data; 32 | break; 33 | } 34 | } 35 | */ 36 | 37 | // All the event types 38 | enum EventType 39 | { 40 | EMPTY = 0, 41 | MOUSE_MOVE, 42 | MOUSE_LBUTTON_DOWN, 43 | MOUSE_LBUTTON_UP, 44 | MOUSE_RBUTTON_DOWN, 45 | MOUSE_RBUTTON_UP, 46 | KEY_DOWN, 47 | KEY_UP, 48 | MOUSE_WHEEL, 49 | EXIT 50 | }; 51 | 52 | // Event specific data structures 53 | 54 | struct MouseMoveData 55 | { 56 | float x; 57 | float y; 58 | }; 59 | 60 | enum KeyCode 61 | { 62 | ESC = 0, 63 | F1, 64 | F2, 65 | F3, 66 | F4, 67 | F5, 68 | F6, 69 | F7, 70 | F8, 71 | F9, 72 | F10, 73 | NUM1, 74 | NUM2, 75 | NUM3, 76 | NUM4, 77 | NUM5, 78 | NUM6, 79 | OTHER, 80 | }; 81 | 82 | struct KeyPressedData 83 | { 84 | KeyCode code; 85 | }; 86 | 87 | struct MouseWheelData 88 | { 89 | float delta; 90 | }; 91 | 92 | // Event data struct 93 | struct Event 94 | { 95 | EventType type; 96 | char data[32] = {}; 97 | }; 98 | 99 | // Ticks represent CPU ticks 100 | typedef LARGE_INTEGER Ticks; 101 | 102 | // `platform` namespace handles interfacing with windows API, with the exception of file system interface 103 | namespace platform 104 | { 105 | // Create and return windows with specific name and dimensions 106 | Window get_window(char *window_name, uint32_t window_width, uint32_t window_height); 107 | bool set_window_title(Window &window, const char *window_title); 108 | 109 | // Check if window is valid 110 | bool is_window_valid(Window *window); 111 | 112 | // Get next Event, should be called per frame until false is returned 113 | bool get_event(Event *event); 114 | 115 | // Cursor manipulation interface 116 | void show_cursor(); 117 | void hide_cursor(); 118 | 119 | // Get number of ticks since startup 120 | Ticks get_ticks(); 121 | 122 | // Get tick frequency 123 | Ticks get_tick_frequency(); 124 | 125 | // Compute time difference between two Ticks (number of ticks) and a tick update frequency 126 | float get_dt_from_tick_difference(Ticks t1, Ticks t2, Ticks frequency); 127 | } 128 | 129 | ///////////////////////////////////////// 130 | /// Timer API 131 | ///////////////////////////////////////// 132 | 133 | // Timer is used for simple timing purposes 134 | struct Timer 135 | { 136 | Ticks frequency; 137 | Ticks start; 138 | }; 139 | 140 | namespace timer 141 | { 142 | // Create a new timer 143 | Timer get(); 144 | 145 | // Start timing 146 | void start(Timer *timer); 147 | 148 | // Return time since the start 149 | float end(Timer *timer); 150 | 151 | // Return the time since the start and start measuring time from now 152 | float checkpoint(Timer *timer); 153 | } -------------------------------------------------------------------------------- /cpplib/random.cpp: -------------------------------------------------------------------------------- 1 | #include "random.h" 2 | #include <stdlib.h> 3 | 4 | float random::uniform(float low, float high) 5 | { 6 | double normalized = (rand() % 7919) / 7919.0; 7 | double result = normalized * ((double)high - (double)low) + (double)low; 8 | 9 | return (float)result; 10 | } 11 | 12 | Vector3 random::uniform_unit_hemisphere() 13 | { 14 | float y = random::uniform(0.0f, 1.0f); 15 | float r = math::sqrt(1.0f - y * y); 16 | float phi = random::uniform(0.0f, math::PI2); 17 | 18 | float radius = random::uniform(0.0f, 1.0f); 19 | radius = math::sqrt(radius); 20 | 21 | Vector3 result; 22 | 23 | result.x = r * math::cos(phi) * radius; 24 | result.y = y * radius; 25 | result.z = r * math::sin(phi) * radius; 26 | 27 | return result; 28 | } -------------------------------------------------------------------------------- /cpplib/random.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "maths.h" 3 | 4 | namespace random 5 | { 6 | float uniform(float low = 0.0f, float high = 1.0f); 7 | 8 | // Azimuth: 0 at +x axis in right handed system 9 | // pi / 2 at +z axis in right handed system 10 | // Polar: 0 at the top 11 | Vector3 uniform_unit_hemisphere(); 12 | } -------------------------------------------------------------------------------- /cpplib/resources.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include <stdint.h> 3 | 4 | struct Sound; 5 | 6 | struct VertexShader; 7 | struct PixelShader; 8 | struct GeometryShader; 9 | struct Mesh; 10 | 11 | typedef uint32_t sid; 12 | 13 | #define EXPAND(x) x 14 | #define HASH1(string) assert(false) 15 | #define HASH2(string, hash) hash 16 | 17 | #define SELECTOR(_1, _2, C, ...) C 18 | #define HASH(...) EXPAND(SELECTOR(__VA_ARGS__, HASH2, HASH1)(__VA_ARGS__)) 19 | 20 | struct AssetInfo 21 | { 22 | char *path; 23 | uint32_t type; 24 | }; 25 | 26 | const uint32_t ASSET_MAX_PATH_LENGTH= 50; 27 | const uint32_t ASSET_MAX_NAME_LENGTH = 50; 28 | const uint32_t ASSET_MAX_TYPE_LENGTH = 20; 29 | 30 | #define NONE 0 31 | #define MESH 1 32 | #define VERTEX_SHADER 2 33 | #define PIXEL_SHADER 3 34 | #define GEOMETRY_SHADER 4 35 | #define AUDIO_OGG 5 36 | #define FONT 6 37 | 38 | struct AssetDatabase 39 | { 40 | uint32_t asset_count; 41 | 42 | sid *keys; 43 | AssetInfo *asset_infos; 44 | }; 45 | 46 | namespace resources 47 | { 48 | void init(char *adf_file); 49 | void load_all(); 50 | void release_all(); 51 | 52 | Mesh *get_mesh(sid id); 53 | VertexShader *get_vertex_shader(sid id); 54 | PixelShader *get_pixel_shader(sid id); 55 | GeometryShader *get_geometry_shader(sid id); 56 | Sound *get_sound(sid id); 57 | uint8_t *get_font_data(sid id); 58 | } -------------------------------------------------------------------------------- /cpplib/stack.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include <stdint.h> 3 | #include <string.h> 4 | #include <cassert> 5 | #include "memory.h" 6 | 7 | template <typename T> 8 | struct Stack 9 | { 10 | T *data; 11 | uint32_t top; 12 | uint32_t size; 13 | }; 14 | 15 | // `stack` namespace handles operations on Stack. 16 | namespace stack 17 | { 18 | // Initialize stack and allocate initial memory necessary for stack of size `size` 19 | template <typename T> 20 | void init(Stack<T> *stack, uint32_t size) 21 | { 22 | stack->size = size; 23 | stack->top = 0; 24 | stack->data = memory::alloc_heap<T>(size); 25 | assert(stack->data); 26 | } 27 | 28 | // Return an initialized stack of size `size` 29 | template <typename T> 30 | Stack<T> get(uint32_t size) 31 | { 32 | Stack<T> stack; 33 | stack::init(&stack, size); 34 | return stack; 35 | } 36 | 37 | // Reset the stack 38 | // Does not free any memory 39 | template <typename T> 40 | void reset(Stack<T> * stack) 41 | { 42 | stack->top = 0; 43 | } 44 | 45 | // Push a new item from stack 46 | template <typename T> 47 | void push(Stack<T> *stack, T item) 48 | { 49 | // In case stack is full, reallocate 50 | if(stack->size == stack->top) 51 | { 52 | T *new_mem = memory::alloc_heap<T>(stack->size * 2); 53 | assert(new_mem); 54 | memcpy(new_mem, stack->data, sizeof(T) * stack->size); 55 | memory::free_heap(stack->data); 56 | stack->data = new_mem; 57 | stack->size *= 2; 58 | } 59 | 60 | stack->data[stack->top++] = item; 61 | } 62 | 63 | // Pop an item from stack 64 | template <typename T> 65 | T pop(Stack<T> *stack) 66 | { 67 | assert(stack->top > 0); // Cannot pop if no items in stack 68 | return stack->data[stack->top--]; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /cpplib/ui.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "maths.h" 3 | 4 | struct Font; 5 | 6 | struct Panel 7 | { 8 | char *name; 9 | Vector2 pos; 10 | float width; 11 | 12 | Vector2 item_pos; 13 | }; 14 | 15 | namespace ui 16 | { 17 | void init(float screen_width, float screen_height); 18 | 19 | void draw_text(const char *text, Font *font, float x, float y, Vector4 color, Vector2 origin = Vector2(0,0)); 20 | void draw_text(const char *text, Font *font, Vector2 pos, Vector4 color, Vector2 origin = Vector2(0,0)); 21 | void draw_text(const char *text, Vector2 pos, Vector4 color, Vector2 origin = Vector2(0,0)); 22 | 23 | void draw_rect(float x, float y, float width, float height, Vector4 color); 24 | void draw_rect(Vector2 pos, float width, float height, Vector4 color); 25 | 26 | Panel start_panel(char *name, Vector2 pos, float width); 27 | Panel start_panel(char *name, float x, float y, float width); 28 | void end_panel(Panel *panel); 29 | Vector4 get_panel_rect(Panel *panel); 30 | 31 | void end(); 32 | 33 | bool add_toggle(Panel *panel, char *label, bool *state); 34 | bool add_slider(Panel *panel, char *label, float *pos, float min, float max); 35 | 36 | void release(); 37 | 38 | // These functions enable turning UI on/off as a listener for inputs 39 | void set_input_responsive(bool is_responsive); 40 | bool is_input_responsive(); 41 | 42 | bool is_registering_input(); 43 | 44 | // Getters for values on which UI operates 45 | float get_screen_width(); 46 | Font *get_font(); 47 | } 48 | -------------------------------------------------------------------------------- /docs/energy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/docs/energy.png -------------------------------------------------------------------------------- /docs/mode_combined.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/docs/mode_combined.png -------------------------------------------------------------------------------- /docs/mode_particles.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/docs/mode_particles.png -------------------------------------------------------------------------------- /docs/mode_segmentation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/docs/mode_segmentation.png -------------------------------------------------------------------------------- /docs/mode_trace.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/docs/mode_trace.png -------------------------------------------------------------------------------- /docs/proxy_shells.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/docs/proxy_shells.png -------------------------------------------------------------------------------- /docs/proxy_sightline.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/docs/proxy_sightline.png -------------------------------------------------------------------------------- /docs/pt_aniso_red.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/docs/pt_aniso_red.png -------------------------------------------------------------------------------- /docs/pt_cool_blue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/docs/pt_cool_blue.png -------------------------------------------------------------------------------- /docs/pt_pointlight.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/docs/pt_pointlight.png -------------------------------------------------------------------------------- /docs/repo_card.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/docs/repo_card.png -------------------------------------------------------------------------------- /docs/title.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/docs/title.png -------------------------------------------------------------------------------- /docs/title_vis2020.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/docs/title_vis2020.png -------------------------------------------------------------------------------- /docs/title_vis2020_narrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/docs/title_vis2020_narrow.png -------------------------------------------------------------------------------- /docs/title_vis2020_play.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/docs/title_vis2020_play.png -------------------------------------------------------------------------------- /docs/trim_combined.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/docs/trim_combined.png -------------------------------------------------------------------------------- /docs/trim_particles.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/docs/trim_particles.png -------------------------------------------------------------------------------- /docs/trim_segmentation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/docs/trim_segmentation.png -------------------------------------------------------------------------------- /docs/trim_trace.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/docs/trim_trace.png -------------------------------------------------------------------------------- /docs/uc1_mapping.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/docs/uc1_mapping.png -------------------------------------------------------------------------------- /docs/uc2_regions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/docs/uc2_regions.png -------------------------------------------------------------------------------- /docs/uc3_absorption.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/docs/uc3_absorption.png -------------------------------------------------------------------------------- /docs/uc3_galaxies.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/docs/uc3_galaxies.png -------------------------------------------------------------------------------- /docs/vis_options.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/docs/vis_options.png -------------------------------------------------------------------------------- /docs/vis_options_small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CreativeCodingLab/Polyphorm/c9ea7fe69eb6d2a8bc068f1a8dc3470fcfd56082/docs/vis_options_small.png -------------------------------------------------------------------------------- /pack_data_celestial.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | file_name = 'galaxiesInSdssSlice_viz_bigger_lumdist' 4 | file_type = '.dat' 5 | separator = ',' 6 | mass_threshold = 0.0 7 | 8 | with open(file_name + file_type) as f: 9 | lines = f.readlines() 10 | data = np.zeros((len(lines)-1, 4), dtype=np.float32) 11 | nonzero_halos = 0 12 | for i, line in enumerate(lines[1:]): 13 | line = line.split(separator) 14 | 15 | azimuth = float(line[1]) / 180.0 * np.pi 16 | polar = (90.0 - float(line[2])) / 180.0 * np.pi 17 | radius = float(line[3]) 18 | 19 | x = radius * np.sin(polar) * np.cos(azimuth) 20 | y = radius * np.sin(polar) * np.sin(azimuth) 21 | z = radius * np.cos(polar) 22 | logmass = float(line[4]) 23 | 24 | if (logmass > mass_threshold): 25 | data[nonzero_halos, :] = [x, y, z, 10.0 ** logmass / 1.0e12] 26 | nonzero_halos += 1 27 | 28 | filtered_data = np.zeros((nonzero_halos, 4), dtype=np.float32) 29 | filtered_data = data[0:nonzero_halos, :] 30 | 31 | print('Min/Max X: ' + str(np.min(filtered_data[:,0])) + ' ' + str(np.max(filtered_data[:,0]))) 32 | print('Min/Max Y: ' + str(np.min(filtered_data[:,1])) + ' ' + str(np.max(filtered_data[:,1]))) 33 | print('Min/Max Z: ' + str(np.min(filtered_data[:,2])) + ' ' + str(np.max(filtered_data[:,2]))) 34 | print('Min/Max/Avg/Med Mass: ' + str(np.min(filtered_data[:,3])) + ' ' + str(np.max(filtered_data[:,3])) + ' ' + str(np.mean(filtered_data[:,3])) + ' ' + str(np.median(filtered_data[:,3]))) 35 | print('Example record: ' + str(filtered_data[0,:])) 36 | print('Number of records: ' + str(nonzero_halos)) 37 | 38 | output_file_name = file_name + '_t=' + str(mass_threshold) 39 | 40 | metadata_file = open(output_file_name + "_metadata.txt", "w") 41 | metadata_file.write("Number of points = " + str(nonzero_halos) + "\n") 42 | metadata_file.write("Min X = " + str(np.min(filtered_data[:,0])) + "\n") 43 | metadata_file.write("Max X = " + str(np.max(filtered_data[:,0])) + "\n") 44 | metadata_file.write("Min Y = " + str(np.min(filtered_data[:,1])) + "\n") 45 | metadata_file.write("Max Y = " + str(np.max(filtered_data[:,1])) + "\n") 46 | metadata_file.write("Min Z = " + str(np.min(filtered_data[:,2])) + "\n") 47 | metadata_file.write("Max Z = " + str(np.max(filtered_data[:,2])) + "\n") 48 | metadata_file.write("Mean weight = " + str(np.mean(filtered_data[:,3])) + "\n") 49 | metadata_file.close() 50 | 51 | filtered_data.tofile(output_file_name + '.bin') 52 | -------------------------------------------------------------------------------- /polyphorm.build: -------------------------------------------------------------------------------- 1 | include_dir(cpplib/) 2 | include_dir(cpplib/freetype/include/) 3 | include_dir(../DirectXTex/DirectXTex/) 4 | build_exe(polyphorm.exe, main.cpp cpplib/ui.cpp cpplib/maths.cpp cpplib/graphics.cpp cpplib/font.cpp cpplib/memory.cpp cpplib/input.cpp cpplib/logging.cpp cpplib/file_system.cpp cpplib/platform.cpp cpplib/random.cpp) 5 | libs(kernel32.lib user32.lib gdi32.lib D3D11.lib dxguid.lib d3dcompiler.lib DXGI.lib XAudio2.lib Ole32.lib cpplib/freetype/win64/freetype271MT.lib Winmm.lib ../DirectXTex/DirectXTex/Bin/Desktop_2017_Win10/x64/Release/DirectXTex.lib) 6 | copy(cpplib/fonts/*, $BIN) 7 | copy(shaders/*, $BIN) -------------------------------------------------------------------------------- /polyphorm.code-workspace: -------------------------------------------------------------------------------- 1 | { 2 | "folders": [ 3 | { 4 | "path": "." 5 | } 6 | ], 7 | "settings": { 8 | "files.associations": { 9 | "xstring": "cpp", 10 | "xutility": "cpp", 11 | "cmath": "cpp" 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /shaders/cs_agents_sort.hlsl: -------------------------------------------------------------------------------- 1 | 2 | RWStructuredBuffer<float> particles_x: register(u2); 3 | RWStructuredBuffer<float> particles_y: register(u3); 4 | RWStructuredBuffer<float> particles_z: register(u4); 5 | RWStructuredBuffer<float> particles_phi: register(u5); 6 | RWStructuredBuffer<float> particles_theta: register(u6); 7 | RWStructuredBuffer<float> particles_weights: register(u7); 8 | 9 | cbuffer ConfigBuffer : register(b0) 10 | { 11 | float sense_spread; 12 | float sense_distance; 13 | float turn_angle; 14 | float move_distance; 15 | float deposit_value; 16 | float decay_factor; 17 | float center_attraction; 18 | int world_width; 19 | int world_height; 20 | int world_depth; 21 | float move_sense_coef; 22 | float normalization_factor; 23 | int n_data_points; 24 | int n_agents; 25 | int n_iteration; 26 | }; 27 | 28 | struct RNG { 29 | #define BAD_W 0x464fffffU 30 | #define BAD_Z 0x9068ffffU 31 | uint m_w; 32 | uint m_z; 33 | 34 | void set_seed(uint seed1, uint seed2) { 35 | m_w = seed1; 36 | m_z = seed2; 37 | if (m_w == 0U || m_w == BAD_W) ++m_w; 38 | if (m_w == 0U || m_z == BAD_Z) ++m_z; 39 | } 40 | 41 | void get_seed(out uint seed1, out uint seed2) { 42 | seed1 = m_w; 43 | seed2 = m_z; 44 | } 45 | 46 | uint random_uint() { 47 | m_z = 36969U * (m_z & 65535U) + (m_z >> 16U); 48 | m_w = 18000U * (m_w & 65535U) + (m_w >> 16U); 49 | return uint((m_z << 16U) + m_w); 50 | } 51 | 52 | float random_float() { 53 | return float(random_uint()) / float(0xFFFFFFFFU); 54 | } 55 | 56 | uint wang_hash(uint seed) { 57 | seed = (seed ^ 61) ^ (seed >> 16); 58 | seed *= 9; 59 | seed = seed ^ (seed >> 4); 60 | seed *= 0x27d4eb2d; 61 | seed = seed ^ (seed >> 15); 62 | return seed; 63 | } 64 | }; 65 | 66 | void swap_agents(uint idxA, uint idxB) { 67 | float tmp; 68 | tmp = particles_x[idxA]; particles_x[idxA] = particles_x[idxB]; particles_x[idxB] = tmp; 69 | tmp = particles_y[idxA]; particles_y[idxA] = particles_y[idxB]; particles_y[idxB] = tmp; 70 | tmp = particles_z[idxA]; particles_z[idxA] = particles_z[idxB]; particles_z[idxB] = tmp; 71 | tmp = particles_theta[idxA]; particles_theta[idxA] = particles_theta[idxB]; particles_theta[idxB] = tmp; 72 | tmp = particles_phi[idxA]; particles_phi[idxA] = particles_phi[idxB]; particles_phi[idxB] = tmp; 73 | tmp = particles_weights[idxA]; particles_weights[idxA] = particles_weights[idxB]; particles_weights[idxB] = tmp; 74 | } 75 | 76 | // Morton codes: https://fgiesen.wordpress.com/2009/12/13/decoding-morton-codes/ 77 | uint Part1By2(uint x_) { 78 | uint x = x_ & 0x000003ff; 79 | x = (x ^ (x << 16)) & 0xff0000ff; 80 | x = (x ^ (x << 8)) & 0x0300f00f; 81 | x = (x ^ (x << 4)) & 0x030c30c3; 82 | x = (x ^ (x << 2)) & 0x09249249; 83 | return x; 84 | } 85 | 86 | uint EncodeMorton3(uint x, uint y, uint z) { 87 | return (Part1By2(z) << 2) + (Part1By2(y) << 1) + Part1By2(x); 88 | } 89 | 90 | [numthreads(10,10,10)] 91 | void main(uint thread_index : SV_GroupIndex, uint3 group_id : SV_GroupID) { 92 | uint group_idx = group_id.x + group_id.y * 10 + group_id.z * 100; 93 | uint idx = thread_index + 1000 * group_idx; 94 | 95 | // uint idxA = 32 * idx + (n_iteration % 32); 96 | // if (idxA >= n_agents-1) 97 | // return; 98 | // uint idxB = idxA + 1; 99 | // idxA = idxA + (n_data_points-1); 100 | // idxB = idxB + (n_data_points-1); 101 | 102 | // float vA = particles_y[idxA]; 103 | // float vB = particles_y[idxB]; 104 | // if (vA > vB) { 105 | // swap_agents(idxA, idxB); 106 | // } 107 | 108 | RNG rng; 109 | rng.set_seed( 110 | rng.wang_hash(73*idx), 111 | rng.wang_hash(13*n_iteration) 112 | ); 113 | uint idxA = n_data_points + rng.random_uint() % n_agents; 114 | uint idxB = n_data_points + rng.random_uint() % n_agents; 115 | float3 posA = float3(particles_x[idxA], particles_y[idxA], particles_z[idxA]); 116 | float3 posAN = float3( 117 | 0.5 * (particles_x[idxA-1] + particles_x[idxA+1]), 118 | 0.5 * (particles_y[idxA-1] + particles_y[idxA+1]), 119 | 0.5 * (particles_z[idxA-1] + particles_z[idxA+1])); 120 | float3 posB = float3(particles_x[idxB], particles_y[idxB], particles_z[idxB]); 121 | float3 posBN = float3( 122 | 0.5 * (particles_x[idxB-1] + particles_x[idxB+1]), 123 | 0.5 * (particles_y[idxB-1] + particles_y[idxB+1]), 124 | 0.5 * (particles_z[idxB-1] + particles_z[idxB+1])); 125 | float dA = length(posA - posAN); 126 | float dB = length(posB - posBN); 127 | float dApot = length(posA - posBN); 128 | float dBpot = length(posB - posAN); 129 | if ((dApot + dBpot) < (dA + dB)) { 130 | swap_agents(idxA, idxB); 131 | } 132 | 133 | // RNG rng; 134 | // rng.set_seed( 135 | // rng.wang_hash(73*idx), 136 | // rng.wang_hash(13*n_iteration) 137 | // ); 138 | // uint idxA = (n_data_points - 1) + rng.random_uint() % n_agents; 139 | // uint idxB = (n_data_points - 1) + rng.random_uint() % n_agents; 140 | // // uint vA = EncodeMorton3(uint(particles_x[idxA]), uint(particles_y[idxA]), uint(particles_z[idxA])); 141 | // // uint vB = EncodeMorton3(uint(particles_x[idxB]), uint(particles_y[idxB]), uint(particles_z[idxB])); 142 | // float vA = particles_y[idxA]; 143 | // float vB = particles_y[idxB]; 144 | // if (idxA < idxB && vA > vB) { 145 | // swap_agents(idxA, idxB); 146 | // } 147 | 148 | // uint idxA = (n_data_points - 1) + idx; 149 | // uint idxB = idxA + n_agents / 2; 150 | // float vA = particles_z[idxA]; 151 | // float vB = particles_z[idxB]; 152 | // if (vA > vB) { 153 | // swap_agents(idxA, idxB); 154 | // } 155 | } 156 | -------------------------------------------------------------------------------- /shaders/cs_density_histo.hlsl: -------------------------------------------------------------------------------- 1 | RWTexture3D<half> tex_density: register(u0); 2 | 3 | RWStructuredBuffer<uint> histogram: register(u1); 4 | RWStructuredBuffer<float> particles_x: register(u2); 5 | RWStructuredBuffer<float> particles_y: register(u3); 6 | RWStructuredBuffer<float> particles_z: register(u4); 7 | RWStructuredBuffer<float> particles_weights: register(u5); 8 | RWStructuredBuffer<float> halos_densities: register(u6); 9 | 10 | cbuffer ConfigBuffer : register(b0) 11 | { 12 | int n_data_points; 13 | int n_histo_bins; 14 | float histogram_base; 15 | int sample_randomly; 16 | float world_width; 17 | float world_height; 18 | float world_depth; 19 | } 20 | 21 | struct RNG { 22 | #define BAD_W 0x464fffffU 23 | #define BAD_Z 0x9068ffffU 24 | uint m_w; 25 | uint m_z; 26 | 27 | void set_seed(uint seed1, uint seed2) { 28 | m_w = seed1; 29 | m_z = seed2; 30 | if (m_w == 0U || m_w == BAD_W) ++m_w; 31 | if (m_w == 0U || m_z == BAD_Z) ++m_z; 32 | } 33 | 34 | void get_seed(out uint seed1, out uint seed2) { 35 | seed1 = m_w; 36 | seed2 = m_z; 37 | } 38 | 39 | uint random_uint() { 40 | m_z = 36969U * (m_z & 65535U) + (m_z >> 16U); 41 | m_w = 18000U * (m_w & 65535U) + (m_w >> 16U); 42 | return uint((m_z << 16U) + m_w); 43 | } 44 | 45 | float random_float() { 46 | return float(random_uint()) / float(0xFFFFFFFFU); 47 | } 48 | 49 | uint wang_hash(uint seed) { 50 | seed = (seed ^ 61) ^ (seed >> 16); 51 | seed *= 9; 52 | seed = seed ^ (seed >> 4); 53 | seed *= 0x27d4eb2d; 54 | seed = seed ^ (seed >> 15); 55 | return seed; 56 | } 57 | }; 58 | 59 | [numthreads(10,10,10)] 60 | void main(uint thread_index : SV_GroupIndex, uint3 group_id : SV_GroupID){ 61 | uint group_idx = group_id.x + group_id.y * 10 + group_id.z * 100; 62 | uint idx = thread_index + 1000 * group_idx; 63 | 64 | if (idx >= n_data_points) // Only consider halo/galaxy locations 65 | return; 66 | 67 | float x = particles_x[idx]; 68 | float y = particles_y[idx]; 69 | float z = particles_z[idx]; 70 | float mass = particles_weights[idx]; 71 | 72 | if (sample_randomly) { 73 | RNG rng; 74 | rng.set_seed( 75 | rng.wang_hash(73*idx), 76 | rng.wang_hash(uint(x*y*z)) 77 | ); 78 | x = rng.random_float() * world_width; 79 | y = rng.random_float() * world_height; 80 | z = rng.random_float() * world_depth; 81 | } 82 | 83 | float density = tex_density[uint3(x, y, z)]; 84 | halos_densities[idx] = density; 85 | // density /= mass; // normalize by mass - for fitting 86 | 87 | uint histo_index = 0; 88 | if (density > 1.0e-5) { 89 | float log_density = log(density) / log(histogram_base); 90 | histo_index = 1 + min(uint(log_density + 5.0), n_histo_bins - 3); 91 | } 92 | 93 | InterlockedAdd(histogram[histo_index], 1); 94 | InterlockedMax(histogram[n_histo_bins-1], uint(1.e5 * density)); 95 | // uint mx = max(histogram[n_histo_bins-1], uint(1.e5 * density)); 96 | // histogram[n_histo_bins-1] = mx; 97 | } 98 | 99 | -------------------------------------------------------------------------------- /shaders/cs_field_decay.hlsl: -------------------------------------------------------------------------------- 1 | RWTexture3D<half2> tex_in: register(u0); 2 | RWTexture3D<half2> tex_out: register(u1); 3 | RWTexture3D<half4> tex_trace: register(u2); 4 | 5 | cbuffer ConfigBuffer : register(b0) 6 | { 7 | float sense_spread; // unused 8 | float sense_distance; // unused 9 | float turn_angle; // unused 10 | float move_distance; // unused 11 | float deposit_value; // unused 12 | float decay_factor; 13 | float center_attraction; // unused 14 | int world_width; 15 | int world_height; 16 | int world_depth; 17 | }; 18 | 19 | struct RNG { 20 | #define BAD_W 0x464fffffU 21 | #define BAD_Z 0x9068ffffU 22 | uint m_w; 23 | uint m_z; 24 | 25 | void set_seed(uint seed1, uint seed2) { 26 | m_w = seed1; 27 | m_z = seed2; 28 | if (m_w == 0U || m_w == BAD_W) ++m_w; 29 | if (m_w == 0U || m_z == BAD_Z) ++m_z; 30 | } 31 | 32 | void get_seed(out uint seed1, out uint seed2) { 33 | seed1 = m_w; 34 | seed2 = m_z; 35 | } 36 | 37 | uint random_uint() { 38 | m_z = 36969U * (m_z & 65535U) + (m_z >> 16U); 39 | m_w = 18000U * (m_w & 65535U) + (m_w >> 16U); 40 | return uint((m_z << 16U) + m_w); 41 | } 42 | 43 | float random_float() { 44 | return float(random_uint()) / float(0xFFFFFFFFU); 45 | } 46 | 47 | uint wang_hash(uint seed) { 48 | seed = (seed ^ 61) ^ (seed >> 16); 49 | seed *= 9; 50 | seed = seed ^ (seed >> 4); 51 | seed *= 0x27d4eb2d; 52 | seed = seed ^ (seed >> 15); 53 | return seed; 54 | } 55 | }; 56 | 57 | [numthreads(8,8,8)] 58 | void main(uint3 threadIDInGroup : SV_GroupThreadID, uint3 groupID : SV_GroupID, 59 | uint3 dispatchThreadId : SV_DispatchThreadID){ 60 | uint3 p = dispatchThreadId.xyz; 61 | 62 | // Average deposit values in a 3x3x3 neighborhood 63 | // Apply distance-based weighting to prevent overestimation along diagonals 64 | float2 v = float2(0.0, 0.0); 65 | float w = 0.0; 66 | for (int dx = -1; dx <= 1; dx++) { 67 | for (int dy = -1; dy <= 1; dy++) { 68 | for (int dz = -1; dz <= 1; dz++) { 69 | float weight = (all(int3(dx,dy,dz)) == 0)? 1.0 : 1.0 / sqrt(float(abs(dx) + abs(dy) + abs(dz))); 70 | int3 txcoord = int3(p) + int3(dx, dy, dz); 71 | txcoord.x = txcoord.x % world_width; 72 | txcoord.y = txcoord.y % world_height; 73 | txcoord.z = txcoord.z % world_depth; 74 | float2 val = tex_in[txcoord]; 75 | v += weight * val; 76 | w += weight; 77 | } 78 | } 79 | } 80 | v /= w; 81 | 82 | // Decay the deposit by a constant factor 83 | v *= decay_factor; 84 | tex_out[p] = v; 85 | 86 | // Decay the trace a little 87 | // tex_trace[p] *= 0.99; 88 | RNG rng; 89 | rng.set_seed( 90 | rng.wang_hash(uint(113.0*v.x)), 91 | rng.wang_hash(uint(p.x*p.y*p.z)) 92 | ); 93 | tex_trace[p] *= 0.985 + 0.01 * rng.random_float(); // avoid quantization errors of a constant decay factor 94 | } 95 | 96 | -------------------------------------------------------------------------------- /shaders/cs_particles_blit.hlsl: -------------------------------------------------------------------------------- 1 | RWTexture2D<uint> tex_in: register(u0); 2 | RWTexture2D<float> tex_out: register(u1); 3 | 4 | cbuffer ConfigBuffer : register(b4) 5 | { 6 | float4x4 projection_matrix; 7 | float4x4 view_matrix; 8 | float4x4 model_matrix; 9 | int texcoord_map; 10 | float trim_x_min; 11 | float trim_x_max; 12 | float trim_y_min; 13 | float trim_y_max; 14 | float trim_z_min; 15 | float trim_z_max; 16 | float trim_density; 17 | float world_width; 18 | float world_height; 19 | float world_depth; 20 | float screen_width; 21 | float screen_height; 22 | float sample_weight; 23 | float optical_thickness; 24 | float highlight_density; 25 | float galaxy_weight; 26 | float histogram_base; 27 | float overdensity_threshold_low; 28 | float overdensity_threshold_high; 29 | }; 30 | 31 | [numthreads(1, 1, 1)] 32 | void main(uint3 threadIDInGroup : SV_GroupThreadID, uint3 groupID : SV_GroupID, 33 | uint3 dispatchThreadId : SV_DispatchThreadID){ 34 | float val = tex_in[dispatchThreadId.xy]; 35 | if (val < 10000) { 36 | tex_out[dispatchThreadId.xy] = val * sample_weight; 37 | } else { 38 | tex_out[dispatchThreadId.xy] = val; 39 | } 40 | } -------------------------------------------------------------------------------- /shaders/cs_particles_transform.hlsl: -------------------------------------------------------------------------------- 1 | RWTexture2D<uint> tex_out: register(u0); 2 | RWStructuredBuffer<float> particles_x: register(u2); 3 | RWStructuredBuffer<float> particles_y: register(u3); 4 | RWStructuredBuffer<float> particles_z: register(u4); 5 | RWStructuredBuffer<float> particles_t: register(u6); 6 | 7 | cbuffer ConfigBuffer : register(b4) 8 | { 9 | float4x4 projection_matrix; 10 | float4x4 view_matrix; 11 | float4x4 model_matrix; 12 | int texcoord_map; 13 | float trim_x_min; 14 | float trim_x_max; 15 | float trim_y_min; 16 | float trim_y_max; 17 | float trim_z_min; 18 | float trim_z_max; 19 | float trim_density; 20 | float world_width; 21 | float world_height; 22 | float world_depth; 23 | float screen_width; 24 | float screen_height; 25 | float sample_weight; 26 | float optical_thickness; 27 | float highlight_density; 28 | float galaxy_weight; 29 | float histogram_base; 30 | float overdensity_threshold_low; 31 | float overdensity_threshold_high; 32 | }; 33 | 34 | uint wang_hash(uint seed) 35 | { 36 | seed = (seed ^ 61) ^ (seed >> 16); 37 | seed *= 9; 38 | seed = seed ^ (seed >> 4); 39 | seed *= 0x27d4eb2d; 40 | seed = seed ^ (seed >> 15); 41 | return seed; 42 | } 43 | 44 | float random(int seed) { 45 | return float(wang_hash(seed) % 1000) / 1000.0f; 46 | } 47 | 48 | float3 random_sphere(uint hash) 49 | { 50 | float a = random(hash); 51 | float b = random(hash + 3); 52 | float azimuth = a * 2 * 3.14159265; 53 | float polar = acos(2 * b - 1); 54 | 55 | float3 result; 56 | result.x = sin(polar) * cos(azimuth); 57 | result.y = cos(polar); 58 | result.z = sin(polar) * sin(azimuth); 59 | 60 | return result; 61 | } 62 | 63 | [numthreads(10, 10, 10)] 64 | void main(uint3 threadIDInGroup : SV_GroupThreadID, uint3 group_id : SV_GroupID, 65 | uint3 dispatchThreadId : SV_DispatchThreadID, uint index : SV_GroupIndex){ 66 | uint idx = index + 1000 * (group_id.x + group_id.y * 10 + group_id.z * 100); 67 | 68 | float x = particles_x[idx]; 69 | float y = particles_y[idx]; 70 | float z = particles_z[idx]; 71 | float t = particles_t[idx]; 72 | float3 in_pos = float3(x, y, z); 73 | 74 | // Project point in "mold world texture space" to 3D scene world space. 75 | float3 world_size = float3(world_width, world_height, world_depth); 76 | float4 in_posf = float4(in_pos / world_size, 1.0); 77 | if (in_posf.x < trim_x_min || in_posf.x > trim_x_max || 78 | in_posf.y < trim_y_min || in_posf.y > trim_y_max || 79 | in_posf.z < trim_z_min || in_posf.z > trim_z_max ) 80 | return; 81 | in_posf.xyz = (2.0 * in_posf.xyz - 1.0.xxx) * float3(1.0, world_height / world_width, world_depth / world_width); 82 | in_posf.yz *= -1; // Invert yz axis because the direction is different for textures and standard right handed system. 83 | 84 | // Project into 3D scene world space. 85 | float4 world_pos = mul(view_matrix, in_posf); 86 | 87 | // Project from 3D to 2D. 88 | float4 out_posf = mul(projection_matrix, world_pos); 89 | out_posf /= out_posf.w; 90 | out_posf = out_posf * 0.5 + 0.5; 91 | if (out_posf.x < 0.0 || out_posf.y < 0.0 || out_posf.x > 1.0 || out_posf.y > 1.0) 92 | return; 93 | 94 | // Store sample to output texture. 95 | out_posf.xy *= float2(screen_width, screen_height); 96 | uint2 out_pos = uint2(out_posf.xy); 97 | if (t < 0.0) { 98 | if (galaxy_weight > 0.001) { 99 | InterlockedAdd(tex_out[out_pos], 10000); 100 | } 101 | } else { 102 | InterlockedAdd(tex_out[out_pos], 10); 103 | } 104 | } -------------------------------------------------------------------------------- /shaders/ps_particles_color.hlsl: -------------------------------------------------------------------------------- 1 | struct PixelInput 2 | { 3 | float4 position_out: SV_POSITION; 4 | float2 texcoord_out: TEXCOORD; 5 | }; 6 | 7 | Texture2D tex_trace : register(t0); 8 | SamplerState tex_sampler_trace : register(s0); 9 | 10 | float4 main(PixelInput input) : SV_TARGET 11 | { 12 | float v = tex_trace.Sample(tex_sampler_trace, input.texcoord_out); 13 | if (v > 9999.0) { 14 | return float4(1.0-exp(-0.0001*v), 0, 0, 1); 15 | } 16 | v /= 3.0; 17 | return float4(0.6*v, v, 0.7*v, 1.0); 18 | } -------------------------------------------------------------------------------- /shaders/ps_volpath.hlsl: -------------------------------------------------------------------------------- 1 | struct PixelInput { 2 | float4 position_out: SV_POSITION; 3 | float2 texcoord_out: TEXCOORD; 4 | }; 5 | 6 | Texture2D tex : register(t0); 7 | SamplerState tex_sampler : register(s0); 8 | 9 | cbuffer ConfigBuffer : register(b4) 10 | { 11 | float4x4 projection_matrix; 12 | float4x4 view_matrix; 13 | float4x4 model_matrix; 14 | int texcoord_map; 15 | float trim_x_min; 16 | float trim_x_max; 17 | float trim_y_min; 18 | float trim_y_max; 19 | float trim_z_min; 20 | float trim_z_max; 21 | float trim_density; 22 | float grid_x; 23 | float grid_y; 24 | float grid_z; 25 | float screen_width; 26 | float screen_height; 27 | float sample_weight; 28 | float optical_thickness; 29 | float highlight_density; 30 | float galaxy_weight; 31 | float histogram_base; 32 | float overdensity_threshold_low; 33 | float overdensity_threshold_high; 34 | float camera_x; 35 | float camera_y; 36 | float camera_z; 37 | int pt_iteration; 38 | float sigma_s; 39 | float sigma_a; 40 | float sigma_e; 41 | float trace_max; 42 | float camera_offset_x; 43 | float camera_offset_y; 44 | float exposure; 45 | int n_bounces; 46 | float ambient_trace; 47 | int compressive_accumulation; 48 | int dummy2; 49 | int dummy3; 50 | }; 51 | 52 | float3 tonemap(float3 L, float exposure) { 53 | return float3(1.0, 1.0, 1.0) - exp(-exposure * L); 54 | } 55 | 56 | float4 main(PixelInput input) : SV_TARGET { 57 | float3 L = tex.Sample(tex_sampler, input.texcoord_out).rgb; 58 | return float4(compressive_accumulation == 1 ? L : tonemap(L, exposure), 1.0); 59 | } -------------------------------------------------------------------------------- /shaders/ps_volume_halocolor.hlsl: -------------------------------------------------------------------------------- 1 | struct PixelInput 2 | { 3 | float4 position_out: SV_POSITION; 4 | float3 texcoord_out: TEXCOORD; 5 | }; 6 | 7 | Texture3D tex_trace : register(t0); 8 | SamplerState tex_trace_sampler : register(s0); 9 | Texture3D tex_deposit : register(t1); 10 | SamplerState tex_deposit_sampler : register(s1); 11 | 12 | cbuffer ConfigBuffer : register(b4) 13 | { 14 | float4x4 projection_matrix; 15 | float4x4 view_matrix; 16 | float4x4 model_matrix; 17 | int texcoord_map; 18 | float trim_x_min; 19 | float trim_x_max; 20 | float trim_y_min; 21 | float trim_y_max; 22 | float trim_z_min; 23 | float trim_z_max; 24 | float trim_density; 25 | float world_width; 26 | float world_height; 27 | float world_depth; 28 | float screen_width; 29 | float screen_height; 30 | float sample_weight; 31 | float optical_thickness; 32 | float highlight_density; 33 | float galaxy_weight; 34 | float histogram_base; 35 | }; 36 | 37 | float remap(float val, float slope) 38 | { 39 | return 1.0 - exp(-slope * val); 40 | } 41 | 42 | float4 main(PixelInput input) : SV_TARGET 43 | { 44 | float4 fragment; 45 | if (input.texcoord_out.x < trim_x_min || input.texcoord_out.x > trim_x_max || 46 | input.texcoord_out.y < trim_y_min || input.texcoord_out.y > trim_y_max || 47 | input.texcoord_out.z < trim_z_min || input.texcoord_out.z > trim_z_max) { 48 | fragment = 0.0.xxxx; 49 | } 50 | else { 51 | float trace = 2.0 * tex_trace.Sample(tex_trace_sampler, input.texcoord_out.xyz); 52 | trace -= 0.166 * tex_trace.Sample(tex_trace_sampler, input.texcoord_out.xyz + float3( 1./world_width, 0, 0)); 53 | trace -= 0.166 * tex_trace.Sample(tex_trace_sampler, input.texcoord_out.xyz + float3(-1./world_width, 0, 0)); 54 | trace -= 0.166 * tex_trace.Sample(tex_trace_sampler, input.texcoord_out.xyz + float3(0, 1./world_height, 0)); 55 | trace -= 0.166 * tex_trace.Sample(tex_trace_sampler, input.texcoord_out.xyz + float3(0,-1./world_height, 0)); 56 | trace -= 0.166 * tex_trace.Sample(tex_trace_sampler, input.texcoord_out.xyz + float3(0, 0, 1./world_depth)); 57 | trace -= 0.166 * tex_trace.Sample(tex_trace_sampler, input.texcoord_out.xyz + float3(0, 0, -1./world_depth)); 58 | float t = sample_weight * (trace - trim_density); 59 | float2 deposit = tex_deposit.Sample(tex_deposit_sampler, input.texcoord_out.xyz).xy; 60 | float2 d = galaxy_weight * deposit; 61 | 62 | fragment.rgb = remap(t, 0.6) * float3(0.5, 0.5, 0.5); 63 | if (d.y > 0.0) 64 | fragment.rgb += remap(d.x, 0.1) * float3(0.0, 0.0, 0.8); 65 | else// if (d.y < 0.0) 66 | fragment.rgb += remap(d.x, 0.1) * float3(0.7, 0.0, 0.0); 67 | // else 68 | // fragment.rgb += remap(d.x, 0.1) * float3(0.0, 0.6, 0.0); 69 | 70 | fragment.a = (0.3*t + 0.15*d.x) * optical_thickness; 71 | } 72 | 73 | fragment.rgb *= 2.0; // Compensate for the drawing 1 stack of meta-quads instead of 3 74 | return fragment; 75 | } -------------------------------------------------------------------------------- /shaders/ps_volume_highlight.hlsl: -------------------------------------------------------------------------------- 1 | struct PixelInput 2 | { 3 | float4 position_out: SV_POSITION; 4 | float3 texcoord_out: TEXCOORD; 5 | }; 6 | 7 | Texture3D tex_trace : register(t0); 8 | SamplerState tex_trace_sampler : register(s0); 9 | Texture3D tex_deposit : register(t1); 10 | SamplerState tex_deposit_sampler : register(s1); 11 | 12 | cbuffer ConfigBuffer : register(b4) 13 | { 14 | float4x4 projection_matrix; 15 | float4x4 view_matrix; 16 | float4x4 model_matrix; 17 | int texcoord_map; 18 | float trim_x_min; 19 | float trim_x_max; 20 | float trim_y_min; 21 | float trim_y_max; 22 | float trim_z_min; 23 | float trim_z_max; 24 | float trim_density; 25 | float world_width; 26 | float world_height; 27 | float world_depth; 28 | float screen_width; 29 | float screen_height; 30 | float sample_weight; 31 | float optical_thickness; 32 | float highlight_density; 33 | float galaxy_weight; 34 | float histogram_base; 35 | }; 36 | 37 | float remap(float val, float slope) 38 | { 39 | return 1.0 - exp(-slope * val); 40 | } 41 | 42 | float4 main(PixelInput input) : SV_TARGET 43 | { 44 | float4 fragment; 45 | if (input.texcoord_out.x < trim_x_min || input.texcoord_out.x > trim_x_max || 46 | input.texcoord_out.y < trim_y_min || input.texcoord_out.y > trim_y_max || 47 | input.texcoord_out.z < trim_z_min || input.texcoord_out.z > trim_z_max) { 48 | fragment = 0.0.xxxx; 49 | } 50 | else { 51 | float trace = tex_trace.Sample(tex_trace_sampler, input.texcoord_out.xyz); 52 | float t = sample_weight * (trace - trim_density); 53 | float deposit = tex_deposit.Sample(tex_deposit_sampler, input.texcoord_out.xyz); 54 | float d = galaxy_weight * deposit; 55 | 56 | // fragment.rgb = remap(t, 0.3) * float3(0.0, 2.1, 15.0) + remap(d, 0.2) * float3(1.0, 0.05, 0.0); 57 | fragment.rgb = remap(t, 0.3) * float3(0.6, 0.05, 0.9) + remap(d, 0.2) * float3(1.0, 0.6, 0.0); 58 | fragment.a = (0.2*t + 0.1*d) * optical_thickness; 59 | 60 | float highlight_low = highlight_density / sqrt(histogram_base); 61 | float highlight_high = highlight_density * sqrt(histogram_base); 62 | // float highlight_low = highlight_density / sqrt(pow(histogram_base, 0.4)); 63 | // float highlight_high = highlight_density * sqrt(pow(histogram_base, 0.4)); 64 | if (trace > highlight_low && trace < highlight_high) { 65 | float smooth_weight = smoothstep(highlight_low, highlight_low + 0.1 * (highlight_high-highlight_low), trace) 66 | * (1.0 - smoothstep(highlight_high - 0.1 * (highlight_high-highlight_low), highlight_high, trace)); 67 | fragment.rgb = (1.0-smooth_weight) * fragment.rgb 68 | + smooth_weight * remap(trace, 10.0) * float3(0.0, 1.0, 0.0); 69 | fragment.a = (1.0-smooth_weight) * fragment.a 70 | + smooth_weight * remap(trace, 10.0) * optical_thickness; 71 | } 72 | } 73 | 74 | fragment.rgb *= 2.0; // Compensate for the drawing 1 stack of meta-quads instead of 3 75 | return fragment; 76 | } -------------------------------------------------------------------------------- /shaders/ps_volume_overdensity.hlsl: -------------------------------------------------------------------------------- 1 | struct PixelInput 2 | { 3 | float4 position_out: SV_POSITION; 4 | float3 texcoord_out: TEXCOORD; 5 | }; 6 | 7 | Texture3D tex_trace : register(t0); 8 | SamplerState tex_sampler_trace : register(s0); 9 | 10 | cbuffer ConfigBuffer : register(b4) 11 | { 12 | float4x4 projection_matrix; 13 | float4x4 view_matrix; 14 | float4x4 model_matrix; 15 | int texcoord_map; 16 | float trim_x_min; 17 | float trim_x_max; 18 | float trim_y_min; 19 | float trim_y_max; 20 | float trim_z_min; 21 | float trim_z_max; 22 | float trim_density; 23 | float world_width; 24 | float world_height; 25 | float world_depth; 26 | float screen_width; 27 | float screen_height; 28 | float sample_weight; 29 | float optical_thickness; 30 | float highlight_density; 31 | float galaxy_weight; 32 | float histogram_base; 33 | float overdensity_threshold_low; 34 | float overdensity_threshold_high; 35 | }; 36 | 37 | #define COLOR_UNDERDENSE float4(0.0, 0.0, 25.0, 0.08) 38 | #define COLOR_MIDDENSE float4(0.0, 2.0, 0.0, 0.06) 39 | #define COLOR_OVERDENSE float4(10.0, 0.0, 0.0, 0.15) 40 | 41 | float remap(float val, float slope) 42 | { 43 | return 1.0 - exp(-slope * val); 44 | } 45 | 46 | float4 main(PixelInput input) : SV_TARGET 47 | { 48 | float4 fragment; 49 | float trace = tex_trace.Sample(tex_sampler_trace, input.texcoord_out.xyz); 50 | if (input.texcoord_out.x < trim_x_min || input.texcoord_out.x > trim_x_max || 51 | input.texcoord_out.y < trim_y_min || input.texcoord_out.y > trim_y_max || 52 | input.texcoord_out.z < trim_z_min || input.texcoord_out.z > trim_z_max || 53 | trace < trim_density) { 54 | fragment = 0.0.xxxx; 55 | } 56 | else { 57 | if (trace < overdensity_threshold_low) 58 | fragment = COLOR_UNDERDENSE; 59 | else if (trace >= overdensity_threshold_low && trace < overdensity_threshold_high) 60 | fragment = COLOR_MIDDENSE; 61 | else if (trace >= overdensity_threshold_high) 62 | fragment = COLOR_OVERDENSE; 63 | fragment.rgb *= remap(2.71, sample_weight); 64 | fragment.a *= optical_thickness * remap(trace, 1.0); 65 | } 66 | 67 | fragment.rgb *= 2.0; // Compensate for the drawing 1 stack of meta-quads instead of 3 68 | return fragment; 69 | } -------------------------------------------------------------------------------- /shaders/ps_volume_trace.hlsl: -------------------------------------------------------------------------------- 1 | struct PixelInput 2 | { 3 | float4 position_out: SV_POSITION; 4 | float3 texcoord_out: TEXCOORD; 5 | }; 6 | 7 | Texture3D tex_trace : register(t0); 8 | SamplerState tex_sampler_trace : register(s0); 9 | Texture2D tex_false_color : register(t1); 10 | SamplerState tex_false_color_sampler : register(s1); 11 | 12 | cbuffer ConfigBuffer : register(b4) 13 | { 14 | float4x4 projection_matrix; 15 | float4x4 view_matrix; 16 | float4x4 model_matrix; 17 | int texcoord_map; 18 | float trim_x_min; 19 | float trim_x_max; 20 | float trim_y_min; 21 | float trim_y_max; 22 | float trim_z_min; 23 | float trim_z_max; 24 | float trim_density; 25 | float world_X; 26 | float world_Y; 27 | float world_Z; 28 | float screen_width; 29 | float screen_height; 30 | float sample_weight; 31 | float optical_thickness; 32 | float highlight_density; 33 | float galaxy_weight; 34 | float histogram_base; 35 | }; 36 | 37 | float remap(float val, float slope) 38 | { 39 | return 1.0 - exp(-slope * val); 40 | } 41 | 42 | float4 main(PixelInput input) : SV_TARGET 43 | { 44 | float4 fragment; 45 | float trace = tex_trace.Sample(tex_sampler_trace, input.texcoord_out.xyz).r; 46 | if (input.texcoord_out.x < trim_x_min || input.texcoord_out.x > trim_x_max || 47 | input.texcoord_out.y < trim_y_min || input.texcoord_out.y > trim_y_max || 48 | input.texcoord_out.z < trim_z_min || input.texcoord_out.z > trim_z_max || 49 | // false) { 50 | trace < trim_density) { 51 | fragment = 0.0.xxxx; 52 | } 53 | else { 54 | float t = (trace - trim_density) * sample_weight; 55 | fragment.rgb = tex_false_color.Sample(tex_false_color_sampler, float2(remap(t, 1.0), 0.5)).rgb; 56 | fragment.a = optical_thickness * remap(t, 1.0); 57 | 58 | // Proxy draws config 59 | // see http://geomalgorithms.com/a02-_lines.html 60 | 61 | // float3 o = float3(0.9321, 0.5179, 0.1403); // for SDSS_huge 62 | // float3 v_l = float3(0.2175, 0.4660, 0.4807) - o; // for SDSS_huge 63 | 64 | // float3 o = float3(-0.0504, 1.0047, 0.8905); // for FRB_cigale 65 | // float3 v_l = float3(0.6647, 0.4100, 0.4624) - o; // for FRB_cigale 66 | 67 | // float3 u_l = normalize(v_l); 68 | // float3 w = input.texcoord_out.xyz - o; 69 | 70 | // // Proxy sightline 71 | // float3 d = w - dot(w, u_l) * u_l; 72 | // d *= float3(world_X, world_Y, world_Z); 73 | // if (length(d) < 2.0) { 74 | // fragment.rgb += float3(2.0, t, 0.0); 75 | // fragment.a += optical_thickness * 2.0; 76 | // } 77 | 78 | // // Proxy distance shells 79 | // v_l *= float3(world_X, world_Y, world_Z); 80 | // w *= float3(world_X, world_Y, world_Z); 81 | // float roi_distance = 10.0 * galaxy_weight * length(v_l); 82 | // float shell_thickness = 1.0; // voxels 83 | // if (abs(length(w) - 0.25 * roi_distance) < shell_thickness || 84 | // abs(length(w) - 0.50 * roi_distance) < shell_thickness || 85 | // abs(length(w) - 0.75 * roi_distance) < shell_thickness || 86 | // abs(length(w) - 1.00 * roi_distance) < shell_thickness ) { 87 | // fragment.rgb += float3(0.5, t, 1.0); 88 | // // fragment.rgb += float3(2.0, t, 0.2); 89 | // fragment.a += optical_thickness * 0.3; 90 | // } 91 | } 92 | 93 | fragment.rgb *= 2.0; // Compensate for the drawing 1 stack of meta-quads instead of 3 94 | return fragment; 95 | } -------------------------------------------------------------------------------- /shaders/ps_volume_velocity.hlsl: -------------------------------------------------------------------------------- 1 | struct PixelInput 2 | { 3 | float4 position_out: SV_POSITION; 4 | float3 texcoord_out: TEXCOORD; 5 | }; 6 | 7 | Texture3D tex_trace : register(t0); 8 | SamplerState tex_sampler_trace : register(s0); 9 | 10 | cbuffer ConfigBuffer : register(b4) 11 | { 12 | float4x4 projection_matrix; 13 | float4x4 view_matrix; 14 | float4x4 model_matrix; 15 | int texcoord_map; 16 | float trim_x_min; 17 | float trim_x_max; 18 | float trim_y_min; 19 | float trim_y_max; 20 | float trim_z_min; 21 | float trim_z_max; 22 | float trim_density; 23 | float world_width; 24 | float world_height; 25 | float world_depth; 26 | float screen_width; 27 | float screen_height; 28 | float sample_weight; 29 | float optical_thickness; 30 | float highlight_density; 31 | float galaxy_weight; 32 | float histogram_base; 33 | float overdensity_threshold_low; 34 | float overdensity_threshold_high; 35 | }; 36 | 37 | float remap(float val, float slope) 38 | { 39 | return 1.0 - exp(-slope * val); 40 | } 41 | 42 | float4 main(PixelInput input) : SV_TARGET 43 | { 44 | float4 fragment; 45 | float4 phase = tex_trace.Sample(tex_sampler_trace, input.texcoord_out.xyz).rgba; 46 | if (input.texcoord_out.x < trim_x_min || input.texcoord_out.x > trim_x_max || 47 | input.texcoord_out.y < trim_y_min || input.texcoord_out.y > trim_y_max || 48 | input.texcoord_out.z < trim_z_min || input.texcoord_out.z > trim_z_max) { 49 | fragment = 0.0.xxxx; 50 | } 51 | else { 52 | fragment.rgb = sample_weight * phase.gba * phase.gba * float3(0.6, 0.5, 1.0); 53 | fragment.a = remap(0.1 * phase.r, optical_thickness); 54 | } 55 | 56 | fragment.rgb *= 2.0; // Compensate for the drawing 1 stack of meta-quads instead of 3 57 | return fragment; 58 | } -------------------------------------------------------------------------------- /shaders/vs_2d.hlsl: -------------------------------------------------------------------------------- 1 | struct VertexInput 2 | { 3 | float4 position: POSITION; 4 | float2 texcoord: TEXCOORD; 5 | }; 6 | 7 | struct VertexOutput 8 | { 9 | float4 position_out: SV_POSITION; 10 | float2 texcoord_out: TEXCOORD; 11 | }; 12 | 13 | VertexOutput main(VertexInput input) 14 | { 15 | VertexOutput result; 16 | 17 | result.position_out = input.position; 18 | result.texcoord_out = input.texcoord; 19 | 20 | return result; 21 | } -------------------------------------------------------------------------------- /shaders/vs_3d.hlsl: -------------------------------------------------------------------------------- 1 | struct VertexInput 2 | { 3 | float4 position: POSITION; 4 | float3 texcoord: TEXCOORD; 5 | }; 6 | 7 | struct VertexOutput 8 | { 9 | float4 position_out: SV_POSITION; 10 | float3 texcoord_out: TEXCOORD; 11 | }; 12 | 13 | 14 | cbuffer ConfigBuffer : register(b4) 15 | { 16 | float4x4 projection_matrix; 17 | float4x4 view_matrix; 18 | float4x4 model_matrix; 19 | int texcoord_map; 20 | }; 21 | 22 | VertexOutput main(VertexInput input) 23 | { 24 | VertexOutput result; 25 | 26 | result.position_out = mul(projection_matrix, mul(view_matrix, mul(model_matrix, input.position))); 27 | if (texcoord_map == 1) { 28 | result.texcoord_out = float3(input.texcoord.x, input.texcoord.y, input.texcoord.z); 29 | } else if (texcoord_map == -1) { 30 | result.texcoord_out = float3(1.0-input.texcoord.x, input.texcoord.y, 1.0-input.texcoord.z); 31 | } else if (texcoord_map == 2) { 32 | result.texcoord_out = float3(input.texcoord.x, input.texcoord.z, 1.0-input.texcoord.y); 33 | } else if (texcoord_map == -2) { 34 | result.texcoord_out = float3(input.texcoord.x, 1.0-input.texcoord.z, input.texcoord.y); 35 | } else if (texcoord_map == 3) { 36 | result.texcoord_out = float3(1.0-input.texcoord.z, input.texcoord.y, input.texcoord.x); 37 | } else if (texcoord_map == -3) { 38 | result.texcoord_out = float3(input.texcoord.z, input.texcoord.y, 1.0-input.texcoord.x); 39 | } 40 | 41 | return result; 42 | } --------------------------------------------------------------------------------