Skip to content

Commit

Permalink
Added a setting to disable the fog effect
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitriySalnikov committed Jun 30, 2024
1 parent de376af commit d6766cd
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 7 deletions.
4 changes: 4 additions & 0 deletions examples_dd3d/DebugDrawDemoScene.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ sky_material = SubResource("ProceduralSkyMaterial_87638")
[sub_resource type="Environment" id="Environment_38m85"]
sky = SubResource("Sky_4jfme")
tonemap_mode = 2
fog_light_energy = 0.41
fog_density = 0.0757
fog_height = 0.5
fog_height_density = 4.6102

[sub_resource type="Animation" id="9"]
resource_name = "New Anim"
Expand Down
11 changes: 9 additions & 2 deletions src/3d/debug_draw_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const char *DebugDraw3D::s_default_plane_size = "volumetric_defaults/plane_size"

const char *DebugDraw3D::s_render_priority = "rendering/render_priority";
const char *DebugDraw3D::s_render_mode = "rendering/render_mode";
const char *DebugDraw3D::s_render_fog_disabled = "rendering/disable_fog";

void DebugDraw3D::_bind_methods() {
#define REG_CLASS_NAME DebugDraw3D
Expand Down Expand Up @@ -150,13 +151,14 @@ void DebugDraw3D::init(DebugDrawManager *p_root) {
DEFINE_SETTING(root_settings_section + s_use_icosphere_hd, true, Variant::BOOL);
DEFINE_SETTING_AND_GET_HINT(real_t def_frustum_scale, root_settings_section + s_default_frustum_scale, 0.5f, Variant::FLOAT, PROPERTY_HINT_RANGE, "0,1,0.0001");

DEFINE_SETTING_AND_GET_HINT(real_t def_thickness, root_settings_section + s_default_thickness, 0.05f, Variant::FLOAT, PROPERTY_HINT_RANGE, "0,100,0.0001");
DEFINE_SETTING_AND_GET_HINT(real_t def_thickness, root_settings_section + s_default_thickness, 0.05f, Variant::FLOAT, PROPERTY_HINT_RANGE, "0,100,0.0001,or_greater");
DEFINE_SETTING_AND_GET_HINT(real_t def_brightness, root_settings_section + s_default_center_brightness, 0.8f, Variant::FLOAT, PROPERTY_HINT_RANGE, "0,1,0.0001");
DEFINE_SETTING_AND_GET(real_t def_hd_sphere, root_settings_section + s_default_hd_spheres, false, Variant::BOOL);
DEFINE_SETTING_AND_GET_HINT(real_t def_plane_size, root_settings_section + s_default_plane_size, 0, Variant::FLOAT, PROPERTY_HINT_RANGE, "0,10000,0.001");
DEFINE_SETTING_AND_GET_HINT(real_t def_plane_size, root_settings_section + s_default_plane_size, 0, Variant::FLOAT, PROPERTY_HINT_RANGE, "0,10000,0.001,or_greater");

DEFINE_SETTING(root_settings_section + s_render_priority, 0, Variant::INT);
DEFINE_SETTING_HINT(root_settings_section + s_render_mode, 0, Variant::INT, PROPERTY_HINT_ENUM, "Default,Forced Transparent,Forced Opaque");
DEFINE_SETTING(root_settings_section + s_render_fog_disabled, true, Variant::BOOL);

default_scoped_config.instantiate();

Expand Down Expand Up @@ -507,6 +509,7 @@ void DebugDraw3D::_load_materials() {

int render_priority = PS()->get_setting(root_settings_section + s_render_priority);
int render_mode = PS()->get_setting(root_settings_section + s_render_mode); // default, transparent, opaque
bool fog_disabled = PS()->get_setting(root_settings_section + s_render_fog_disabled);

for (int variant = 0; variant < (int)MeshMaterialVariant::MAX; variant++) {
String prefix = "";
Expand All @@ -524,6 +527,10 @@ void DebugDraw3D::_load_materials() {
break;
}

if (fog_disabled) {
prefix = "#define FOG_DISABLED\n";
}

LOAD_SHADER(mesh_shaders[(int)MeshMaterialType::Wireframe][variant], prefix + DD3DResources::src_resources_wireframe_unshaded_gdshader);
LOAD_SHADER(mesh_shaders[(int)MeshMaterialType::Billboard][variant], prefix + DD3DResources::src_resources_billboard_unshaded_gdshader);
LOAD_SHADER(mesh_shaders[(int)MeshMaterialType::Plane][variant], prefix + DD3DResources::src_resources_plane_unshaded_gdshader);
Expand Down
1 change: 1 addition & 0 deletions src/3d/debug_draw_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ class DebugDraw3D : public Object, public IScopeStorage<DebugDraw3DScopeConfig,

const static char *s_render_priority;
const static char *s_render_mode;
const static char *s_render_fog_disabled;

std::vector<SubViewport *> custom_editor_viewports;
DebugDrawManager *root_node = nullptr;
Expand Down
5 changes: 4 additions & 1 deletion src/resources/billboard_unshaded.gdshader
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@

shader_type spatial;
render_mode cull_back, shadows_disabled, unshaded
#if defined(FOG_DISABLED)
, fog_disabled
#endif
#if defined(NO_DEPTH)
,depth_test_disabled;
, depth_test_disabled;
#else
;
#endif
Expand Down
5 changes: 4 additions & 1 deletion src/resources/extendable_meshes.gdshader
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@

shader_type spatial;
render_mode cull_disabled, shadows_disabled, unshaded, world_vertex_coords
#if defined(FOG_DISABLED)
, fog_disabled
#endif
#if defined(NO_DEPTH)
,depth_test_disabled;
, depth_test_disabled;
#else
;
#endif
Expand Down
5 changes: 4 additions & 1 deletion src/resources/plane_unshaded.gdshader
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@

shader_type spatial;
render_mode cull_disabled, shadows_disabled, unshaded
#if defined(FOG_DISABLED)
, fog_disabled
#endif
#if defined(NO_DEPTH)
,depth_test_disabled;
, depth_test_disabled;
#else
;
#endif
Expand Down
5 changes: 4 additions & 1 deletion src/resources/wireframe_unshaded.gdshader
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@

shader_type spatial;
render_mode cull_disabled, shadows_disabled, unshaded
#if defined(FOG_DISABLED)
, fog_disabled
#endif
#if defined(NO_DEPTH)
,depth_test_disabled;
, depth_test_disabled;
#else
;
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#define DD3D_MAJOR 1
#define DD3D_MINOR 4
#define DD3D_PATCH 2
#define DD3D_PATCH 3
#define DD3D_VERSION ((DD3D_MAJOR << (8 * 3)) + (DD3D_MINOR << (8 * 2)) + (DD3D_PATCH << (8 * 1)))

#define _DD3D_VERSION_STR_TEXT(text) #text
Expand Down

0 comments on commit d6766cd

Please sign in to comment.