Created
June 26, 2021 15:59
-
-
Save mkvenkit/16c85171d7a71d58d364ff23b7060bbb to your computer and use it in GitHub Desktop.
Make a bump map
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from PIL import Image | |
from math import sqrt | |
def main(): | |
NX, NY = 256, 256 | |
nmap = np.zeros([NX, NY, 3], np.float32) | |
r = 32.0 | |
rsq = r*r | |
centers = [(64, 64), (192, 64), (64, 192), (192, 192)] | |
for i in range(NX): | |
for j in range(NY): | |
inside = False | |
for C in centers: | |
x = (i-C[0]) | |
y = (j-C[1]) | |
if x*x + y*y < rsq : | |
nmap[i][j][0] = x / r | |
nmap[i][j][1] = y / r | |
nmap[i][j][2] = sqrt(rsq - (x*x + y*y))/ r | |
inside = True | |
if not inside: | |
nmap[i][j][0] = 0.0 | |
nmap[i][j][1] = 0.0 | |
nmap[i][j][2] = 1.0 | |
# [-1, 1] to [0, 255] | |
nmap = 255.0*0.5*(nmap + 1.0) | |
img = np.array(nmap, np.uint8) | |
img = Image.fromarray(img) | |
img.save("bmap.png") | |
# call main | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment