Added access to block local transform in custom shaders for VoxelLodTerrain
This commit is contained in:
parent
09b32c9dd8
commit
18e7792bd5
@ -208,6 +208,22 @@ void VoxelBlock::_set_visible(bool visible) {
|
||||
|
||||
void VoxelBlock::set_shader_material(Ref<ShaderMaterial> material) {
|
||||
_shader_material = material;
|
||||
|
||||
if (_mesh_instance.is_valid()) {
|
||||
_mesh_instance.set_material_override(_shader_material);
|
||||
|
||||
for (int dir = 0; dir < Cube::SIDE_COUNT; ++dir) {
|
||||
DirectMeshInstance &mi = _transition_mesh_instances[dir];
|
||||
if (mi.is_valid()) {
|
||||
mi.set_material_override(_shader_material);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (_shader_material.is_valid()) {
|
||||
const Transform local_transform(Basis(), _position_in_voxels.to_vec3());
|
||||
_shader_material->set_shader_param(VoxelStringNames::get_singleton()->u_block_local_transform, local_transform);
|
||||
}
|
||||
}
|
||||
|
||||
//void VoxelBlock::set_transition_bit(uint8_t side, bool value) {
|
||||
@ -243,6 +259,7 @@ void VoxelBlock::set_transition_mask(uint8_t m) {
|
||||
tm |= bits[Cube::SIDE_NEGATIVE_Z] << 4;
|
||||
tm |= bits[Cube::SIDE_POSITIVE_Z] << 5;
|
||||
|
||||
// TODO Godot 4: we may replace this with a per-instance parameter so we can lift material access limitation
|
||||
_shader_material->set_shader_param(VoxelStringNames::get_singleton()->u_transition_mask, tm);
|
||||
}
|
||||
for (int dir = 0; dir < Cube::SIDE_COUNT; ++dir) {
|
||||
|
@ -1003,9 +1003,9 @@ void VoxelLodTerrain::_process() {
|
||||
{
|
||||
VOXEL_PROFILE_SCOPE();
|
||||
|
||||
for (size_t i = 0; i < _reception_buffers.data_output.size(); ++i) {
|
||||
for (size_t reception_index = 0; reception_index < _reception_buffers.data_output.size(); ++reception_index) {
|
||||
VOXEL_PROFILE_SCOPE();
|
||||
const VoxelServer::BlockDataOutput &ob = _reception_buffers.data_output[i];
|
||||
const VoxelServer::BlockDataOutput &ob = _reception_buffers.data_output[reception_index];
|
||||
|
||||
if (ob.type == VoxelServer::BlockDataOutput::TYPE_SAVE) {
|
||||
// That's a save confirmation event.
|
||||
|
@ -22,4 +22,5 @@ VoxelStringNames::VoxelStringNames() {
|
||||
block_unloaded = StaticCString::create("block_unloaded");
|
||||
|
||||
u_transition_mask = StaticCString::create("u_transition_mask");
|
||||
u_block_local_transform = StaticCString::create("u_block_local_transform");
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ public:
|
||||
StringName block_unloaded;
|
||||
|
||||
StringName u_transition_mask;
|
||||
StringName u_block_local_transform;
|
||||
};
|
||||
|
||||
#endif // VOXEL_STRING_NAMES_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user