Skip to content

Instantly share code, notes, and snippets.

@semagnum
Created January 13, 2024 17:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save semagnum/21be0304dc7fc7e2cfe6ae1a3990061c to your computer and use it in GitHub Desktop.
Save semagnum/21be0304dc7fc7e2cfe6ae1a3990061c to your computer and use it in GitHub Desktop.
Blender add-on containing shortcuts for Cycles render settings in the viewport.
# Viewport Shortcuts, Blender add-on that contains shortcuts of viewport render settings.
# Copyright (C) 2024 Spencer Magnusson
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import sys
import bpy
bl_info = {
'name': 'Viewport Shortcuts',
'author': 'Spencer Magnusson',
'version': (0, 0, 1),
'blender': (3, 6, 0),
'description': 'Viewport Shortcuts',
'location': 'View 3D N panel',
'support': 'COMMUNITY',
'category': '3D View',
'doc_url': '',
'tracker_url': '',
}
def _update_helper_category_name(self, _context):
panel_ids = ['VS_PT_Viewport_Shortcuts', 'VS_PT_Viewport_Shortcuts_Denoising']
for pid in panel_ids:
is_panel_registered = hasattr(bpy.types, pid)
if is_panel_registered:
try:
bpy.utils.unregister_class(getattr(bpy.types, pid))
except:
pass
mod = sys.modules[__name__]
for pid in panel_ids:
panel = getattr(mod, pid)
panel.bl_category = self.category_name
bpy.utils.register_class(panel)
class VS_Preferences(bpy.types.AddonPreferences):
bl_idname = 'viewport_shortcuts'
category_name: bpy.props.StringProperty(
name='Category',
description='Category the add-on panels will be listed under.',
default='Viewport Shortcuts',
update=_update_helper_category_name
)
"""Category the panel will be under."""
def draw(self, context):
"""Draws BLint preference properties and operators, including rule creation."""
layout = self.layout
layout.prop(self, 'category_name')
class VS_PT_Viewport_Shortcuts(bpy.types.Panel):
bl_space_type = 'VIEW_3D'
bl_label = 'Viewport Shortcuts'
bl_region_type = 'UI'
bl_category = 'Viewport Shortcuts'
def draw(self, context):
layout = self.layout
scene = context.scene
cscene = scene.cycles
layout.use_property_split = True
layout.use_property_decorate = False
heading = layout.column(align=True, heading="Noise Threshold")
row = heading.row(align=True)
row.prop(cscene, "use_preview_adaptive_sampling", text="")
sub = row.row()
sub.active = cscene.use_preview_adaptive_sampling
sub.prop(cscene, "preview_adaptive_threshold", text="")
if cscene.use_preview_adaptive_sampling:
col = layout.column(align=True)
col.prop(cscene, "preview_samples", text="Max Samples")
col.prop(cscene, "preview_adaptive_min_samples", text="Min Samples")
else:
layout.prop(cscene, "preview_samples", text="Samples")
def get_effective_preview_denoiser(context):
scene = context.scene
cscene = scene.cycles
if cscene.preview_denoiser != "AUTO":
return cscene.preview_denoiser
if context.preferences.addons['cycles'].preferences.get_devices_for_type('OPTIX'):
return 'OPTIX'
return 'OIDN'
class VS_PT_Viewport_Shortcuts_Denoising(bpy.types.Panel):
bl_label = "Denoise"
bl_parent_id = 'VS_PT_Viewport_Shortcuts'
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_options = {'DEFAULT_CLOSED'}
def draw_header(self, context):
self.layout.prop(context.scene.cycles, "use_preview_denoising", text="")
def draw(self, context):
layout = self.layout
layout.use_property_split = True
layout.use_property_decorate = False
scene = context.scene
cscene = scene.cycles
col = layout.column()
col.active = cscene.use_preview_denoising
col.prop(cscene, "preview_denoiser", text="Denoiser")
col.prop(cscene, "preview_denoising_input_passes", text="Passes")
effective_preview_denoiser = get_effective_preview_denoiser(context)
if effective_preview_denoiser == 'OPENIMAGEDENOISE':
col.prop(cscene, "preview_denoising_prefilter", text="Prefilter")
col.prop(cscene, "preview_denoising_start_sample", text="Start Sample")
classes_to_register = (VS_Preferences, VS_PT_Viewport_Shortcuts, VS_PT_Viewport_Shortcuts_Denoising)
register, unregister = bpy.utils.register_classes_factory(classes_to_register)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment