mirror of
https://github.com/Relintai/props.git
synced 2024-11-14 10:17:30 +01:00
Reimplement get_random_ao in PropMesher. Now it just returns the RAO value for that position.
This commit is contained in:
parent
308d8e0baf
commit
3d1faef5ac
@ -22,6 +22,8 @@ SOFTWARE.
|
|||||||
|
|
||||||
#include "prop_mesher.h"
|
#include "prop_mesher.h"
|
||||||
|
|
||||||
|
#include "modules/opensimplex/open_simplex_noise.h"
|
||||||
|
|
||||||
const String PropMesher::BINDING_STRING_BUILD_FLAGS = "Use Isolevel,Use Lighting,Use AO,Use RAO,Generate AO,Generate RAO,Bake Lights,Create Collider,Create Lods";
|
const String PropMesher::BINDING_STRING_BUILD_FLAGS = "Use Isolevel,Use Lighting,Use AO,Use RAO,Generate AO,Generate RAO,Bake Lights,Create Collider,Create Lods";
|
||||||
|
|
||||||
bool PropMesher::Vertex::operator==(const Vertex &p_vertex) const {
|
bool PropMesher::Vertex::operator==(const Vertex &p_vertex) const {
|
||||||
@ -595,43 +597,18 @@ void PropMesher::generate_ao() {
|
|||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void PropMesher::generate_random_ao(int seed, int octaves, int period, float persistence, float scale_factor) {
|
uint8_t PropMesher::get_random_ao(const Vector3 &position) {
|
||||||
/*
|
float val = _noise->get_noise_3d(position.x, position.y, position.z);
|
||||||
ERR_FAIL_COND(!_chunk.is_valid());
|
|
||||||
|
|
||||||
int margin_start = _chunk->get_margin_start();
|
val *= _rao_scale_factor;
|
||||||
int margin_end = _chunk->get_margin_end();
|
|
||||||
|
|
||||||
int size_x = _chunk->get_size_x();
|
if (val > 1)
|
||||||
int size_z = _chunk->get_size_z();
|
val = 1;
|
||||||
|
|
||||||
int position_x = _chunk->get_position_x();
|
if (val < 0)
|
||||||
int position_z = _chunk->get_position_z();
|
val = -val;
|
||||||
|
|
||||||
Ref<OpenSimplexNoise> noise;
|
return static_cast<uint8_t>(val * 255.0);
|
||||||
noise.instance();
|
|
||||||
|
|
||||||
noise->set_seed(seed);
|
|
||||||
noise->set_octaves(octaves);
|
|
||||||
noise->set_period(period);
|
|
||||||
noise->set_persistence(persistence);
|
|
||||||
|
|
||||||
for (int x = -margin_start; x < size_x + margin_end; ++x) {
|
|
||||||
for (int z = -margin_start; z < size_z + margin_end; ++z) {
|
|
||||||
|
|
||||||
float val = noise->get_noise_3d(x + (position_x * size_x), 0, z + (position_z * size_z));
|
|
||||||
|
|
||||||
val *= scale_factor;
|
|
||||||
|
|
||||||
if (val > 1)
|
|
||||||
val = 1;
|
|
||||||
|
|
||||||
if (val < 0)
|
|
||||||
val = -val;
|
|
||||||
|
|
||||||
_chunk->set_voxel(int(val * 255.0), x, z, TerraChunkDefault::DEFAULT_CHANNEL_RANDOM_AO);
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PropMesher::add_mesher(const Ref<PropMesher> &mesher) {
|
void PropMesher::add_mesher(const Ref<PropMesher> &mesher) {
|
||||||
@ -987,6 +964,15 @@ PropMesher::PropMesher() {
|
|||||||
_build_flags = PropMesher::BUILD_FLAG_CREATE_COLLIDER | PropMesher::BUILD_FLAG_CREATE_LODS;
|
_build_flags = PropMesher::BUILD_FLAG_CREATE_COLLIDER | PropMesher::BUILD_FLAG_CREATE_LODS;
|
||||||
|
|
||||||
_format = VisualServer::ARRAY_FORMAT_NORMAL | VisualServer::ARRAY_FORMAT_TEX_UV;
|
_format = VisualServer::ARRAY_FORMAT_NORMAL | VisualServer::ARRAY_FORMAT_TEX_UV;
|
||||||
|
|
||||||
|
_noise.instance();
|
||||||
|
//todo add properties for these if needed
|
||||||
|
_noise->set_octaves(4);
|
||||||
|
_noise->set_period(30);
|
||||||
|
_noise->set_persistence(0.3);
|
||||||
|
|
||||||
|
_rao_scale_factor = 0.6;
|
||||||
|
_rao_seed = 2134;
|
||||||
}
|
}
|
||||||
|
|
||||||
PropMesher::~PropMesher() {
|
PropMesher::~PropMesher() {
|
||||||
@ -1044,7 +1030,7 @@ void PropMesher::_bind_methods() {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("generate_ao"), &PropMesher::generate_ao);
|
ClassDB::bind_method(D_METHOD("generate_ao"), &PropMesher::generate_ao);
|
||||||
ClassDB::bind_method(D_METHOD("generate_random_ao", "seed", "octaves", "period", "persistence", "scale_factor"), &PropMesher::generate_random_ao, DEFVAL(4), DEFVAL(30), DEFVAL(0.3), DEFVAL(0.6));
|
ClassDB::bind_method(D_METHOD("get_random_ao", "position"),&PropMesher::get_random_ao);
|
||||||
|
|
||||||
BIND_VMETHOD(MethodInfo("_add_mesher", PropertyInfo(Variant::OBJECT, "mesher", PROPERTY_HINT_RESOURCE_TYPE, "PropMesher")));
|
BIND_VMETHOD(MethodInfo("_add_mesher", PropertyInfo(Variant::OBJECT, "mesher", PROPERTY_HINT_RESOURCE_TYPE, "PropMesher")));
|
||||||
ClassDB::bind_method(D_METHOD("add_mesher", "mesher"), &PropMesher::add_mesher);
|
ClassDB::bind_method(D_METHOD("add_mesher", "mesher"), &PropMesher::add_mesher);
|
||||||
|
@ -60,6 +60,8 @@ using PoolVector = Vector<N>;
|
|||||||
#include "../terraman/data/terra_light.h"
|
#include "../terraman/data/terra_light.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
class OpenSimplexNoise;
|
||||||
|
|
||||||
class PropMesher : public Reference {
|
class PropMesher : public Reference {
|
||||||
GDCLASS(PropMesher, Reference);
|
GDCLASS(PropMesher, Reference);
|
||||||
|
|
||||||
@ -153,7 +155,7 @@ public:
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
void generate_ao();
|
void generate_ao();
|
||||||
void generate_random_ao(int seed, int octaves = 4, int period = 30, float persistence = 0.3, float scale_factor = 0.6);
|
uint8_t get_random_ao(const Vector3 &position);
|
||||||
|
|
||||||
void add_mesher(const Ref<PropMesher> &mesher);
|
void add_mesher(const Ref<PropMesher> &mesher);
|
||||||
void _add_mesher(const Ref<PropMesher> &mesher);
|
void _add_mesher(const Ref<PropMesher> &mesher);
|
||||||
@ -239,6 +241,10 @@ protected:
|
|||||||
float _base_light_value;
|
float _base_light_value;
|
||||||
Rect2 _uv_margin;
|
Rect2 _uv_margin;
|
||||||
int _build_flags;
|
int _build_flags;
|
||||||
|
|
||||||
|
Ref<OpenSimplexNoise> _noise;
|
||||||
|
float _rao_scale_factor;
|
||||||
|
int _rao_seed;
|
||||||
};
|
};
|
||||||
|
|
||||||
VARIANT_ENUM_CAST(PropMesher::BuildFlags);
|
VARIANT_ENUM_CAST(PropMesher::BuildFlags);
|
||||||
|
Loading…
Reference in New Issue
Block a user