// Copyright (c) 2023 Lachlan McDonald
// This work is licensed under the MIT License (MIT)
// https://github.com/lachlanmcdonald/magicavoxel-shaders
//
// xs flood2 [Height]
//
// xs_begin
// author : '@lmcdx.bsky.social'
// arg : { name = 'Height'  var = 'm_height'  range = '1 256'  value = '1'  step = '1'  precision = '0' }
// xs_end

float map(vec3 v) {
	float index = voxel(v);

	if (index == 0.0) {
		if (v.z < m_height) {
			for (float z = 0.0; z < v.z; z += 1.0) {
				if (voxel(vec3(v.x, v.y, z)) > 0.0) {
					return index;
				}
			}

			return i_color_index;
		}
	}

	return index;
}