Closed Upliner closed 3 years ago
UPD: now I also use foreach_set and now displacement calculation is really fast!
2021-02-01 18:17:39,929 INFO: MB-Lab.materialengine - calculate_disp_pixels - 155 - start: calculate_disp_pixels human_female_displacement.png
2021-02-01 18:17:40,195 INFO: MB-Lab.materialengine - calculate_disp_pixels - 172 - finish: calculate_disp_pixels human_female_displacement.png
2021-02-01 18:17:40,230 INFO: MB-Lab.materialengine - calculate_displacement_texture - 313 - Displacement calculated in 0.3054218292236328 seconds
My displacement calculation algorithm is faster and uses less memory
1) multiply_images function doesn't seem to be used anywhere so I removed it 2) pixels.foreach_get() is much faster than np.array(pixels) 3) I use in-place array modifications such as += and *= to get rid of excessive data copying and memory allocations 4) reshape(-1) is faster than flatten() and doesn't allocate additional memory
As a result my version is 2x faster, and calculate_disp_pixels function is 18x faster
Before:
After: