JOML 1.9.0 Pre-Release

The next version of JOML, which will be 1.9.0, will feature ‘immutable’ views/interfaces on all JOML classes.
This feature was proposed over a year ago and finally made its way into the code base.
For a detailed debate/examination of immutable views, have a look at the mentioned GitHub issue #52.

In summary, it allows an API to communicate/express the intent that a data structure, which it exposes or consumes, should/will not be modified by the consumer and/or by the provider. This is valuable in the way that a consumer of that API will know what to do when given a mutable or immutable data structure, which is most apparent when dealing with mutable instances such as Vector4f or Matrix4f, and with a client not knowing whether it can savely store a reference to this instance or (inefficiently) copy the data structure.
Likewise, it protects the API provider from unintentional modifications made by the API consumer.

Examples:


// API provider:

private Vector4f internal;
public Vector4fc provideImmutable() {
  return internal;
}
public void consumeImmutable(Vector4fc constVector) {
  // ... constVector will not be modified ...
}

// API client:

Vector4fc providerVector = api.provideImmutable();
// providerVector will not be changed by API consumer
Vector4f clientVector = new Vector4f(...);
api.consumeImmutable(clientVector);

So, it’s all about communicating and to some extent enforcing intention of how a data structure is to be used, and by whom. This in turn improves efficiency and reduces errors in programs due to unclear semantics/intentions.

The release will happen in a few days once final testing is done.

People interested in it, can already use it from oss.sonatype.org as org.joml:joml:1.9.0-SNAPSHOT or from the GitHub repository. The API is stable and also completely backwards source-compatible, meaning that porting an unmodified application from earlier JOML versions to 1.9.0 will compile without changes.

The 1.9.0 release will also feature various methods to generate sampling patterns:

  • Poisson on Disk
  • Best Candidate on Disk
  • Equi-Angle “Spiral” on Disk
  • Stratified / “Center-weighted” Stratified on Square
  • Uniform Disk
  • Uniform Sphere

These can be helpful to generate sample locations for use in a shader.

Also new is Gaussian convolution kernel generation configurable for 2D and separable 1D kernels.

Example of Poisson (left) and Best Candidate (right) with 11,070 samples:

The code for the sampling all looks good. I’d think about changing the random number generator.

xorshiro maybe: http://xoroshiro.di.unimi.it/

A maybe problem here is it’s 64-bit (thinking android). I tossed up a few other various choices here: https://github.com/roquendm/JGO-Grabbag/tree/master/src/roquen/math/rng

EDIT: Seems I drop the ball on some of mine. I can restructure these to be faster on average for real use patterns.

Cool! I’d love to use a decent and first-and-foremost reproducible/deterministic, as in “people can see how it works and it produces the same results on all machines,” PRNG.

Well if 64-bit operations are ok…xoroshiro is state-of-the-art and very fast (notice the result is ready after one addition).

Xoroshiro128+ looks decent. I am a bit unsure whether a nextInt() method would just use the 64-bit long computed by Xoroshiro and cut off the upper 32-bits.
The results however look good, so I guess, it’s okay.

Yeah you can just drop the high bits.

Now also featuring Best Candidate sampling on a sphere using Hierarchical Triangular Mesh indexing for fast 1-nearest neighbor search. This generates nice blue noise sampling patterns useful for 3D sampling in ambient occlusion or ray tracing.

Left: 128 samples
Right: 4096 samples
Black are in foreground, Grey in background