From 4fdc46460d7d858e87de2256005db1a9c802f661 Mon Sep 17 00:00:00 2001 From: akaneyu Date: Sun, 7 Dec 2025 11:51:18 +0900 Subject: [PATCH] Support Blender 5.0 --- addon/__init__.py | 4 +- addon/ui_renderer.py | 90 +++++++++++++++++++++----------------------- 2 files changed, 44 insertions(+), 50 deletions(-) diff --git a/addon/__init__.py b/addon/__init__.py index 58cb972..6c5e09e 100644 --- a/addon/__init__.py +++ b/addon/__init__.py @@ -18,8 +18,8 @@ bl_info = { "name": "Image Editor Plus", "author": "akaneyu", - "version": (1, 10, 0), - "blender": (3, 3, 0), + "version": (1, 11, 0), + "blender": (4, 2, 0), "location": "Image", "warning": "", "description": "", diff --git a/addon/ui_renderer.py b/addon/ui_renderer.py index d02d254..04a6882 100644 --- a/addon/ui_renderer.py +++ b/addon/ui_renderer.py @@ -1,5 +1,5 @@ ''' - Copyright (C) 2020 - 2024 Akaneyu + Copyright (C) 2020 - 2025 Akaneyu 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 @@ -18,15 +18,12 @@ import sys import math import gpu +from gpu.shader import create_from_info from gpu_extras.batch import batch_for_shader from mathutils import Matrix, Vector import numpy as np default_vertex_shader = ''' -uniform mat4 ModelViewProjectionMatrix; - -in vec2 pos; - void main() { gl_Position = ModelViewProjectionMatrix * vec4(pos, 0, 1.0); @@ -34,10 +31,6 @@ void main() ''' default_fragment_shader = ''' -uniform vec4 color; - -out vec4 fragColor; - void main() { fragColor = color; @@ -45,34 +38,18 @@ void main() ''' dotted_line_vertex_shader = ''' -uniform mat4 ModelViewProjectionMatrix; - -in vec2 pos; -in float arcLength; - -out float arcLengthOut; - void main() { - arcLengthOut = arcLength; + arcLengthInter = arcLength; gl_Position = ModelViewProjectionMatrix * vec4(pos, 0, 1.0); } ''' dotted_line_fragment_shader = ''' -uniform float scale; -uniform float offset; -uniform vec4 color1; -uniform vec4 color2; - -in float arcLengthOut; - -out vec4 fragColor; - void main() { - if (step(sin((arcLengthOut + offset) * scale), 0.5) == 1) { + if (step(sin((arcLengthInter + offset) * scale), 0.5) == 1) { fragColor = color1; } else { fragColor = color2; @@ -81,13 +58,6 @@ void main() ''' image_vertex_shader = ''' -uniform mat4 ModelViewProjectionMatrix; - -in vec2 pos; -in vec2 texCoord; - -out vec2 texCoordOut; - void main() { gl_Position = ModelViewProjectionMatrix * vec4(pos, 0, 1.0); @@ -96,12 +66,6 @@ void main() ''' image_fragment_shader = ''' -uniform sampler2D image; - -in vec2 texCoordOut; - -out vec4 fragColor; - void main() { fragColor = texture(image, texCoordOut); @@ -118,18 +82,48 @@ def make_scale_matrix(scale): class UIRenderer: def __init__(self): - self.default_shader = gpu.types.GPUShader(default_vertex_shader, - default_fragment_shader) - self.default_shader_u_color = self.default_shader.uniform_from_name("color") + default_shader_info = gpu.types.GPUShaderCreateInfo() + default_shader_info.push_constant('MAT4', 'ModelViewProjectionMatrix') + default_shader_info.push_constant('VEC4', 'color') + default_shader_info.vertex_in(0, 'VEC2', 'pos') + default_shader_info.fragment_out(0, 'VEC4', 'fragColor') + default_shader_info.vertex_source(default_vertex_shader) + default_shader_info.fragment_source(default_fragment_shader) + self.default_shader = create_from_info(default_shader_info) + self.default_shader_u_color = self.default_shader.uniform_from_name('color') - self.dotted_line_shader = gpu.types.GPUShader(dotted_line_vertex_shader, - dotted_line_fragment_shader) + dotted_line_shader_inter = gpu.types.GPUStageInterfaceInfo("dotted_line") + dotted_line_shader_inter.smooth('FLOAT', "arcLengthInter") + + dotted_line_shader_info = gpu.types.GPUShaderCreateInfo() + dotted_line_shader_info.push_constant('MAT4', 'ModelViewProjectionMatrix') + dotted_line_shader_info.push_constant('FLOAT', 'scale') + dotted_line_shader_info.push_constant('FLOAT', 'offset') + dotted_line_shader_info.push_constant('VEC4', 'color1') + dotted_line_shader_info.push_constant('VEC4', 'color2') + dotted_line_shader_info.vertex_in(0, 'VEC2', 'pos') + dotted_line_shader_info.vertex_in(1, 'FLOAT', 'arcLength') + dotted_line_shader_info.vertex_out(dotted_line_shader_inter) + dotted_line_shader_info.fragment_out(0, 'VEC4', 'fragColor') + dotted_line_shader_info.vertex_source(dotted_line_vertex_shader) + dotted_line_shader_info.fragment_source(dotted_line_fragment_shader) + self.dotted_line_shader = create_from_info(dotted_line_shader_info) self.dotted_line_shader_u_color1 = self.dotted_line_shader.uniform_from_name("color1") self.dotted_line_shader_u_color2 = self.dotted_line_shader.uniform_from_name("color2") - #self.image_shader = gpu.shader.from_builtin('2D_IMAGE') - self.image_shader = gpu.types.GPUShader(image_vertex_shader, - image_fragment_shader) + image_shader_inter = gpu.types.GPUStageInterfaceInfo("image_shader") + image_shader_inter.smooth('VEC2', "texCoordOut") + + image_shader_info = gpu.types.GPUShaderCreateInfo() + image_shader_info.push_constant('MAT4', 'ModelViewProjectionMatrix') + image_shader_info.sampler(0, 'FLOAT_2D', 'image') + image_shader_info.vertex_in(0, 'VEC2', 'pos') + image_shader_info.vertex_in(1, 'VEC2', 'texCoord') + image_shader_info.vertex_out(image_shader_inter) + image_shader_info.fragment_out(0, 'VEC4', 'fragColor') + image_shader_info.vertex_source(image_vertex_shader) + image_shader_info.fragment_source(image_fragment_shader) + self.image_shader = create_from_info(image_shader_info) def render_selection_frame(self, pos, size, rot=0, scale=(1.0, 1.0)): width, height = size[0], size[1]