Ejemplo n.º 1
0
void sun_lightmap::generate(world_lightmap_access& data,
                                 const chunk_coordinates& pos,
                                 const surface& s, lightmap_hr &lightchunk,
                                 unsigned int phase) const
{
    trace((boost::format("for %1%") % world_vector(pos - world_chunk_center))
              .str());

    auto lmi = std::begin(lightchunk);

    for (faces f : s) {
        world_coordinates blk = pos * chunk_size + f.pos;

        for (int d(0); d < 6; ++d) {
            if (!f[d])
                continue;

            const ray_bundle& r = detail_levels_[phase][d];
            float light_level = recurse(r, r.weight, blk, data);
            lmi->sunlight = clamp(light_level, 0.0f, 1.0f) * 255.0f + 0.49f;
            ++lmi;
        }
    }
    assert(lmi == std::end(lightchunk));
    trace((boost::format("done with %1%")
           % world_vector(pos - world_chunk_center)).str());

}
Ejemplo n.º 2
0
std::set<world_vector>
shape::chunks() const
{
    std::set<world_vector> result;
    aabb<vec3i> span (cast_to<vec3i>(bounding_box()) >> cnkshift);
    for (auto p : range<vec3i>(span))
        result.insert(world_vector(p));

    return result;
}
lightmap&
ambient_occlusion_lightmap::generate (world_lightmap_access& data,
                                      const chunk_coordinates& pos,
                                      const surface& s,
                                      lightmap& lightchunk,
                                      unsigned int phase) const
{
    assert(phase < detail_levels_.size());
    trace("for %1%", world_vector(pos - world_chunk_center));

    auto lmi (std::begin(lightchunk));
    for (faces f : s)
    {
        world_coordinates blk (pos * chunk_size + f.pos);

        for (int d (0) ; d < 5; ++d)
        {
            if (f[d])
            {
                const ray_bundle& r (detail_levels_[phase][d]);
                float light_level (recurse(r, r.weight, blk, data));

                if (d < 4)
                    light_level += d * 0.05f;

                light_level = clamp(light_level, 0.0f, 1.0f);
                lmi->ambient = light_level * 15.4f;
                ++lmi;
            }
        }

        if (f[5])
        {
            lmi->ambient = 0;
            ++lmi;
        }
    }
    assert(lmi == std::end(lightchunk));
    trace("done with %1%", world_vector(pos - world_chunk_center));

    return lightchunk;
}
Ejemplo n.º 4
0
void soil_generator::generate(chunk_coordinates pos, chunk& dest)
{
    if (!w_.is_area_data_available(pos, surfacemap_))
    {
        std::cout << "No area data available for soil" << std::endl;
        return;
    }

    auto sm  (w_.get_area_data(pos, surfacemap_));

    chunk_coordinates bot ();
    auto region (w_.lock_region({pos + world_vector(0, 0, -1), pos}, *this));
    int16_t z_offset (convert_height_16bit(pos.z * chunk_size));

    for (uint32_t x (pos.x * chunk_size); x < (pos.x + 1) * chunk_size; ++x)
    {
        for (uint32_t y (pos.x * chunk_size); y < (pos.x + 1) * chunk_size; ++y)
        {
            int16_t lz ((*sm)(x, y));
            if (lz < z_offset || lz >= z_offset + chunk_size)
                continue;

            uint32_t z (water_level + lz);
            if (region(x,y,z) == (uint16_t)16)
            {
                if (lz >= 5)
                {
                    region(x,y,lz  ) = grass_;
                    region(x,y,lz-1) = dirt_;
                    region(x,y,lz-2) = rock_;
                }
                else
                {
                    region(x,y,lz  ) = sand_;
                    region(x,y,lz-1) = sand_;
                    region(x,y,lz-2) = rock_;
                }
            }
        }
    }
}
Ejemplo n.º 5
0
 vector rel_world_position(const world_coordinates& o) const
 {
     return vector(world_vector(position() - o)) + position_fraction();
 }