diff --git a/modules/vertex_lights_2d/SCsub b/modules/vertex_lights_2d/SCsub new file mode 100644 index 000000000..32429a9a2 --- /dev/null +++ b/modules/vertex_lights_2d/SCsub @@ -0,0 +1,8 @@ +import os + +Import('env') + +module_env = env.Clone() + +module_env.add_source_files(env.modules_sources,"register_types.cpp") +module_env.add_source_files(env.modules_sources,"vertex_lights_2d.cpp") diff --git a/modules/vertex_lights_2d/config.py b/modules/vertex_lights_2d/config.py new file mode 100644 index 000000000..677d0cef7 --- /dev/null +++ b/modules/vertex_lights_2d/config.py @@ -0,0 +1,17 @@ + + +def can_build(env, platform): + return True + + +def configure(env): + pass + + +def get_doc_classes(): + return [ + "VertexLights2D", + ] + +def get_doc_path(): + return "doc_classes" diff --git a/modules/vertex_lights_2d/register_types.cpp b/modules/vertex_lights_2d/register_types.cpp new file mode 100644 index 000000000..16cfd2ddd --- /dev/null +++ b/modules/vertex_lights_2d/register_types.cpp @@ -0,0 +1,54 @@ +/*************************************************************************/ +/* register_types.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* PANDEMONIUM ENGINE */ +/* https://github.com/Relintai/pandemonium_engine */ +/*************************************************************************/ +/* Copyright (c) 2022-present Péter Magyar. */ +/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ +/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "register_types.h" + +#include "core/config/engine.h" + +#include "vertex_lights_2d.h" + +VertexLights2D *vertex_lights_2d = NULL; + +void register_vertex_lights_2d_types(ModuleRegistrationLevel p_level) { + if (p_level == MODULE_REGISTRATION_LEVEL_SCENE) { + vertex_lights_2d = memnew(VertexLights2D); + ClassDB::register_class(); + Engine::get_singleton()->add_singleton(Engine::Singleton("VertexLights2D", VertexLights2D::get_singleton())); + } +} + +void unregister_vertex_lights_2d_types(ModuleRegistrationLevel p_level) { + if (p_level == MODULE_REGISTRATION_LEVEL_SINGLETON) { + if (vertex_lights_2d) { + memdelete(vertex_lights_2d); + } + } +} diff --git a/modules/vertex_lights_2d/register_types.h b/modules/vertex_lights_2d/register_types.h new file mode 100644 index 000000000..04cf0e4e1 --- /dev/null +++ b/modules/vertex_lights_2d/register_types.h @@ -0,0 +1,40 @@ +#ifndef VERTEX_LIGHTS_2D_REGISTER_TYPES_H +#define VERTEX_LIGHTS_2D_REGISTER_TYPES_H + +/*************************************************************************/ +/* register_types.h */ +/*************************************************************************/ +/* This file is part of: */ +/* PANDEMONIUM ENGINE */ +/* https://github.com/Relintai/pandemonium_engine */ +/*************************************************************************/ +/* Copyright (c) 2022-present Péter Magyar. */ +/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ +/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "modules/register_module_types.h" + +void register_vertex_lights_2d_types(ModuleRegistrationLevel p_level); +void unregister_vertex_lights_2d_types(ModuleRegistrationLevel p_level); + +#endif \ No newline at end of file diff --git a/modules/vertex_lights_2d/vertex_lights_2d.cpp b/modules/vertex_lights_2d/vertex_lights_2d.cpp new file mode 100644 index 000000000..956164f5b --- /dev/null +++ b/modules/vertex_lights_2d/vertex_lights_2d.cpp @@ -0,0 +1,138 @@ +/*************************************************************************/ +/* vertex_lights_2d.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* PANDEMONIUM ENGINE */ +/* https://github.com/Relintai/pandemonium_engine */ +/*************************************************************************/ +/* Copyright (c) 2022-present Péter Magyar. */ +/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ +/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "vertex_lights_2d.h" + +/* +Transform VertexLights2D::get_transform() const { + return _transform; +} +void VertexLights2D::set_transform(const Transform &p_transform) { + _transform = p_transform; +} + +real_t VertexLights2D::get_range() const { + return _range; +} +void VertexLights2D::set_range(const real_t value) { + _range = value; +} + +real_t VertexLights2D::get_attenuation() const { + return _attenuation; +} +void VertexLights2D::set_attenuation(const real_t value) { + _attenuation = value; +} + +Color VertexLights2D::get_color() const { + return _color; +} +void VertexLights2D::set_color(const Color value) { + _color = value; +} + +real_t VertexLights2D::get_energy() const { + return _energy; +} +void VertexLights2D::set_energy(const real_t value) { + _energy = value; +} + +real_t VertexLights2D::get_indirect_energy() const { + return _indirect_energy; +} +void VertexLights2D::set_indirect_energy(const real_t value) { + _indirect_energy = value; +} + +bool VertexLights2D::get_negative() const { + return _negative; +} +void VertexLights2D::set_negative(const bool value) { + _negative = value; +} + +real_t VertexLights2D::get_specular() const { + return _specular; +} +void VertexLights2D::set_specular(const real_t value) { + _specular = value; +} +*/ + +VertexLights2D::VertexLights2D() { + ERR_FAIL_COND(_self); + + _self = this; +} + +VertexLights2D::~VertexLights2D() { + _self = NULL; +} + +void VertexLights2D::_bind_methods() { + /* + ClassDB::bind_method(D_METHOD("get_transform"), &VertexLights2D::get_transform); + ClassDB::bind_method(D_METHOD("set_transform", "transform"), &VertexLights2D::set_transform); + ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM, "transform"), "set_transform", "get_transform"); + + ClassDB::bind_method(D_METHOD("get_range"), &VertexLights2D::get_range); + ClassDB::bind_method(D_METHOD("set_range", "value"), &VertexLights2D::set_range); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "light_range"), "set_range", "get_range"); + + ClassDB::bind_method(D_METHOD("get_attenuation"), &VertexLights2D::get_attenuation); + ClassDB::bind_method(D_METHOD("set_attenuation", "value"), &VertexLights2D::set_attenuation); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "light_attenuation"), "set_attenuation", "get_attenuation"); + + ClassDB::bind_method(D_METHOD("get_color"), &VertexLights2D::get_color); + ClassDB::bind_method(D_METHOD("set_color", "value"), &VertexLights2D::set_color); + ADD_PROPERTY(PropertyInfo(Variant::COLOR, "light_color"), "set_color", "get_color"); + + ClassDB::bind_method(D_METHOD("get_energy"), &VertexLights2D::get_energy); + ClassDB::bind_method(D_METHOD("set_energy", "value"), &VertexLights2D::set_energy); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "light_energy"), "set_energy", "get_energy"); + + ClassDB::bind_method(D_METHOD("get_indirect_energy"), &VertexLights2D::get_indirect_energy); + ClassDB::bind_method(D_METHOD("set_indirect_energy", "value"), &VertexLights2D::set_indirect_energy); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "light_indirect_energy"), "set_indirect_energy", "get_indirect_energy"); + + ClassDB::bind_method(D_METHOD("get_negative"), &VertexLights2D::get_negative); + ClassDB::bind_method(D_METHOD("set_negative", "value"), &VertexLights2D::set_negative); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "light_negative"), "set_negative", "get_negative"); + + ClassDB::bind_method(D_METHOD("get_specular"), &VertexLights2D::get_specular); + ClassDB::bind_method(D_METHOD("set_specular", "value"), &VertexLights2D::set_specular); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "light_specular"), "set_specular", "get_specular"); + */ +} + +VertexLights2D *VertexLights2D::_self = NULL; diff --git a/modules/vertex_lights_2d/vertex_lights_2d.h b/modules/vertex_lights_2d/vertex_lights_2d.h new file mode 100644 index 000000000..05bee6926 --- /dev/null +++ b/modules/vertex_lights_2d/vertex_lights_2d.h @@ -0,0 +1,120 @@ +#ifndef VERTEX_LIGHTS_2D_H +#define VERTEX_LIGHTS_2D_H + +/*************************************************************************/ +/* vertex_lights_2d.h */ +/*************************************************************************/ +/* This file is part of: */ +/* PANDEMONIUM ENGINE */ +/* https://github.com/Relintai/pandemonium_engine */ +/*************************************************************************/ +/* Copyright (c) 2022-present Péter Magyar. */ +/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ +/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "core/object/object.h" + +#include "core/containers/hash_map.h" +#include "core/containers/vector.h" +#include "core/math/color.h" + +#include "core/math/transform.h" + +class VertexLights2D : public Object { + GDCLASS(VertexLights2D, Object); + +public: + enum VertexLight2DMode { + VERTEX_LIGHT_2D_MODE_ADD = 0, + VERTEX_LIGHT_2D_MODE_SUB, + VERTEX_LIGHT_2D_MODE_MIX, + //VERTEX_LIGHT_2D_MODE_MASK + }; + + /* + Transform get_transform() const; + void set_transform(const Transform &p_transform); + + real_t get_range() const; + void set_range(const real_t value); + + real_t get_attenuation() const; + void set_attenuation(const real_t value); + + Color get_color() const; + void set_color(const Color value); + + real_t get_energy() const; + void set_energy(const real_t value); + + real_t get_indirect_energy() const; + void set_indirect_energy(const real_t value); + + bool get_negative() const; + void set_negative(const bool value); + + real_t get_specular() const; + void set_specular(const real_t value); + */ + + _FORCE_INLINE_ static VertexLights2D *get_singleton() { + return _self; + } + + VertexLights2D(); + ~VertexLights2D(); + +protected: + static void _bind_methods(); + + struct VertexLightData2D { + Vector2 position; + Color color; + VertexLight2DMode mode; + Vector2i z_range; + Vector2i layer_range; + int item_cull_mask; + + VertexLightData2D() { + item_cull_mask = 1; + } + }; + + struct VertexLightQuadrant2D { + HashMap lights; + Vector2i size; + }; + + struct VertexLightMap2D { + HashMap quadrants; + }; + + HashMap _maps; + Vector2i _default_quadrant_size; + + static VertexLights2D *_self; +}; + +VARIANT_ENUM_CAST(VertexLights2D::VertexLight2DMode); + +#endif