I’m looking for way to generate 3D noise that can be applied to a material and sampled at specific points through C++ and/or BP. My approach is similar to this dynamic physical ocean, but I want to sample opacity based on world position rather that z displacement based on xy position. The author of that technique had limited success with render target lookups, but found it to be too slow to be practical. So I’d hoped to emulate his latter approach, running same logic on both CPU and GPU. I’ve found Perlin, simplex, and gradient noise all capable of creating the cloudy visual effect I’m after. While I’ve been able to generate matching noise on the GPU between shaders and material nodes, and on the CPU between C++ and BP, I get different results where the logic, and even the code(in the case of c++ and shaders) is identical.
For example, the simplex shader I’m using has code like:
float mod289(float x) {
return x - floor(x/289) * 289.0;
}
float permute(float x) {
return mod289(
x*x*34.0 + x
);
}
While permute(111.1) spits out 152.25 in C++ and 152.22 in the material editor, permute(permute(111.1)) spits out 171.375 and 237.154 respectively.
I’m new to C++ and shaders, so I’m wondering if any more experienced coders have dealt with floating point issues like this. Are there any methods I can use, or extra steps I can take to produce somewhat similar results, without destroying the visual effect? I tried adjusting precision by dropping digits at different points to make them match better, but it quickly results in blockyness and strange artifacts.