Skip to content

Commit 47118cd

Browse files
Simplify animation keyframes
1 parent c1cf006 commit 47118cd

2 files changed

Lines changed: 75 additions & 77 deletions

File tree

Cycles/SFR_Benchmark_cy.py

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,19 @@ class SFR_Benchmark_cy(Operator):
1212
bl_label = "Frame Benchmark"
1313
bl_description = "Tests your scene to detect the best optimization settings."
1414

15+
insert_keyframes: bpy.props.BoolProperty(
16+
name="Insert keyframes",
17+
description="Inserts keyframes for each property to the current frame (used for benchmarking animations)",
18+
default=False,
19+
options=set(), # Not animatable!
20+
)
21+
1522
@classmethod
16-
def poll(cls, context):
23+
def poll(cls, context: Context):
1724
if not dependencies.checked or dependencies.needs_install:
1825
dependencies.check_dependencies()
1926

20-
return not dependencies.needs_install
27+
return context.scene.render.engine == 'CYCLES' and not dependencies.needs_install
2128

2229
def execute(self, context: Context):
2330

@@ -28,8 +35,8 @@ def execute(self, context: Context):
2835
scene = context.scene
2936
cycles = scene.cycles
3037
settings: SFR_Settings = scene.sfr_settings
38+
keyframe_insert = scene.keyframe_insert
3139

32-
# return {'FINISHED'}
3340
prefs = context.preferences.addons['cycles'].preferences
3441

3542
for device_type in prefs.get_device_types(context):
@@ -76,6 +83,25 @@ def execute(self, context: Context):
7683
cycles.volume_preview_step_rate = 5
7784
cycles.volume_max_steps = 256
7885

86+
if self.insert_keyframes:
87+
keyframe_insert('cycles.max_bounces')
88+
if settings.use_diffuse:
89+
keyframe_insert('cycles.diffuse_bounces')
90+
if settings.use_glossy:
91+
keyframe_insert('cycles.glossy_bounces')
92+
if settings.use_transmission:
93+
keyframe_insert('cycles.transmission_bounces')
94+
if settings.use_transparent:
95+
keyframe_insert('cycles.transparent_max_bounces')
96+
if settings.use_volume:
97+
keyframe_insert('cycles.volume_bounces')
98+
if settings.use_indirect:
99+
keyframe_insert('cycles.sample_clamp_indirect')
100+
if settings.use_caustics:
101+
keyframe_insert('cycles.blur_glossy')
102+
keyframe_insert('cycles.caustics_reflective')
103+
keyframe_insert('cycles.caustics_refractive')
104+
79105
# simplfy the scene
80106
scene.render.use_simplify = True
81107
# viewport
@@ -124,13 +150,17 @@ def execute(self, context: Context):
124150
# set settings
125151
print("Diffuse Bounces Pre: ", cycles.diffuse_bounces)
126152
cycles.diffuse_bounces += 1
153+
if self.insert_keyframes:
154+
keyframe_insert('cycles.diffuse_bounces')
127155
# set next
128156
iteration += 1
129157
print("Diffuse Iteration: ", iteration)
130158
# start second render
131159
repeat = TestRender(path, iteration, settings)
132160
print("Diffuse Bounces Post: ", cycles.diffuse_bounces)
133161
cycles.diffuse_bounces -= 1
162+
if self.insert_keyframes:
163+
keyframe_insert('cycles.diffuse_bounces')
134164
print("Diffuse Bounces Final: ", cycles.diffuse_bounces)
135165

136166
### GLOSS1 ###
@@ -142,12 +172,16 @@ def execute(self, context: Context):
142172
while repeat:
143173
# set settings
144174
cycles.glossy_bounces += 1
175+
if self.insert_keyframes:
176+
keyframe_insert('cycles.glossy_bounces')
145177
# set next
146178
iteration += 1
147179
print("Glossy Iteration: ", iteration)
148180
# start second render
149181
repeat = TestRender(path, iteration, settings)
150182
cycles.glossy_bounces -= 1
183+
if self.insert_keyframes:
184+
keyframe_insert('cycles.glossy_bounces')
151185

152186
### TRANSMISSION1 ###
153187
if settings.use_transmission:
@@ -158,12 +192,16 @@ def execute(self, context: Context):
158192
while repeat:
159193
# set settings
160194
cycles.transmission_bounces += 1
195+
if self.insert_keyframes:
196+
keyframe_insert('cycles.transmission_bounces')
161197
# set next
162198
iteration += 1
163199
print("Transmission Iteration: ", iteration)
164200
# start second render
165201
repeat = TestRender(path, iteration, settings)
166202
cycles.transmission_bounces -= 1
203+
if self.insert_keyframes:
204+
keyframe_insert('cycles.transmission_bounces')
167205

