{"id":16132249,"url":"https://github.com/hybriddog/stochastic_texture_sampling_demo","last_synced_at":"2025-04-06T14:43:09.284Z","repository":{"id":151779351,"uuid":"609898835","full_name":"HybridDog/stochastic_texture_sampling_demo","owner":"HybridDog","description":"Stochastic Texture Sampling Demonstration","archived":false,"fork":false,"pushed_at":"2023-05-21T12:02:13.000Z","size":136,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-12T20:45:56.690Z","etag":null,"topics":["computer-graphics","real-time-rendering","texture-mapping","webgl2"],"latest_commit_sha":null,"homepage":"https://hybriddog.github.io/stochastic_texture_sampling_demo/","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/HybridDog.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-03-05T15:16:30.000Z","updated_at":"2023-03-12T13:39:17.000Z","dependencies_parsed_at":null,"dependency_job_id":"f1f56dde-8891-4051-aeb5-91e35ffbc254","html_url":"https://github.com/HybridDog/stochastic_texture_sampling_demo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HybridDog%2Fstochastic_texture_sampling_demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HybridDog%2Fstochastic_texture_sampling_demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HybridDog%2Fstochastic_texture_sampling_demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HybridDog%2Fstochastic_texture_sampling_demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HybridDog","download_url":"https://codeload.github.com/HybridDog/stochastic_texture_sampling_demo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247500447,"owners_count":20948877,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["computer-graphics","real-time-rendering","texture-mapping","webgl2"],"created_at":"2024-10-09T22:29:31.977Z","updated_at":"2025-04-06T14:43:09.270Z","avatar_url":"https://github.com/HybridDog.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Stochastic Texture Sampling Demonstration\n\nThis application is based on the official demonstration of\n[\"Procedural Stochastic Textures by Tiling and\nBlending\"](https://eheitzresearch.wordpress.com/738-2/) by Thomas Deliot and\nEric Heitz, which explains modifications to [\"High-Performance By-Example\nNoise using a Histogram-Preserving Blending\nOperator\"](https://eheitzresearch.wordpress.com/722-2/) for practical\nimplementations.\n\nUsing emscripten, the application can be compiled to a self-contained HTML file,\nwhich works after downloading offline in a web browser.\n\n\n## Colour Transformation\n\nThe decorrelation and gaussianization of colours is implemented as follows:\n* Load an input texture, which is usually in the sRGB colour space\n* Convert the colours of each pixel to OKLab\n* Calculate a decorrelation matrix with Principal Component Analysis from all\n  these colour values and apply this matrix on the colours.\n  Additionally, create a matrix which inverts this decorrelation and the last\n  matrix multiplication step of the OKLab conversion.\n* Perform a histogram transformation for each component of the decorrelated\n  colour vector. Additionally, create lookup tables for the inverse histogram\n  transformation.\n\nExperiments with [SuperTux' snow tiles](https://github.com/SuperTux/supertux/blob/baf72d708b982789c0be8ca912d3b59a76e17c0a/data/images/tiles/snow/convex.png)\nand [Minetest's `default_lava.png`](https://github.com/minetest/minetest_game/blob/aeb27c4db6959d20e525f5754b88d107b168e957/mods/default/textures/default_lava.png)\nhave shown that the colour decorrelation with linear RGB values leads to colour\nproblems in the final image, such as violet colours in the blue SuperTux\ntexture and green colours in the orange-red `default_lava.png`.\nWith sRGB, which is what the demonstration of Thomas Deliot et al. uses, these\nproblems are less visible, and a perceptual colour space appears to give the\nbest results of the three for these example textures.\n\nInstead of a gaussian distribution, this application uses the truncated\ngaussian distribution and soft-clipping contrast operator\nexplained in [On Histogram-preserving Blending for Randomized Texture\nTiling](https://jcgt.org/published/0008/04/02/).\nWith a simple gaussian distribution, the lookup table works badly: the first and\nlast entry do not correspond to the highest and lowest value of the sorted\nchannel values, which results in visible clipping artifacts.\n\n\n## Missing Features\n\nIt is possible to extend this demonstration with more not-yet-implemented\nfeatures, for example:\n* Low discrepancy noise for the patch offsets.\n  If we replace the pcg3d PRNG in the shader by something with\n  low discrepancy, e.g. blue noise, there would be less low frequency in the\n  patch offsets.\n  Hypothetically, this means there are less clumps with visible tiling, so we\n  could make the grid coarser for the same tiling visibility.\n  A coarser grid means better preservation of patterns within the texture.\n  Pressing a key to toggle between low discrepancy and usual randomness could be\n  interesting for the user.\n* Automatically set a good grid scaling using a heuristic.\n  In my experience so far, if the texture has many low frequency parts, a coarse\n  grid scaling looks better whereas if the texure consists of only high\n  frequency parts, the grid scaling can be configured to be finer without\n  altering the look of the texture a lot.\n  It should be possible to do a Wavelet or Fourier transformation on the\n  gaussianized texture to determine the frequencies and use the low frequency\n  amplitudes for a grid scaling value heuristic.\n  Determining the frequencies after the histogram transformations (i.e. on the\n  gaussianized texture) should give better results than using the input texture\n  since the heuristic should be independent of the global contrast, color, etc.\n* Arguments in the URL (HTTP parameters) and command-line.\n  To showcase an example texture with stochastic texture sampling, it can be\n  helpful to initialise the state of the application to a desired one.\n  * Option for interpolation\n  * Initial camera positions\n  * Triangle grid scaling\n  * URL to a texture\n* Transparency support.\n  With a texture with either fully transparent or opaque pixels, the colours\n  currently look wrong (too dark).\n* Support high bit depth and wide gamut images\n  * Investigate if SDL3 works better for this purpose\n  * Use the monitor-specific colour profile (if possible at all)\n  * Load images into linear rgb float arrays (perhaps SDL2 image supports this)\n* Support mipmapping.\n  The original demonstration uses 2D lookup tables to accout for colour problems\n  when mipmaps are used. This is not yet implemented here for simplicity.\n* Texture drag and drop without a browser.\n  Currently, the texture can only be changed the application is compiled with\n  emscripten.\n  With SDL2 drag and drop, it should also be possible to do this without a\n  browser.\n* \"exponentiated blending\" from\n  \"On Histogram-preserving Blending for Randomized Texture Tiling\"\n\nPull requests are welcome.\n\n\n# TODO\n\n* The default \"press h\" texture histogram transformation reversal does not give\n  the original texture; with nearest neighbour interpolation, there are some\n  wrong pixels.\n  This can be tested with adjusted weights in the shader:\n  ```\n  w1 = 1.0;\n  w2 = 0.0;\n  w3 = 0.0;\n  ```\n* With a space texture which is black except for a few stars or a green meadow\n  texture with a single small violet flower, there are visible artifacts.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhybriddog%2Fstochastic_texture_sampling_demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhybriddog%2Fstochastic_texture_sampling_demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhybriddog%2Fstochastic_texture_sampling_demo/lists"}