mirror of
https://github.com/Relintai/terraman.git
synced 2025-04-23 21:43:23 +02:00
Removed the old liquid mesher, and reused the normal blocky mesher as liquid mesher. It should work as is.
This commit is contained in:
parent
55a98b96d5
commit
3ccfb05b5c
1
SCsub
1
SCsub
@ -39,7 +39,6 @@ sources = [
|
|||||||
"meshers/terrain_mesher.cpp",
|
"meshers/terrain_mesher.cpp",
|
||||||
|
|
||||||
"meshers/blocky/terrain_mesher_blocky.cpp",
|
"meshers/blocky/terrain_mesher_blocky.cpp",
|
||||||
"meshers/blocky/terrain_mesher_liquid_blocky.cpp",
|
|
||||||
"meshers/default/terrain_mesher_default.cpp",
|
"meshers/default/terrain_mesher_default.cpp",
|
||||||
|
|
||||||
"world/terrain_world.cpp",
|
"world/terrain_world.cpp",
|
||||||
|
@ -48,7 +48,6 @@ def get_doc_classes():
|
|||||||
"TerrainMesherBlocky",
|
"TerrainMesherBlocky",
|
||||||
"TerrainWorldBlocky",
|
"TerrainWorldBlocky",
|
||||||
"TerrainChunkBlocky",
|
"TerrainChunkBlocky",
|
||||||
"TerrainMesherLiquidBlocky",
|
|
||||||
|
|
||||||
"TerrainWorldMarchingCubes",
|
"TerrainWorldMarchingCubes",
|
||||||
"TerrainChunkMarchingCubes",
|
"TerrainChunkMarchingCubes",
|
||||||
|
@ -1,13 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
|
||||||
<class name="TerrainMesherLiquidBlocky" inherits="TerrainMesherDefault" version="3.5">
|
|
||||||
<brief_description>
|
|
||||||
</brief_description>
|
|
||||||
<description>
|
|
||||||
</description>
|
|
||||||
<tutorials>
|
|
||||||
</tutorials>
|
|
||||||
<methods>
|
|
||||||
</methods>
|
|
||||||
<constants>
|
|
||||||
</constants>
|
|
||||||
</class>
|
|
@ -1,484 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (c) 2019-2022 Péter Magyar
|
|
||||||
|
|
||||||
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 "terrain_mesher_liquid_blocky.h"
|
|
||||||
|
|
||||||
#include "../../world/default/terrain_chunk_default.h"
|
|
||||||
|
|
||||||
void TerrainMesherLiquidBlocky::_add_chunk(Ref<TerrainChunk> p_chunk) {
|
|
||||||
Ref<TerrainChunkDefault> chunk = p_chunk;
|
|
||||||
|
|
||||||
ERR_FAIL_COND(!chunk.is_valid());
|
|
||||||
|
|
||||||
//if ((get_build_flags() & TerrainChunkDefault::BUILD_FLAG_GENERATE_AO) != 0)
|
|
||||||
// chunk->generate_ao();
|
|
||||||
|
|
||||||
int x_size = chunk->get_size_x();
|
|
||||||
int z_size = chunk->get_size_z();
|
|
||||||
|
|
||||||
float voxel_scale = get_voxel_scale();
|
|
||||||
|
|
||||||
uint8_t *channel_type = chunk->channel_get(TerrainChunkDefault::DEFAULT_CHANNEL_TYPE);
|
|
||||||
|
|
||||||
if (!channel_type)
|
|
||||||
return;
|
|
||||||
|
|
||||||
uint8_t *channel_color_r = NULL;
|
|
||||||
uint8_t *channel_color_g = NULL;
|
|
||||||
uint8_t *channel_color_b = NULL;
|
|
||||||
uint8_t *channel_ao = NULL;
|
|
||||||
uint8_t *channel_rao = NULL;
|
|
||||||
|
|
||||||
Color base_light(_base_light_value, _base_light_value, _base_light_value);
|
|
||||||
Color light;
|
|
||||||
bool use_lighting = (get_build_flags() & TerrainChunkDefault::BUILD_FLAG_USE_LIGHTING) != 0;
|
|
||||||
bool use_ao = (get_build_flags() & TerrainChunkDefault::BUILD_FLAG_USE_AO) != 0;
|
|
||||||
bool use_rao = (get_build_flags() & TerrainChunkDefault::BUILD_FLAG_USE_RAO) != 0;
|
|
||||||
|
|
||||||
if (use_lighting) {
|
|
||||||
channel_color_r = chunk->channel_get(TerrainChunkDefault::DEFAULT_CHANNEL_LIGHT_COLOR_R);
|
|
||||||
channel_color_g = chunk->channel_get(TerrainChunkDefault::DEFAULT_CHANNEL_LIGHT_COLOR_G);
|
|
||||||
channel_color_b = chunk->channel_get(TerrainChunkDefault::DEFAULT_CHANNEL_LIGHT_COLOR_B);
|
|
||||||
|
|
||||||
if (use_ao)
|
|
||||||
channel_ao = chunk->channel_get(TerrainChunkDefault::DEFAULT_CHANNEL_AO);
|
|
||||||
|
|
||||||
if (use_rao)
|
|
||||||
channel_rao = chunk->channel_get(TerrainChunkDefault::DEFAULT_CHANNEL_RANDOM_AO);
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector<uint8_t> liquids;
|
|
||||||
for (int i = 0; i < _library->terra_surface_get_num(); ++i) {
|
|
||||||
Ref<TerrainSurface> surface = _library->terra_surface_get(i);
|
|
||||||
|
|
||||||
if (!surface.is_valid())
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (surface->get_liquid())
|
|
||||||
liquids.push_back(static_cast<uint8_t>(i + 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int z = chunk->get_margin_start(); z < z_size + chunk->get_margin_start(); ++z) {
|
|
||||||
for (int x = chunk->get_margin_start(); x < x_size + chunk->get_margin_start(); ++x) {
|
|
||||||
|
|
||||||
int index = chunk->get_data_index(x, z);
|
|
||||||
int indexxp = chunk->get_data_index(x + 1, z);
|
|
||||||
int indexxn = chunk->get_data_index(x - 1, z);
|
|
||||||
int indexzp = chunk->get_data_index(x, z + 1);
|
|
||||||
int indexzn = chunk->get_data_index(x, z - 1);
|
|
||||||
|
|
||||||
uint8_t type = channel_type[index];
|
|
||||||
|
|
||||||
if (type == 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (liquids.find(type) == -1)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
Ref<TerrainSurface> surface = _library->terra_surface_get(type - 1);
|
|
||||||
|
|
||||||
if (!surface.is_valid())
|
|
||||||
continue;
|
|
||||||
|
|
||||||
uint8_t neighbours[] = {
|
|
||||||
channel_type[indexxp],
|
|
||||||
channel_type[indexxn],
|
|
||||||
channel_type[indexzp],
|
|
||||||
channel_type[indexzn],
|
|
||||||
};
|
|
||||||
|
|
||||||
//x + 1
|
|
||||||
if (neighbours[0] == 0) {
|
|
||||||
if (use_lighting) {
|
|
||||||
light = Color(channel_color_r[indexxp] / 255.0,
|
|
||||||
channel_color_g[indexxp] / 255.0,
|
|
||||||
channel_color_b[indexxp] / 255.0);
|
|
||||||
|
|
||||||
float ao = 0;
|
|
||||||
|
|
||||||
if (use_ao)
|
|
||||||
ao = channel_ao[indexxp] / 255.0;
|
|
||||||
|
|
||||||
if (use_rao) {
|
|
||||||
float rao = channel_rao[indexxp] / 255.0;
|
|
||||||
ao += rao;
|
|
||||||
}
|
|
||||||
|
|
||||||
light += base_light;
|
|
||||||
|
|
||||||
if (ao > 0)
|
|
||||||
light -= Color(ao, ao, ao) * _ao_strength;
|
|
||||||
|
|
||||||
light.r = CLAMP(light.r, 0, 1.0);
|
|
||||||
light.g = CLAMP(light.g, 0, 1.0);
|
|
||||||
light.b = CLAMP(light.b, 0, 1.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
int vc = get_vertex_count();
|
|
||||||
add_indices(vc + 2);
|
|
||||||
add_indices(vc + 1);
|
|
||||||
add_indices(vc + 0);
|
|
||||||
add_indices(vc + 3);
|
|
||||||
add_indices(vc + 2);
|
|
||||||
add_indices(vc + 0);
|
|
||||||
|
|
||||||
Vector2 uvs[] = {
|
|
||||||
surface->transform_uv(TerrainSurface::TERRAIN_SIDE_SIDE, Vector2(0, 1)),
|
|
||||||
surface->transform_uv(TerrainSurface::TERRAIN_SIDE_SIDE, Vector2(0, 0)),
|
|
||||||
surface->transform_uv(TerrainSurface::TERRAIN_SIDE_SIDE, Vector2(1, 0)),
|
|
||||||
surface->transform_uv(TerrainSurface::TERRAIN_SIDE_SIDE, Vector2(1, 1))
|
|
||||||
};
|
|
||||||
|
|
||||||
Vector3 verts[] = {
|
|
||||||
Vector3(1, 0, 0) * voxel_scale + Vector3(x - 1, - 1, z - 1) * voxel_scale,
|
|
||||||
Vector3(1, 1, 0) * voxel_scale + Vector3(x - 1, - 1, z - 1) * voxel_scale,
|
|
||||||
Vector3(1, 1, 1) * voxel_scale + Vector3(x - 1, - 1, z - 1) * voxel_scale,
|
|
||||||
Vector3(1, 0, 1) * voxel_scale + Vector3(x - 1, - 1, z - 1) * voxel_scale
|
|
||||||
};
|
|
||||||
|
|
||||||
for (int i = 0; i < 4; ++i) {
|
|
||||||
add_normal(Vector3(1, 0, 0));
|
|
||||||
|
|
||||||
if (use_lighting)
|
|
||||||
add_color(light);
|
|
||||||
|
|
||||||
add_uv(uvs[i]);
|
|
||||||
add_vertex(verts[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//x - 1
|
|
||||||
if (neighbours[1] == 0) {
|
|
||||||
if (use_lighting) {
|
|
||||||
light = Color(channel_color_r[indexxn] / 255.0,
|
|
||||||
channel_color_g[indexxn] / 255.0,
|
|
||||||
channel_color_b[indexxn] / 255.0);
|
|
||||||
|
|
||||||
float ao = 0;
|
|
||||||
|
|
||||||
if (use_ao)
|
|
||||||
ao = channel_ao[indexxn] / 255.0;
|
|
||||||
|
|
||||||
if (use_rao) {
|
|
||||||
float rao = channel_rao[indexxn] / 255.0;
|
|
||||||
ao += rao;
|
|
||||||
}
|
|
||||||
|
|
||||||
light += base_light;
|
|
||||||
|
|
||||||
if (ao > 0)
|
|
||||||
light -= Color(ao, ao, ao) * _ao_strength;
|
|
||||||
|
|
||||||
light.r = CLAMP(light.r, 0, 1.0);
|
|
||||||
light.g = CLAMP(light.g, 0, 1.0);
|
|
||||||
light.b = CLAMP(light.b, 0, 1.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
int vc = get_vertex_count();
|
|
||||||
add_indices(vc + 0);
|
|
||||||
add_indices(vc + 1);
|
|
||||||
add_indices(vc + 2);
|
|
||||||
|
|
||||||
add_indices(vc + 0);
|
|
||||||
add_indices(vc + 2);
|
|
||||||
add_indices(vc + 3);
|
|
||||||
|
|
||||||
Vector2 uvs[] = {
|
|
||||||
surface->transform_uv(TerrainSurface::TERRAIN_SIDE_SIDE, Vector2(0, 1)),
|
|
||||||
surface->transform_uv(TerrainSurface::TERRAIN_SIDE_SIDE, Vector2(0, 0)),
|
|
||||||
surface->transform_uv(TerrainSurface::TERRAIN_SIDE_SIDE, Vector2(1, 0)),
|
|
||||||
surface->transform_uv(TerrainSurface::TERRAIN_SIDE_SIDE, Vector2(1, 1))
|
|
||||||
};
|
|
||||||
|
|
||||||
Vector3 verts[] = {
|
|
||||||
Vector3(0, 0, 0) * voxel_scale + Vector3(x - 1, - 1, z - 1) * voxel_scale,
|
|
||||||
Vector3(0, 1, 0) * voxel_scale + Vector3(x - 1, - 1, z - 1) * voxel_scale,
|
|
||||||
Vector3(0, 1, 1) * voxel_scale + Vector3(x - 1, - 1, z - 1) * voxel_scale,
|
|
||||||
Vector3(0, 0, 1) * voxel_scale + Vector3(x - 1, - 1, z - 1) * voxel_scale
|
|
||||||
};
|
|
||||||
|
|
||||||
for (int i = 0; i < 4; ++i) {
|
|
||||||
add_normal(Vector3(-1, 0, 0));
|
|
||||||
|
|
||||||
if (use_lighting)
|
|
||||||
add_color(light);
|
|
||||||
|
|
||||||
add_uv(uvs[i]);
|
|
||||||
add_vertex(verts[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
//y + 1
|
|
||||||
if (neighbours[2] == 0) {
|
|
||||||
if (use_lighting) {
|
|
||||||
light = Color(channel_color_r[indexyp] / 255.0,
|
|
||||||
channel_color_g[indexyp] / 255.0,
|
|
||||||
channel_color_b[indexyp] / 255.0);
|
|
||||||
|
|
||||||
float ao = 0;
|
|
||||||
|
|
||||||
if (use_ao)
|
|
||||||
ao = channel_ao[indexyp] / 255.0;
|
|
||||||
|
|
||||||
if (use_rao) {
|
|
||||||
float rao = channel_rao[indexyp] / 255.0;
|
|
||||||
ao += rao;
|
|
||||||
}
|
|
||||||
|
|
||||||
light += base_light;
|
|
||||||
|
|
||||||
if (ao > 0)
|
|
||||||
light -= Color(ao, ao, ao) * _ao_strength;
|
|
||||||
}
|
|
||||||
|
|
||||||
light.r = CLAMP(light.r, 0, 1.0);
|
|
||||||
light.g = CLAMP(light.g, 0, 1.0);
|
|
||||||
light.b = CLAMP(light.b, 0, 1.0);
|
|
||||||
|
|
||||||
int vc = get_vertex_count();
|
|
||||||
add_indices(vc + 2);
|
|
||||||
add_indices(vc + 1);
|
|
||||||
add_indices(vc + 0);
|
|
||||||
add_indices(vc + 3);
|
|
||||||
add_indices(vc + 2);
|
|
||||||
add_indices(vc + 0);
|
|
||||||
|
|
||||||
Vector2 uvs[] = {
|
|
||||||
surface->transform_uv(TerrainSurface::TERRAIN_SIDE_TOP, Vector2(0, 1)),
|
|
||||||
surface->transform_uv(TerrainSurface::TERRAIN_SIDE_TOP, Vector2(0, 0)),
|
|
||||||
surface->transform_uv(TerrainSurface::TERRAIN_SIDE_TOP, Vector2(1, 0)),
|
|
||||||
surface->transform_uv(TerrainSurface::TERRAIN_SIDE_TOP, Vector2(1, 1))
|
|
||||||
};
|
|
||||||
|
|
||||||
Vector3 verts[] = {
|
|
||||||
Vector3(1, 1, 0) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale,
|
|
||||||
Vector3(0, 1, 0) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale,
|
|
||||||
Vector3(0, 1, 1) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale,
|
|
||||||
Vector3(1, 1, 1) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale
|
|
||||||
};
|
|
||||||
|
|
||||||
for (int i = 0; i < 4; ++i) {
|
|
||||||
add_normal(Vector3(0, 1, 0));
|
|
||||||
|
|
||||||
if (use_lighting)
|
|
||||||
add_color(light);
|
|
||||||
|
|
||||||
add_uv(uvs[i]);
|
|
||||||
add_vertex(verts[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
//y - 1
|
|
||||||
if (neighbours[3] == 0) {
|
|
||||||
if (use_lighting) {
|
|
||||||
light = Color(channel_color_r[indexyn] / 255.0,
|
|
||||||
channel_color_g[indexyn] / 255.0,
|
|
||||||
channel_color_b[indexyn] / 255.0);
|
|
||||||
|
|
||||||
float ao = 0;
|
|
||||||
|
|
||||||
if (use_ao)
|
|
||||||
ao = channel_ao[indexyn] / 255.0;
|
|
||||||
|
|
||||||
if (use_rao) {
|
|
||||||
float rao = channel_rao[indexyn] / 255.0;
|
|
||||||
ao += rao;
|
|
||||||
}
|
|
||||||
|
|
||||||
light += base_light;
|
|
||||||
|
|
||||||
if (ao > 0)
|
|
||||||
light -= Color(ao, ao, ao) * _ao_strength;
|
|
||||||
}
|
|
||||||
|
|
||||||
light.r = CLAMP(light.r, 0, 1.0);
|
|
||||||
light.g = CLAMP(light.g, 0, 1.0);
|
|
||||||
light.b = CLAMP(light.b, 0, 1.0);
|
|
||||||
|
|
||||||
int vc = get_vertex_count();
|
|
||||||
add_indices(vc + 0);
|
|
||||||
add_indices(vc + 1);
|
|
||||||
add_indices(vc + 2);
|
|
||||||
|
|
||||||
add_indices(vc + 0);
|
|
||||||
add_indices(vc + 2);
|
|
||||||
add_indices(vc + 3);
|
|
||||||
|
|
||||||
Vector2 uvs[] = {
|
|
||||||
surface->transform_uv(TerrainSurface::TERRAIN_SIDE_BOTTOM, Vector2(0, 1)),
|
|
||||||
surface->transform_uv(TerrainSurface::TERRAIN_SIDE_BOTTOM, Vector2(0, 0)),
|
|
||||||
surface->transform_uv(TerrainSurface::TERRAIN_SIDE_BOTTOM, Vector2(1, 0)),
|
|
||||||
surface->transform_uv(TerrainSurface::TERRAIN_SIDE_BOTTOM, Vector2(1, 1))
|
|
||||||
};
|
|
||||||
|
|
||||||
Vector3 verts[] = {
|
|
||||||
Vector3(1, 0, 0) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale,
|
|
||||||
Vector3(0, 0, 0) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale,
|
|
||||||
Vector3(0, 0, 1) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale,
|
|
||||||
Vector3(1, 0, 1) * voxel_scale + Vector3(x - 1, y - 1, z - 1) * voxel_scale
|
|
||||||
};
|
|
||||||
|
|
||||||
for (int i = 0; i < 4; ++i) {
|
|
||||||
add_normal(Vector3(0, -1, 0));
|
|
||||||
|
|
||||||
if (use_lighting)
|
|
||||||
add_color(light);
|
|
||||||
|
|
||||||
add_uv(uvs[i]);
|
|
||||||
add_vertex(verts[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
//z + 1
|
|
||||||
if (neighbours[2] == 0) {
|
|
||||||
if (use_lighting) {
|
|
||||||
light = Color(channel_color_r[indexzp] / 255.0,
|
|
||||||
channel_color_g[indexzp] / 255.0,
|
|
||||||
channel_color_b[indexzp] / 255.0);
|
|
||||||
|
|
||||||
float ao = 0;
|
|
||||||
|
|
||||||
if (use_ao)
|
|
||||||
ao = channel_ao[indexzp] / 255.0;
|
|
||||||
|
|
||||||
if (use_rao) {
|
|
||||||
float rao = channel_rao[indexzp] / 255.0;
|
|
||||||
ao += rao;
|
|
||||||
}
|
|
||||||
|
|
||||||
light += base_light;
|
|
||||||
|
|
||||||
if (ao > 0)
|
|
||||||
light -= Color(ao, ao, ao) * _ao_strength;
|
|
||||||
|
|
||||||
light.r = CLAMP(light.r, 0, 1.0);
|
|
||||||
light.g = CLAMP(light.g, 0, 1.0);
|
|
||||||
light.b = CLAMP(light.b, 0, 1.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
int vc = get_vertex_count();
|
|
||||||
add_indices(vc + 2);
|
|
||||||
add_indices(vc + 1);
|
|
||||||
add_indices(vc + 0);
|
|
||||||
add_indices(vc + 3);
|
|
||||||
add_indices(vc + 2);
|
|
||||||
add_indices(vc + 0);
|
|
||||||
|
|
||||||
Vector2 uvs[] = {
|
|
||||||
surface->transform_uv(TerrainSurface::TERRAIN_SIDE_SIDE, Vector2(0, 1)),
|
|
||||||
surface->transform_uv(TerrainSurface::TERRAIN_SIDE_SIDE, Vector2(0, 0)),
|
|
||||||
surface->transform_uv(TerrainSurface::TERRAIN_SIDE_SIDE, Vector2(1, 0)),
|
|
||||||
surface->transform_uv(TerrainSurface::TERRAIN_SIDE_SIDE, Vector2(1, 1))
|
|
||||||
};
|
|
||||||
|
|
||||||
Vector3 verts[] = {
|
|
||||||
Vector3(1, 0, 1) * voxel_scale + Vector3(x - 1, - 1, z - 1) * voxel_scale,
|
|
||||||
Vector3(1, 1, 1) * voxel_scale + Vector3(x - 1, - 1, z - 1) * voxel_scale,
|
|
||||||
Vector3(0, 1, 1) * voxel_scale + Vector3(x - 1, - 1, z - 1) * voxel_scale,
|
|
||||||
Vector3(0, 0, 1) * voxel_scale + Vector3(x - 1, - 1, z - 1) * voxel_scale
|
|
||||||
};
|
|
||||||
|
|
||||||
for (int i = 0; i < 4; ++i) {
|
|
||||||
add_normal(Vector3(0, 0, 1));
|
|
||||||
|
|
||||||
if (use_lighting)
|
|
||||||
add_color(light);
|
|
||||||
|
|
||||||
add_uv(uvs[i]);
|
|
||||||
add_vertex(verts[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//z - 1
|
|
||||||
if (neighbours[3] == 0) {
|
|
||||||
if (use_lighting) {
|
|
||||||
light = Color(channel_color_r[indexzn] / 255.0,
|
|
||||||
channel_color_g[indexzn] / 255.0,
|
|
||||||
channel_color_b[indexzn] / 255.0);
|
|
||||||
|
|
||||||
float ao = 0;
|
|
||||||
|
|
||||||
if (use_ao)
|
|
||||||
ao = channel_ao[indexzn] / 255.0;
|
|
||||||
|
|
||||||
if (use_rao) {
|
|
||||||
float rao = channel_rao[indexzn] / 255.0;
|
|
||||||
ao += rao;
|
|
||||||
}
|
|
||||||
|
|
||||||
light += base_light;
|
|
||||||
|
|
||||||
if (ao > 0)
|
|
||||||
light -= Color(ao, ao, ao) * _ao_strength;
|
|
||||||
|
|
||||||
light.r = CLAMP(light.r, 0, 1.0);
|
|
||||||
light.g = CLAMP(light.g, 0, 1.0);
|
|
||||||
light.b = CLAMP(light.b, 0, 1.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
int vc = get_vertex_count();
|
|
||||||
add_indices(vc + 0);
|
|
||||||
add_indices(vc + 1);
|
|
||||||
add_indices(vc + 2);
|
|
||||||
|
|
||||||
add_indices(vc + 0);
|
|
||||||
add_indices(vc + 2);
|
|
||||||
add_indices(vc + 3);
|
|
||||||
|
|
||||||
Vector2 uvs[] = {
|
|
||||||
surface->transform_uv(TerrainSurface::TERRAIN_SIDE_SIDE, Vector2(0, 1)),
|
|
||||||
surface->transform_uv(TerrainSurface::TERRAIN_SIDE_SIDE, Vector2(0, 0)),
|
|
||||||
surface->transform_uv(TerrainSurface::TERRAIN_SIDE_SIDE, Vector2(1, 0)),
|
|
||||||
surface->transform_uv(TerrainSurface::TERRAIN_SIDE_SIDE, Vector2(1, 1))
|
|
||||||
};
|
|
||||||
|
|
||||||
Vector3 verts[] = {
|
|
||||||
Vector3(1, 0, 0) * voxel_scale + Vector3(x - 1, - 1, z - 1) * voxel_scale,
|
|
||||||
Vector3(1, 1, 0) * voxel_scale + Vector3(x - 1, - 1, z - 1) * voxel_scale,
|
|
||||||
Vector3(0, 1, 0) * voxel_scale + Vector3(x - 1, - 1, z - 1) * voxel_scale,
|
|
||||||
Vector3(0, 0, 0) * voxel_scale + Vector3(x - 1, - 1, z - 1) * voxel_scale
|
|
||||||
};
|
|
||||||
|
|
||||||
for (int i = 0; i < 4; ++i) {
|
|
||||||
add_normal(Vector3(0, 0, -1));
|
|
||||||
|
|
||||||
if (use_lighting)
|
|
||||||
add_color(light);
|
|
||||||
|
|
||||||
add_uv(uvs[i]);
|
|
||||||
add_vertex(verts[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TerrainMesherLiquidBlocky::TerrainMesherLiquidBlocky() {
|
|
||||||
}
|
|
||||||
|
|
||||||
TerrainMesherLiquidBlocky::~TerrainMesherLiquidBlocky() {
|
|
||||||
}
|
|
||||||
|
|
||||||
void TerrainMesherLiquidBlocky::_bind_methods() {
|
|
||||||
ClassDB::bind_method(D_METHOD("_add_chunk", "buffer"), &TerrainMesherLiquidBlocky::_add_chunk);
|
|
||||||
}
|
|
@ -1,52 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (c) 2019-2022 Péter Magyar
|
|
||||||
|
|
||||||
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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef TERRAIN_MESHER_LIQUID_BLOCKY_H
|
|
||||||
#define TERRAIN_MESHER_LIQUID_BLOCKY_H
|
|
||||||
|
|
||||||
#include "core/version.h"
|
|
||||||
|
|
||||||
#if VERSION_MAJOR > 3
|
|
||||||
#include "core/math/color.h"
|
|
||||||
#else
|
|
||||||
#include "core/color.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "core/math/vector2.h"
|
|
||||||
#include "core/math/vector3.h"
|
|
||||||
|
|
||||||
#include "../default/terrain_mesher_default.h"
|
|
||||||
|
|
||||||
class TerrainMesherLiquidBlocky : public TerrainMesherDefault {
|
|
||||||
GDCLASS(TerrainMesherLiquidBlocky, TerrainMesherDefault);
|
|
||||||
|
|
||||||
public:
|
|
||||||
void _add_chunk(Ref<TerrainChunk> p_chunk);
|
|
||||||
|
|
||||||
TerrainMesherLiquidBlocky();
|
|
||||||
~TerrainMesherLiquidBlocky();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
static void _bind_methods();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
@ -56,7 +56,6 @@ SOFTWARE.
|
|||||||
#include "world/terrain_world_editor.h"
|
#include "world/terrain_world_editor.h"
|
||||||
|
|
||||||
#include "meshers/blocky/terrain_mesher_blocky.h"
|
#include "meshers/blocky/terrain_mesher_blocky.h"
|
||||||
#include "meshers/blocky/terrain_mesher_liquid_blocky.h"
|
|
||||||
|
|
||||||
#include "world/blocky/terrain_chunk_blocky.h"
|
#include "world/blocky/terrain_chunk_blocky.h"
|
||||||
#include "world/blocky/terrain_world_blocky.h"
|
#include "world/blocky/terrain_world_blocky.h"
|
||||||
@ -103,7 +102,6 @@ void register_terraman_types() {
|
|||||||
ClassDB::register_class<TerrainMesherBlocky>();
|
ClassDB::register_class<TerrainMesherBlocky>();
|
||||||
ClassDB::register_class<TerrainWorldBlocky>();
|
ClassDB::register_class<TerrainWorldBlocky>();
|
||||||
ClassDB::register_class<TerrainChunkBlocky>();
|
ClassDB::register_class<TerrainChunkBlocky>();
|
||||||
ClassDB::register_class<TerrainMesherLiquidBlocky>();
|
|
||||||
|
|
||||||
ClassDB::register_class<TerrainLevelGenerator>();
|
ClassDB::register_class<TerrainLevelGenerator>();
|
||||||
ClassDB::register_class<TerrainLevelGeneratorFlat>();
|
ClassDB::register_class<TerrainLevelGeneratorFlat>();
|
||||||
|
@ -25,7 +25,6 @@ SOFTWARE.
|
|||||||
#include "terrain_chunk_blocky.h"
|
#include "terrain_chunk_blocky.h"
|
||||||
|
|
||||||
#include "../../meshers/blocky/terrain_mesher_blocky.h"
|
#include "../../meshers/blocky/terrain_mesher_blocky.h"
|
||||||
#include "../../meshers/blocky/terrain_mesher_liquid_blocky.h"
|
|
||||||
#include "../jobs/terrain_light_job.h"
|
#include "../jobs/terrain_light_job.h"
|
||||||
#include "../jobs/terrain_prop_job.h"
|
#include "../jobs/terrain_prop_job.h"
|
||||||
#include "../jobs/terrain_terrain_job.h"
|
#include "../jobs/terrain_terrain_job.h"
|
||||||
@ -66,7 +65,12 @@ Ref<TerrainChunk> TerrainWorldBlocky::_create_chunk(int x, int z, Ref<TerrainChu
|
|||||||
tj->add_jobs_step(s);
|
tj->add_jobs_step(s);
|
||||||
|
|
||||||
tj->set_mesher(Ref<TerrainMesher>(memnew(TerrainMesherBlocky())));
|
tj->set_mesher(Ref<TerrainMesher>(memnew(TerrainMesherBlocky())));
|
||||||
tj->set_liquid_mesher(Ref<TerrainMesher>(memnew(TerrainMesherLiquidBlocky())));
|
|
||||||
|
Ref<TerrainMesherBlocky> liquid_mesher;
|
||||||
|
liquid_mesher.instance();
|
||||||
|
liquid_mesher->set_channel_index_type(TerrainChunkDefault::DEFAULT_CHANNEL_LIQUID_TYPE);
|
||||||
|
liquid_mesher->set_channel_index_isolevel(TerrainChunkDefault::DEFAULT_CHANNEL_LIQUID_ISOLEVEL);
|
||||||
|
tj->set_liquid_mesher(liquid_mesher);
|
||||||
|
|
||||||
Ref<TerrainPropJob> pj;
|
Ref<TerrainPropJob> pj;
|
||||||
pj.instance();
|
pj.instance();
|
||||||
|
Loading…
Reference in New Issue
Block a user