Skip to content

Commit

Permalink
Separate control map debug view into base/overlay textures view, and …
Browse files Browse the repository at this point in the history
…blend values view
  • Loading branch information
TokisanGames committed Nov 3, 2023
1 parent 86186e2 commit 1c9b249
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 20 deletions.
33 changes: 27 additions & 6 deletions src/shaders/debug_views.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,31 @@ R"(
ROUGHNESS = 0.7;
NORMAL_MAP = vec3(0.5, 0.5, 1.0);

//INSERT: DEBUG_CONTROLMAP
// Show control map
ALBEDO = vec3(float(mat[0].base)/32., float(mat[0].over)/32., float(mat[0].blend)/8.);
ROUGHNESS = 0.7;
//INSERT: DEBUG_CONTROL_TEXTURE
// Show control map texture selection
float ctrl_base = weight_inv * (
float(mat[0].base)/32. * weights.x +
float(mat[1].base)/32. * weights.y +
float(mat[2].base)/32. * weights.z +
float(mat[3].base)/32. * weights.w );
float ctrl_over = weight_inv * (
float(mat[0].over)/32. * weights.x +
float(mat[1].over)/32. * weights.y +
float(mat[2].over)/32. * weights.z +
float(mat[3].over)/32. * weights.w );
ALBEDO = vec3(ctrl_base, ctrl_over, 0.);
ROUGHNESS = 0.9;
NORMAL_MAP = vec3(0.5, 0.5, 1.0);

//INSERT: DEBUG_CONTROL_BLEND
// Show control map blend values
float ctrl_blend = weight_inv * (
float(mat[0].blend) * weights.x +
float(mat[1].blend) * weights.y +
float(mat[2].blend) * weights.z +
float(mat[3].blend) * weights.w );
ALBEDO = vec3(ctrl_blend/8.);
ROUGHNESS = 1.0;
NORMAL_MAP = vec3(0.5, 0.5, 1.0);

//INSERT: DEBUG_TEXTURE_HEIGHT
Expand Down Expand Up @@ -84,8 +105,8 @@ R"(
}

