depressed-pho / natural-mystic-shaders

Shader pack for Minecraft Bedrock aliming to be as realistic as possible
Creative Commons Zero v1.0 Universal
28 stars 3 forks source link

Possible optimization of the cloud shader #29

Closed depressed-pho closed 5 years ago

depressed-pho commented 5 years ago

The cloud shader can cause performance issues on low-end devices. Here's an idea for optimizing it:

For any octaves, suppose the accumulated density is d, and the cut-off threshold is c. If d + \Sum_{k=0}^{\infty} {\frac{1}{2}}^k = d + \frac{1}{1-\frac{1}{2}} < c holds, then we immediately know that the density can never reach the threshold and therefore we can exit the loop early. Likewise, suppose the amplification factor is a, and if ad \geq 1 then we immediately know that any further accumulation will not affect the density.

depressed-pho commented 5 years ago

But of course conditional branches in shaders is a Bad Thing and it may even work the other way.

depressed-pho commented 5 years ago

I did it, and it seemed to be effective at least on iPad Pro. Closing.