Open ahmetaa opened 10 years ago
Why not use the same technique which is used in the Go version, i.e. just calculate a good enough random number
As I said this can apply to all languages.
I was talking about this:
https://github.com/kid0m4n/rays/blob/master/gorays/main.go#L57-L66
Sorry I misinterpreted what you said. That function is like a simple hash function. If it is good enough for ray tracing I guess it is fine. But a sequence still would be faster.
Faster sure. But we gotta strike a balance. Precomputing value would a stretch IMHO.
In the Java code there are a lot of ThreadLocalRandom.current().nextFloat() calls. Random float number generation is quite slow in general. If this is used a lot in the loops it may create a bottleneck.
So Instead, creating a large global random number array beforehand and use the values afterwards would be faster. According to my not-so-reliable test it is around 7-8 times faster than ThreadLocalRandom nextFloat(). Below is an example class for this. Probably using this one instance per thread is a good idea. This can apply to all languages.
Of course this is not exactly random so it may not work at all. But it still may worth a shot when look-up is large enough (hundreds of thousands?).
something like