// Draw Vertices
if ( mod(UV.x*2. + _grid_line*_vertex_size*.5, _grid_step) < _grid_line*_vertex_size &&
mod(UV.y*2. + _grid_line*_vertex_size*.5, _grid_step) < _grid_line*_vertex_size ) {
if ( mod(UV.x + _grid_line*_vertex_size*.5, _grid_step) < _grid_line*_vertex_size &&
mod(UV.y + _grid_line*_vertex_size*.5, _grid_step) < _grid_line*_vertex_size ) {
ALBEDO += vec3(0.15);
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/shaders/main.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ void fragment() {
vec2 weights1 = clamp(texel_pos - texel_pos_floor, 0, 1);
weights1 = mix(weights1, vec2(1.0) - weights1, mirror.xy);
vec2 weights0 = vec2(1.0) - weights1;
// Then adjust the weights based upon the texture height
vec4 weights;
weights.x = blend_weights(weights0.x * weights0.y, mat[0].alb_ht.a);
weights.y = blend_weights(weights0.x * weights1.y, mat[1].alb_ht.a);
Expand Down Expand Up @@ -282,7 +283,8 @@ void fragment() {
//INSERT: DEBUG_HEIGHTMAP
//INSERT: DEBUG_COLORMAP
//INSERT: DEBUG_ROUGHMAP
//INSERT: DEBUG_CONTROLMAP
//INSERT: DEBUG_CONTROL_TEXTURE
//INSERT: DEBUG_CONTROL_BLEND
//INSERT: DEBUG_TEXTURE_HEIGHT
//INSERT: DEBUG_TEXTURE_NORMAL
//INSERT: DEBUG_TEXTURE_ROUGHNESS
Expand Down
32 changes: 22 additions & 10 deletions src/terrain_3d_material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ String Terrain3DMaterial::_parse_shader(String p_shader, String p_name, Array p_
// Process the insert
if (!p_name.is_empty()) {
// Load mode
if (!id.is_empty()) {
if (!id.is_empty() && !segment[1].is_empty()) {
_shader_code[id] = segment[1];
}
} else {
// Apply mode
if (!id.is_empty() && !p_excludes.has(id)) {
if (!id.is_empty() && !p_excludes.has(id) && _shader_code.has(id)) {
String str = _shader_code[id];
shader += str;
}
Expand Down Expand Up @@ -117,8 +117,11 @@ String Terrain3DMaterial::_generate_shader_code() {
if (!_debug_view_tex_rough) {
excludes.push_back("DEBUG_TEXTURE_ROUGHNESS");
}
if (!_debug_view_controlmap) {
excludes.push_back("DEBUG_CONTROLMAP");
if (!_debug_view_control_texture) {
excludes.push_back("DEBUG_CONTROL_TEXTURE");
}
if (!_debug_view_control_blend) {
excludes.push_back("DEBUG_CONTROL_BLEND");
}
if (!_debug_view_vertex_grid) {
excludes.push_back("DEBUG_VERTEX_GRID");
Expand Down Expand Up @@ -436,9 +439,15 @@ void Terrain3DMaterial::set_show_roughmap(bool p_enabled) {
_update_shader();
}

void Terrain3DMaterial::set_show_controlmap(bool p_enabled) {
LOG(INFO, "Enable show_controlmap: ", p_enabled);
_debug_view_controlmap = p_enabled;
void Terrain3DMaterial::set_show_control_texture(bool p_enabled) {
LOG(INFO, "Enable show_control_texture: ", p_enabled);
_debug_view_control_texture = p_enabled;
_update_shader();
}

void Terrain3DMaterial::set_show_control_blend(bool p_enabled) {
LOG(INFO, "Enable show_control_blend: ", p_enabled);
_debug_view_control_blend = p_enabled;
_update_shader();
}

Expand Down Expand Up @@ -639,8 +648,10 @@ void Terrain3DMaterial::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_show_colormap"), &Terrain3DMaterial::get_show_colormap);
ClassDB::bind_method(D_METHOD("set_show_roughmap", "enabled"), &Terrain3DMaterial::set_show_roughmap);
ClassDB::bind_method(D_METHOD("get_show_roughmap"), &Terrain3DMaterial::get_show_roughmap);
ClassDB::bind_method(D_METHOD("set_show_controlmap", "enabled"), &Terrain3DMaterial::set_show_controlmap);
ClassDB::bind_method(D_METHOD("get_show_controlmap"), &Terrain3DMaterial::get_show_controlmap);
ClassDB::bind_method(D_METHOD("set_show_control_texture", "enabled"), &Terrain3DMaterial::set_show_control_texture);
ClassDB::bind_method(D_METHOD("get_show_control_texture"), &Terrain3DMaterial::get_show_control_texture);
ClassDB::bind_method(D_METHOD("set_show_control_blend", "enabled"), &Terrain3DMaterial::set_show_control_blend);
ClassDB::bind_method(D_METHOD("get_show_control_blend"), &Terrain3DMaterial::get_show_control_blend);
ClassDB::bind_method(D_METHOD("set_show_texture_height", "enabled"), &Terrain3DMaterial::set_show_texture_height);
ClassDB::bind_method(D_METHOD("get_show_texture_height"), &Terrain3DMaterial::get_show_texture_height);
ClassDB::bind_method(D_METHOD("set_show_texture_normal", "enabled"), &Terrain3DMaterial::set_show_texture_normal);
Expand All @@ -660,7 +671,8 @@ void Terrain3DMaterial::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_heightmap", PROPERTY_HINT_NONE), "set_show_heightmap", "get_show_heightmap");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_colormap", PROPERTY_HINT_NONE), "set_show_colormap", "get_show_colormap");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_roughmap", PROPERTY_HINT_NONE), "set_show_roughmap", "get_show_roughmap");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_controlmap", PROPERTY_HINT_NONE), "set_show_controlmap", "get_show_controlmap");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_control_texture", PROPERTY_HINT_NONE), "set_show_control_texture", "get_show_control_texture");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_control_blend", PROPERTY_HINT_NONE), "set_show_control_blend", "get_show_control_blend");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_texture_height", PROPERTY_HINT_NONE), "set_show_texture_height", "get_show_texture_height");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_texture_normal", PROPERTY_HINT_NONE), "set_show_texture_normal", "get_show_texture_normal");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_texture_rough", PROPERTY_HINT_NONE), "set_show_texture_rough", "get_show_texture_rough");
Expand Down
9 changes: 6 additions & 3 deletions src/terrain_3d_material.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class Terrain3DMaterial : public Resource {
bool _debug_view_heightmap = false;
bool _debug_view_colormap = false;
bool _debug_view_roughmap = false;
bool _debug_view_controlmap = false;
bool _debug_view_control_texture = false;
bool _debug_view_control_blend = false;
bool _debug_view_tex_height = false;
bool _debug_view_tex_normal = false;
bool _debug_view_tex_rough = false;
Expand Down Expand Up @@ -88,8 +89,10 @@ class Terrain3DMaterial : public Resource {
bool get_show_colormap() const { return _debug_view_colormap; }
void set_show_roughmap(bool p_enabled);
bool get_show_roughmap() const { return _debug_view_roughmap; }
void set_show_controlmap(bool p_enabled);
bool get_show_controlmap() const { return _debug_view_controlmap; }
void set_show_control_texture(bool p_enabled);
bool get_show_control_texture() const { return _debug_view_control_texture; }
void set_show_control_blend(bool p_enabled);
bool get_show_control_blend() const { return _debug_view_control_blend; }
void set_show_texture_height(bool p_enabled);
bool get_show_texture_height() const { return _debug_view_tex_height; }
void set_show_texture_normal(bool p_enabled);
Expand Down

0 comments on commit 1c9b249

Please sign in to comment.