-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextract_params.py
More file actions
172 lines (133 loc) · 5.27 KB
/
extract_params.py
File metadata and controls
172 lines (133 loc) · 5.27 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import json
import os
from pathlib import Path
from collections import defaultdict
def extract_params():
definitions_dir = Path("/root/image_video_effects/shader_definitions")
# Stats
total_files = 0
shaders_with_params = 0
categories = set()
# Output structure
output = {}
# Find all JSON files
json_files = sorted(definitions_dir.rglob("*.json"))
total_files = len(json_files)
for json_file in json_files:
try:
with open(json_file, 'r') as f:
data = json.load(f)
# Handle array format (like post-processing.json)
if isinstance(data, list):
for item in data:
shader_id = item.get('id')
category = item.get('category')
params = item.get('params', [])
uniforms = item.get('uniforms', {})
if not shader_id:
continue
categories.add(category)
# Convert uniforms to params format if no params exist
if not params and uniforms:
for i, (key, val) in enumerate(uniforms.items()):
param = {
"id": key,
"name": val.get('label', key),
"default": val.get('default', 0.5),
"min": val.get('min', 0),
"max": val.get('max', 1),
"mapping": f"zoom_params.{chr(ord('x') + i)}" if i < 4 else None
}
if 'step' in val:
param['step'] = val['step']
params.append(param)
entry = {
"category": category,
"params": params if params else []
}
if params:
shaders_with_params += 1
output[shader_id] = entry
# Handle object format (standard)
elif isinstance(data, dict):
shader_id = data.get('id')
category = data.get('category')
params = data.get('params', [])
if not shader_id:
continue
categories.add(category)
# Build entry
entry = {
"category": category,
"params": params if params else []
}
if params:
shaders_with_params += 1
output[shader_id] = entry
except Exception as e:
print(f"Error processing {json_file}: {e}")
continue
# Save consolidated output
with open("/root/image_video_effects/shader_params_extracted.json", 'w') as f:
json.dump(output, f, indent=2)
# Generate report
report = f"""# Shader Parameters Extraction Report
## Summary Statistics
| Metric | Value |
|--------|-------|
| Total JSON files found | {total_files} |
| Total shaders extracted | {len(output)} |
| Shaders with params | {shaders_with_params} |
| Categories covered | {len(categories)} |
## Categories
"""
# Count shaders per category
category_counts = defaultdict(int)
category_with_params = defaultdict(int)
for shader_id, data in output.items():
cat = data['category']
category_counts[cat] += 1
if data['params']:
category_with_params[cat] += 1
for cat in sorted(categories):
report += f"- **{cat}**: {category_counts[cat]} shaders ({category_with_params[cat]} with params)\\n"
# Sample of extracted data
report += """
## Sample Extracted Data
```json
{
"""
# Show first 3 shaders with params as examples
examples = [(k, v) for k, v in output.items() if v['params']][:3]
for i, (shader_id, data) in enumerate(examples):
report += f''' "{shader_id}": {{
"category": "{data['category']}",
"params": {json.dumps(data['params'], indent=4)}
}}'''
if i < len(examples) - 1:
report += ",\n"
report += """
}
```
## Parameter Schema
Each parameter object contains:
- `id`: Parameter identifier (string)
- `name`: Display name (string)
- `default`: Default value (number)
- `min`: Minimum value (number)
- `max`: Maximum value (number)
- `step`: Step increment (number, optional)
- `mapping`: WGSL uniform mapping (string, optional)
- `description`: Parameter description (string, optional)
## Output File
Extracted data saved to: `shader_params_extracted.json`
"""
with open("/root/image_video_effects/extraction_report.md", 'w') as f:
f.write(report)
print(f"Extraction complete!")
print(f"Total JSON files: {total_files}")
print(f"Total shaders: {len(output)}")
print(f"Shaders with params: {shaders_with_params}")
print(f"Categories: {len(categories)}")
if __name__ == "__main__":
extract_params()