168206
### GLOSS2 ###
169207
if settings.use_transmission and settings.use_glossy:
@@ -174,12 +212,16 @@ def execute(self, context: Context):
174212
while repeat:
175213
# set settings
176214
cycles.glossy_bounces += 1
215+
if self.insert_keyframes:
216+
keyframe_insert('cycles.glossy_bounces')
177217
# set next
178218
iteration += 1
179219
print("Glossy2 Iteration: ", iteration)
180220
# start second render
181221
repeat = TestRender(path, iteration, settings)
182222
cycles.glossy_bounces -= 1
223+
if self.insert_keyframes:
224+
keyframe_insert('cycles.glossy_bounces')
183225

184226
### TRANSMISSION2 ###
185227
if settings.use_transmission and settings.use_glossy:
@@ -190,12 +232,16 @@ def execute(self, context: Context):
190232
while repeat:
191233
# set settings
192234
cycles.transmission_bounces += 1
235+
if self.insert_keyframes:
236+
keyframe_insert('cycles.transmission_bounces')
193237
# set next
194238
iteration += 1
195239
print("Transmission2 Iteration: ", iteration)
196240
# start second render
197241
repeat = TestRender(path, iteration, settings)
198242
cycles.transmission_bounces -= 1
243+
if self.insert_keyframes:
244+
keyframe_insert('cycles.transmission_bounces')
199245

200246
### TRANSPARENT ###
201247
if settings.use_transparent:
@@ -206,12 +252,16 @@ def execute(self, context: Context):
206252
while repeat:
207253
# set settings
208254
cycles.transparent_max_bounces += 1
255+
if self.insert_keyframes:
256+
keyframe_insert('cycles.transparent_max_bounces')
209257
# set next
210258
iteration += 1
211259
print("Transparent Iteration: ", iteration)
212260
# start second render
213261
repeat = TestRender(path, iteration, settings)
214262
cycles.transparent_max_bounces -= 1
263+
if self.insert_keyframes:
264+
keyframe_insert('cycles.transparent_max_bounces')
215265

216266
### VOLUME ###
217267
if settings.use_volume:
@@ -222,12 +272,16 @@ def execute(self, context: Context):
222272
while repeat:
223273
# set settings
224274
cycles.volume_bounces += 1
275+
if self.insert_keyframes:
276+
keyframe_insert('cycles.volume_bounces')
225277
# set next
226278
iteration += 1
227279
print("Volume Iteration: ", iteration)
228280
# start second render
229281
repeat = TestRender(path, iteration, settings)
230282
cycles.volume_bounces -= 1
283+
if self.insert_keyframes:
284+
keyframe_insert('cycles.volume_bounces')
231285

232286
### INDIRECT ###
233287
if settings.use_indirect:
@@ -238,12 +292,16 @@ def execute(self, context: Context):
238292
while repeat:
239293
# set settings
240294
cycles.sample_clamp_indirect += 1
295+
if self.insert_keyframes:
296+
keyframe_insert('cycles.sample_clamp_indirect')
241297
# set next
242298
iteration += 1
243299
print("Indirect Clamp Iteration: ", iteration)
244300
# start second render
245301
repeat = TestRender(path, iteration, settings)
246302
cycles.sample_clamp_indirect -= 1
303+
if self.insert_keyframes:
304+
keyframe_insert('cycles.sample_clamp_indirect')
247305

248306
### CAUSTIC BLUR ###
249307
if settings.use_caustics:
@@ -253,12 +311,16 @@ def execute(self, context: Context):
253311
while repeat:
254312
# set settings
255313
cycles.blur_glossy += 1
314+
if self.insert_keyframes:
315+
keyframe_insert('cycles.blur_glossy')
256316
# set next
257317
iteration += 1
258318
print("Caustic Blur Iteration: ", iteration)
259319
# start second render
260320
repeat = TestRender(path, iteration, settings)
261321
cycles.blur_glossy -= 1
322+
if self.insert_keyframes:
323+
keyframe_insert('cycles.blur_glossy')
262324

263325
### CAUSTIC REFL ###
264326
# start first render
@@ -287,6 +349,8 @@ def execute(self, context: Context):
287349

288350
### TOTAL ###
289351
cycles.max_bounces = cycles.diffuse_bounces + cycles.glossy_bounces + cycles.transmission_bounces + cycles.volume_bounces
352+
if self.insert_keyframes:
353+
keyframe_insert('cycles.max_bounces')
290354

