Skip to content

Commit a08d5db

Browse files
committed
wip insert search code only when none bg
1 parent d80c8e4 commit a08d5db

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

src/shaders/backgrounds.glsl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright © 2025 Cory Petkovsek, Roope Palmroos, and Contributors.
22

33
R"(
4+
//INSERT: NONE_BACKGROUND
5+
#define BG_MODE_NONE
46
//INSERT: FLAT_UNIFORMS
57
uniform float ground_level : hint_range(-1000., 1000.) = 0.0;
68
uniform float region_blend : hint_range(.001, 1., 0.001) = 0.25;

src/shaders/main.glsl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ render_mode blend_mix, depth_draw_opaque, cull_back, diffuse_burley, specular_sc
2727
#define DIV_255 0.003921568627450 // 1. / 255.
2828
#define DIV_1024 0.0009765625 // 1. / 1024.
2929
#define TAU_16TH -0.392699081698724 // -TAU / 16.
30+
//INSERT: NONE_BACKGROUND
3031

3132
// Inline Functions
3233
#define DECODE_BLEND(control) float(control >>14u & 0xFFu) * DIV_255
@@ -120,6 +121,7 @@ varying vec3 v_camera_pos;
120121
// Z: layer index used for texturearrays, -1 if not in a region
121122
ivec3 get_index_coord(const vec2 uv, const int search) {
122123
vec2 r_uv = round(uv);
124+
#ifdef BG_MODE_NONE
123125
vec2 o_uv = mod(r_uv, _region_size);
124126
ivec2 pos;
125127
int bounds, layer_index = -1;
@@ -131,6 +133,11 @@ ivec3 get_index_coord(const vec2 uv, const int search) {
131133
layer_index = (_region_map[ pos.y * _region_map_size + pos.x ] * bounds - 1);
132134
}
133135
}
136+
#else
137+
ivec2 pos = ivec2(floor(r_uv * _region_texel_size)) + (_region_map_size / 2);
138+
int bounds = int(uint(pos.x | pos.y) < uint(_region_map_size));
139+
int layer_index = _region_map[pos.y * _region_map_size + pos.x] * bounds - 1;
140+
#endif
134141
return ivec3(ivec2(mod(r_uv, _region_size)), layer_index);
135142
}
136143

src/terrain_3d_material.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ String Terrain3DMaterial::_apply_inserts(const String &p_shader, const Array &p_
139139
String Terrain3DMaterial::_generate_shader_code() const {
140140
LOG(INFO, "Generating default shader code");
141141
Array excludes;
142+
if (_world_background != NONE) {
143+
excludes.push_back("NONE_BACKGROUND");
144+
}
142145
if (_world_background != FLAT) {
143146
excludes.push_back("FLAT_UNIFORMS");
144147
excludes.push_back("FLAT_FUNCTIONS");

0 commit comments

Comments
 (0)