-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_pyblend3.py
More file actions
35 lines (28 loc) · 1.47 KB
/
update_pyblend3.py
File metadata and controls
35 lines (28 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
def update_pyblend():
with open("Sources/HeyFoSCore/Processing/PyBlend.swift", "r") as f:
text = f.read()
# Increase dilation kernel size
old_dilate = """let dilated = try dilateTexture(focusMap, kernelSize: 15)"""
new_dilate = """let dilated = try dilateTexture(focusMap, kernelSize: 25)"""
text = text.replace(old_dilate, new_dilate)
# Increase blur to match the bigger dilation (prevent jagged edges)
old_blur = """let blurred = try gaussianBlur(dilated, radius: 3.0)"""
new_blur = """let blurred = try gaussianBlur(dilated, radius: 5.0)"""
text = text.replace(old_blur, new_blur)
# Increase exponent to make it closer to winner-takes-all, completely killing small focus responses
old_exp = "var exponentParam: Float = 4.0"
new_exp = "var exponentParam: Float = 12.0"
text = text.replace(old_exp, new_exp)
# We can also add a minimum threshold in the shader
old_shader = """float val = input.read(gid).r;
float sharpened = pow(max(val, 0.0001f), exponent);"""
new_shader = """float val = input.read(gid).r;
// Add a small threshold to completely kill noise floor
if (val < 0.01f) { val = 0.0f; }
float sharpened = pow(max(val, 0.000001f), exponent);"""
text = text.replace(old_shader, new_shader)
with open("Sources/HeyFoSCore/Processing/PyBlend.swift", "w") as f:
f.write(text)
print("Updated PyBlend.swift")
if __name__ == "__main__":
update_pyblend()