291355
self.report({'INFO'}, "Benchmark complete")
292356

Utils/SFR_AnimationBenchmark.py

Lines changed: 8 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -9,92 +9,26 @@ class SFR_AnimationBenchmark(Operator):
99
bl_label = "Animation Benchmark"
1010
bl_description = "Benchmarks for animations"
1111

12+
@classmethod
13+
def poll(cls, context: Context):
14+
return context.scene.render.engine == 'CYCLES'
15+
1216
def execute(self, context: Context):
1317

1418
scene = context.scene
1519
settings: SFR_Settings = scene.sfr_settings
16-
keyframe_insert = context.window.scene.keyframe_insert
17-
frame_current = scene.frame_current
20+
1821
frame_start = scene.frame_start
1922
frame_end = scene.frame_end
2023

21-
frame_skipped = settings.frame_skipped
22-
23-
max_bounces = []
24-
diffuse_bounces = []
25-
glossy_bounces = []
26-
transmission_bounces = []
27-
transparent_bounces = []
28-
volume_bounces = []
29-
clamp_indirect = []
30-
caustic_blur = []
31-
vol_steps = []
24+
frame_step = settings.frame_skipped
3225

3326
if scene.render.engine == 'CYCLES':
34-
35-
cycles = scene.cycles
36-
37-
for frame_current in range(frame_start, frame_end, frame_skipped):
38-
27+
for frame_current in range(frame_start, frame_end, frame_step):
3928
scene.frame_current = frame_current
4029

4130
# start benchmark
42-
bpy.ops.render.superfastrender_benchmark()
43-
44-
max_bounces.append(cycles.max_bounces)
45-
diffuse_bounces.append(cycles.diffuse_bounces)
46-
glossy_bounces.append(cycles.glossy_bounces)
47-
transmission_bounces.append(cycles.transmission_bounces)
48-
transparent_bounces.append(cycles.transparent_max_bounces)
49-
volume_bounces.append(cycles.volume_bounces)
50-
clamp_indirect.append(cycles.sample_clamp_indirect)
51-
caustic_blur.append(cycles.blur_glossy)
52-
vol_steps.append(cycles.volume_max_steps)
53-
54-
for frame_current in range(frame_start, frame_end, frame_skipped):
55-
56-
# key max bounces
57-
cycles.max_bounces = max_bounces[0]
58-
del max_bounces[0]
59-
keyframe_insert('cycles.max_bounces', frame=frame_current)
60-
61-
if settings.use_diffuse:
62-
cycles.diffuse_bounces = diffuse_bounces[0]
63-
del diffuse_bounces[0]
64-
keyframe_insert('cycles.diffuse_bounces', frame=frame_current)
65-
66-
if settings.use_glossy:
67-
cycles.glossy_bounces = glossy_bounces[0]
68-
del glossy_bounces[0]
69-
keyframe_insert('cycles.glossy_bounces', frame=frame_current)
70-
71-
if settings.use_transparent:
72-
cycles.transparent_max_bounces = transparent_bounces[0]
73-
del transparent_bounces[0]
74-
keyframe_insert('cycles.transparent_max_bounces', frame=frame_current)
75-
76-
if settings.use_transmission:
77-
cycles.transmission_bounces = transmission_bounces[0]
78-
del transmission_bounces[0]
79-
keyframe_insert('cycles.transmission_bounces', frame=frame_current)
80-
81-
if settings.use_indirect:
82-
cycles.sample_clamp_indirect = clamp_indirect[0]
83-
del clamp_indirect[0]
84-
keyframe_insert('cycles.sample_clamp_indirect', frame=frame_current)
85-
86-
if settings.use_caustics:
87-
cycles.blur_glossy = caustic_blur[0]
88-
del caustic_blur[0]
89-
keyframe_insert('cycles.blur_glossy', frame=frame_current)
90-
91-
if settings.use_volume:
92-
cycles.volume_bounces = volume_bounces[0]
93-
del volume_bounces[0]
94-
cycles.volume_max_steps = vol_steps[0]
95-
del vol_steps[0]
96-
keyframe_insert('cycles.volume_bounces', frame=frame_current)
97-
keyframe_insert('cycles.volume_max_steps', frame=frame_current)
31+
bpy.ops.render.superfastrender_benchmark('EXEC_DEFAULT', insert_keyframes=True)
9832

9933
else:
10034
self.report({'WARNING'}, "Current render engine is not supported")

0 commit comments

Comments
 (0)