Initial Commit
This commit is contained in:
82
tools/ShaderProcessor.py
Normal file
82
tools/ShaderProcessor.py
Normal file
@@ -0,0 +1,82 @@
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
|
||||
# Specify the directory where your .frag files are located
|
||||
directory_path = 'src'
|
||||
output_directory = 'processed'
|
||||
|
||||
# List of variables to update
|
||||
variables_to_update = [
|
||||
'iTime', 'iTimeDelta', 'iFrameRate', 'iSampleRate',
|
||||
'iFrame', 'iDate', 'iMouse', 'iResolution',
|
||||
r'iChannelTime', r'iChannelResolution'
|
||||
]
|
||||
|
||||
# Header and footer to append
|
||||
header = '''
|
||||
#version 450
|
||||
|
||||
layout(location = 0) in vec2 qt_TexCoord0;
|
||||
layout(location = 0) out vec4 fragColor;
|
||||
|
||||
layout(std140, binding = 0) uniform buf {
|
||||
mat4 qt_Matrix;
|
||||
float qt_Opacity;
|
||||
float iTime;
|
||||
float iTimeDelta;
|
||||
float iFrameRate;
|
||||
float iSampleRate;
|
||||
int iFrame;
|
||||
vec4 iDate;
|
||||
vec4 iMouse;
|
||||
vec3 iResolution;
|
||||
float iChannelTime[4];
|
||||
vec3 iChannelResolution[4];
|
||||
} ubuf;
|
||||
|
||||
layout(binding = 1) uniform sampler2D iChannel0;
|
||||
layout(binding = 2) uniform sampler2D iChannel1;
|
||||
layout(binding = 3) uniform sampler2D iChannel2;
|
||||
layout(binding = 4) uniform sampler2D iChannel3;
|
||||
|
||||
vec2 fragCoord = vec2(qt_TexCoord0.x, 1.0 - qt_TexCoord0.y) * ubuf.iResolution.xy;
|
||||
'''
|
||||
|
||||
footer = '''
|
||||
|
||||
void main() {
|
||||
vec4 color = vec4(0.0);
|
||||
mainImage(color, fragCoord);
|
||||
fragColor = color;
|
||||
}
|
||||
'''
|
||||
|
||||
for root, dirs, files in os.walk(directory_path):
|
||||
for file in files:
|
||||
if file.endswith('.frag'):
|
||||
file_path = os.path.join(root, file)
|
||||
|
||||
with open(file_path, 'r', encoding='utf-8') as f:
|
||||
content = f.read()
|
||||
|
||||
# Replace variable names
|
||||
for var in variables_to_update:
|
||||
content = re.sub(r'\b' + re.escape(var) + r'\b', 'ubuf.' + var, content)
|
||||
|
||||
# Insert header after first empty line
|
||||
insert_index = content.find('\n\n') + 1
|
||||
content = content[:insert_index] + header + content[insert_index:]
|
||||
|
||||
# Append footer
|
||||
content += footer
|
||||
|
||||
# Construct new output path
|
||||
relative_path = os.path.relpath(root, directory_path)
|
||||
new_root = os.path.join(output_directory, relative_path)
|
||||
os.makedirs(new_root, exist_ok=True)
|
||||
new_file_path = os.path.join(new_root, file)
|
||||
|
||||
# Write to the new file
|
||||
with open(new_file_path, 'w', encoding='utf-8') as f:
|
||||
f.write(content)
|
||||
Reference in New Issue
Block a user