OverviewFilesCommitsIssuesDocsReleasesPeers

blender-bridge commits / 1d2249b

Add VT material factory create_vt_material() (v0.13.1)
VirtualTexture::create_vt_material() lazy-loads vt_lookup.gdshader, binds atlas + page table textures, and returns a ShaderMaterial with fallback albedo/roughness/metallic uniforms for when tiles aren't resident yet. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1d2249bd836af9f9dd52b5e072a393056f5b88b7
by plankatron <fleeky@gmail.com> · 2026-03-03T20:27:28.000Z

Changed files (5) +43 -3

blender_addon/__init__.py +1 -1
……@@ -11,7 +11,7 @@ Usage:
1111
1212import bpy
1313
14ADDON_VERSION = "0.13.0"
14ADDON_VERSION = "0.13.1"
1515
1616# Support hot-reload (F3 > Reload Scripts)
1717if "shm_protocol" in locals():
blender_addon/blender_manifest.toml +1 -1
……@@ -2,7 +2,7 @@ schema_version = "1.0.0"
22id = "blender_godot_bridge"
33name = "Blender-Godot Bridge"
44tagline = "Real-time bidirectional scene sync with Godot"
5version = "0.13.0"
5version = "0.13.1"
66blender_version_min = "4.2.0"
77type = "add-on"
88maintainer = "blender-bridge <noreply@localhost>"
src/blender_bridge.cpp +1 -1
……@@ -163,7 +163,7 @@ Error BlenderBridge::start_server(const String &socket_path) {
163163 _known_instance_ids.clear();
164164 _next_object_id = 1;
165165
166 UtilityFunctions::print("BlenderBridge v0.13.0: Server started (shm=", _shm_name, ", sock=", socket_path, ", regions=2x", (int)_region_size, ")");
166 UtilityFunctions::print("BlenderBridge v0.13.1: Server started (shm=", _shm_name, ", sock=", socket_path, ", regions=2x", (int)_region_size, ")");
167167 return OK;
168168}
169169
src/virtual_texture.cpp +30 -0
……@@ -3,6 +3,7 @@
33#include <godot_cpp/classes/image.hpp>
44#include <godot_cpp/classes/rd_texture_format.hpp>
55#include <godot_cpp/classes/rd_texture_view.hpp>
6#include <godot_cpp/classes/resource_loader.hpp>
67#include <godot_cpp/variant/utility_functions.hpp>
78
89using namespace godot;
……@@ -30,6 +31,9 @@ void VirtualTexture::_bind_methods() {
3031 ClassDB::bind_method(D_METHOD("get_atlas_texture"), &VirtualTexture::get_atlas_texture);
3132 ClassDB::bind_method(D_METHOD("get_page_table_texture"), &VirtualTexture::get_page_table_texture);
3233
34 // Material factory
35 ClassDB::bind_method(D_METHOD("create_vt_material", "fallback_albedo", "roughness", "metallic"), &VirtualTexture::create_vt_material);
36
3337 // Feedback
3438 ClassDB::bind_method(D_METHOD("submit_feedback", "feedback_data"), &VirtualTexture::submit_feedback);
3539
……@@ -140,6 +144,32 @@ Ref<Texture2DRD> VirtualTexture::get_page_table_texture() const {
140144 return _page_table_tex;
141145}
142146
147// ── Material factory ──────────────────────────────────────────────────────
148
149Ref<ShaderMaterial> VirtualTexture::create_vt_material(const Color &fallback, float rough, float metal) {
150 // Lazy-load the shader
151 if (!_shader_loaded) {
152 _vt_shader = ResourceLoader::get_singleton()->load("res://addons/blender_bridge/vt_lookup.gdshader");
153 _shader_loaded = true;
154 }
155 if (_vt_shader.is_null()) {
156 UtilityFunctions::push_warning("VirtualTexture: vt_lookup.gdshader not found at res://addons/blender_bridge/");
157 return Ref<ShaderMaterial>();
158 }
159
160 Ref<ShaderMaterial> mat;
161 mat.instantiate();
162 mat->set_shader(_vt_shader);
163 mat->set_shader_parameter("vt_atlas", _atlas_tex);
164 mat->set_shader_parameter("vt_page_table", _page_table_tex);
165 mat->set_shader_parameter("tile_size_uv", 1.0f / _cache_grid_size);
166 mat->set_shader_parameter("page_table_size", (float)_page_table.tiles_at_mip(0));
167 mat->set_shader_parameter("albedo_color", fallback);
168 mat->set_shader_parameter("roughness", rough);
169 mat->set_shader_parameter("metallic", metal);
170 return mat;
171}
172
143173// ── Tile upload ───────────────────────────────────────────────────────────────
144174
145175Error VirtualTexture::upload_tile(int texture_id, int tile_x, int tile_y, int mip, const PackedByteArray &rgba_data) {
src/virtual_texture.h +10 -0
……@@ -3,8 +3,11 @@
33#include <godot_cpp/classes/node.hpp>
44#include <godot_cpp/classes/rendering_device.hpp>
55#include <godot_cpp/classes/rendering_server.hpp>
6#include <godot_cpp/classes/shader.hpp>
7#include <godot_cpp/classes/shader_material.hpp>
68#include <godot_cpp/classes/texture2drd.hpp>
79#include <godot_cpp/core/class_db.hpp>
10#include <godot_cpp/variant/color.hpp>
811#include <godot_cpp/variant/dictionary.hpp>
912#include <godot_cpp/variant/packed_byte_array.hpp>
1013#include <godot_cpp/variant/rid.hpp>
……@@ -42,6 +45,9 @@ public:
4245 Ref<Texture2DRD> get_atlas_texture() const;
4346 Ref<Texture2DRD> get_page_table_texture() const;
4447
48 // ── Material factory ────────────────────────────────────────────────
49 Ref<ShaderMaterial> create_vt_material(const Color &fallback_albedo, float roughness, float metallic);
50
4551 // ── Configuration ───────────────────────────────────────────────────
4652 void set_tile_size(int size);
4753 int get_tile_size() const;
……@@ -102,6 +108,10 @@ private:
102108 Ref<Texture2DRD> _page_table_tex;
103109 bool _gpu_initialized = false;
104110
111 // ── Shader (lazy-loaded) ────────────────────────────────────────────
112 Ref<Shader> _vt_shader;
113 bool _shader_loaded = false;
114
105115 // ── Frame tracking ──────────────────────────────────────────────────
106116 uint64_t _frame_count = 0;
107117 int _tiles_uploaded_this_frame = 0;