Update examples

This commit is contained in:
Nikita Lisitsa 2020-12-16 11:17:48 +03:00
parent d34d712fa3
commit 91f693ed6e
6 changed files with 76 additions and 61 deletions

View file

@ -16,9 +16,9 @@
#include <psemek/gfx/fullscreen.hpp>
#include <psemek/pcg/perlin.hpp>
#include <psemek/pcg/fractal.hpp>
#include <psemek/pcg/random/generator.hpp>
#include <psemek/pcg/random/device.hpp>
#include <psemek/pcg/random/uniform_sphere.hpp>
#include <psemek/random/generator.hpp>
#include <psemek/random/device.hpp>
#include <psemek/random/uniform_sphere.hpp>
#include <psemek/util/range.hpp>
#include <psemek/util/clock.hpp>
#include <psemek/async/threadpool.hpp>
@ -218,8 +218,8 @@ struct cloud_app
{
async::threadpool bg("bg");
pcg::generator rng(pcg::random_device{});
pcg::uniform_sphere_vector_distribution<float, 3> d;
random::generator rng(random::random_device{});
random::uniform_sphere_vector_distribution<float, 3> d;
std::vector<util::array<geom::vector<float, 3>, 3>> grad(4);
std::vector<float> weights(grad.size());

View file

@ -332,15 +332,22 @@ void deferred_app::present()
std::vector<gfx::deferred_renderer::object> objects;
gfx::deferred_renderer::material plane_material;
plane_material.color = gfx::color_4f{1.f, 1.f, 1.f, 1.f};
plane_material.casts_shadow = false;
{
gfx::deferred_renderer::object obj;
obj.mesh = &plane;
obj.pre_transform = geom::scale<float, 3>(10.f).affine_matrix();
obj.bbox = {{{-10.f, 10.f}, {-10.f, 10.f}, {0.f, 0.f}}};
obj.casts_shadow = false;
obj.mat = &plane_material;
objects.push_back(obj);
}
gfx::deferred_renderer::material cube_material;
cube_material.color = gfx::color_4f{1.f, 1.f, 1.f, 1.f};
for (float x : {-3.f, 3.f})
{
for (float y : {-3.f, 3.f})
@ -349,18 +356,23 @@ void deferred_app::present()
obj.mesh = &cube;
obj.pre_transform = geom::translation<float, 3>{geom::vector{x, y, 3.f}}.affine_matrix();
obj.bbox = {{{x - 1.f, x + 1.f}, {y - 1.f, y + 1.f}, {2.f, 4.f}}};
obj.mat = &cube_material;
objects.push_back(obj);
}
}
gfx::deferred_renderer::material sphere_material;
sphere_material.color = gfx::color_4f{1.f, 1.f, 1.f, 1.f};
sphere_material.specular.intensity = 4.f;
sphere_material.specular.shininess = 50.f;
for (float z : {2.f, 6.f})
{
gfx::deferred_renderer::object obj;
obj.mesh = &sphere;
obj.pre_transform = geom::translation<float, 3>{geom::vector{0.f, 0.f, z}}.affine_matrix();
obj.bbox = {{{-1.f, 1.f}, {-1.f, 1.f}, {z - 1.f, z + 1.f}}};
obj.mat.specular.intensity = 4.f;
obj.mat.specular.shininess = 50.f;
obj.mat = &sphere_material;
objects.push_back(obj);
}
@ -369,15 +381,14 @@ void deferred_app::present()
obj.mesh = &torus;
obj.pre_transform = geom::translation<float, 3>{geom::vector{0.f, 0.f, 4.f}}.affine_matrix();
obj.bbox = {{{-1.f, 1.f}, {-1.f, 1.f}, {4 - 0.2f, 4 + 0.2f}}};
obj.mat.specular.intensity = 4.f;
obj.mat.specular.shininess = 50.f;
obj.mat = &sphere_material;
objects.push_back(obj);
}
gfx::deferred_renderer::options options;
options.camera = &camera;
options.clear_color = geom::vector{0.f, 0.f, 0.1f, 1.f};
options.clear_color = geom::vector{0.f, 0.f, 0.1f};
options.ambient = {1.f, 1.f, 1.f};
options.directional_lights.emplace_back();
@ -414,16 +425,20 @@ void deferred_app::present()
l.min_shadow_distance = 0.1f;
}
for (auto const & l : options.point_lights)
std::vector<gfx::deferred_renderer::material> light_materials(options.point_lights.size());
for (std::size_t i = 0; i < options.point_lights.size(); ++i)
{
auto const & l = options.point_lights[i];
float const s = 0.1f;
gfx::deferred_renderer::object obj;
obj.mesh = &sphere;
obj.pre_transform = (geom::translation<float, 3>{l.position - geom::point<float, 3>::zero()}.transform() * geom::scale<float, 3>(s).transform()).affine_matrix();
obj.bbox = {{{l.position[0] - s, l.position[0] + s}, {l.position[1] - s, l.position[1] + s}, {l.position[2] - s, l.position[2] + s}}};
obj.mat.color = geom::vector{l.color[0], l.color[1], l.color[2], 1.f};
obj.mat.lit = false;
obj.casts_shadow = false;
light_materials[i].color = geom::vector{l.color[0], l.color[1], l.color[2], 1.f};
light_materials[i].lit = false;
light_materials[i].casts_shadow = false;
obj.mat = &light_materials[i];
objects.push_back(obj);
}

View file

@ -10,9 +10,9 @@
#include <psemek/geom/translation.hpp>
#include <psemek/geom/easing.hpp>
#include <psemek/geom/gradient.hpp>
#include <psemek/pcg/random/device.hpp>
#include <psemek/pcg/random/generator.hpp>
#include <psemek/pcg/random/uniform_sphere.hpp>
#include <psemek/random/device.hpp>
#include <psemek/random/generator.hpp>
#include <psemek/random/uniform_sphere.hpp>
#include <psemek/pcg/perlin.hpp>
#include <psemek/util/clock.hpp>
@ -169,8 +169,8 @@ candle_renderer::candle_renderer()
}
{
pcg::generator rng;
pcg::uniform_sphere_vector_distribution<float, 2> d;
random::generator rng;
random::uniform_sphere_vector_distribution<float, 2> d;
util::array<geom::vector<float, 2>, 2> grad({16, 16});
@ -198,8 +198,8 @@ candle_renderer::candle_renderer()
void candle_renderer::add(geom::point<float, 3> const & pos, geom::vector<float, 3> const & dir, float size)
{
pcg::generator rng{pcg::random_device{}};
pcg::uniform_sphere_vector_distribution<float, 2> d;
random::generator rng{random::random_device{}};
random::uniform_sphere_vector_distribution<float, 2> d;
geom::vector<float, 2> noise_offset;
while (true)
{

View file

@ -14,11 +14,11 @@
#include <psemek/geom/easing.hpp>
#include <psemek/geom/gradient.hpp>
#include <psemek/geom/permutation.hpp>
#include <psemek/pcg/random/device.hpp>
#include <psemek/pcg/random/generator.hpp>
#include <psemek/pcg/random/uniform_sphere.hpp>
#include <psemek/pcg/random/uniform_ball.hpp>
#include <psemek/pcg/random/uniform_box.hpp>
#include <psemek/random/device.hpp>
#include <psemek/random/generator.hpp>
#include <psemek/random/uniform_sphere.hpp>
#include <psemek/random/uniform_ball.hpp>
#include <psemek/random/uniform_box.hpp>
#include <psemek/pcg/perlin.hpp>
#include <psemek/pcg/sample.hpp>
#include <psemek/util/clock.hpp>
@ -211,8 +211,8 @@ struct grass_app
init_grass();
init_grass_slices();
pcg::generator rng;
pcg::uniform_sphere_vector_distribution<float, 2> d;
random::generator rng;
random::uniform_sphere_vector_distribution<float, 2> d;
util::array<geom::vector<float, 2>, 2> grad({size / 8 + 1, size / 8 + 1});
for (auto & v : grad) v = d(rng);
@ -233,7 +233,7 @@ struct grass_app
random_transform_index.resize({size, size});
for (auto & i : random_transform_index)
i = pcg::uniform_int_distribution<int>{0, 7}(rng);
i = random::uniform_int_distribution<int>{0, 7}(rng);
}
void init_ground()
@ -314,7 +314,7 @@ struct grass_app
grass_texture.generate_mipmap();
}
pcg::generator rng;
random::generator rng;
std::size_t memory = 0;
@ -322,11 +322,11 @@ struct grass_app
std::vector<vertex> vertices;
std::vector<geom::triangle<std::uint32_t>> triangles;
pcg::uniform_box_point_distribution<float, 2> d_origin({{{0.f, 1.f}, {0.f, 1.f}}});
pcg::uniform_sphere_vector_distribution<float, 2> d_orientation;
pcg::uniform_real_distribution<float> d_width{1.f / 64.f, 1.f / 128.f};
pcg::uniform_real_distribution<float> d_height{0.25f, 1.f};
pcg::uniform_real_distribution<float> d_density{0.f, 1.f};
random::uniform_box_point_distribution<float, 2> d_origin({{{0.f, 1.f}, {0.f, 1.f}}});
random::uniform_sphere_vector_distribution<float, 2> d_orientation;
random::uniform_real_distribution<float> d_width{1.f / 64.f, 1.f / 128.f};
random::uniform_real_distribution<float> d_height{0.25f, 1.f};
random::uniform_real_distribution<float> d_density{0.f, 1.f};
for (int blade = 0; blade < 4096; ++blade)
{
@ -346,7 +346,7 @@ struct grass_app
auto n = geom::ort(r);
auto color = pcg::uniform_real_distribution<float>{0.f, 1.f}(rng);
auto color = random::uniform_real_distribution<float>{0.f, 1.f}(rng);
float den = d_density(rng);

View file

@ -15,8 +15,8 @@
#include <psemek/async/event_loop.hpp>
#include <psemek/pcg/random/generator.hpp>
#include <psemek/pcg/random/uniform.hpp>
#include <psemek/random/generator.hpp>
#include <psemek/random/uniform.hpp>
#include <eigen3/Eigen/SVD>
#include <eigen3/Eigen/Householder>
@ -67,7 +67,7 @@ struct physics_2d_app
async::event_loop loop;
pcg::generator gen;
random::generator gen;
physics_2d_app()
: app("Physics 2D example", 4)
@ -174,7 +174,7 @@ struct physics_2d_app
physics.add_object(box_group, box_shape, material, {simulation_box.corner(0.5f, 0.9f) + geom::vector{dx, 0.f}, 0.f}, {});
// physics.add_object(ball_group, ball_shape, material, {simulation_box.corner(0.5f, 0.9f) + geom::vector{dx, 0.f}, 0.f}, {});
// float r = pcg::uniform_distribution<float>{0.05f, 0.5f}(gen);
// float r = random::uniform_distribution<float>{0.05f, 0.5f}(gen);
// auto new_shape = physics.add_shape(phys2d::ball{r});
// physics.add_object(ball_group, new_shape, material, {simulation_box.corner(0.5f, 0.9f) + geom::vector{dx, 0.f}, 0.f}, {});
// radiuses.push_back(r);

View file

@ -8,8 +8,8 @@
#include <psemek/gfx/color.hpp>
#include <psemek/geom/math.hpp>
#include <psemek/geom/interval.hpp>
#include <psemek/pcg/random/uniform.hpp>
#include <psemek/pcg/random/generator.hpp>
#include <psemek/random/uniform.hpp>
#include <psemek/random/generator.hpp>
#include <psemek/util/recursive.hpp>
#include <vector>
@ -175,10 +175,10 @@ tree_description generate(tree_species_description const & species, RNG && rng)
std::size_t id = result.branches.size();
result.branches.emplace_back();
float base_radius = pcg::uniform_distribution<float>{curve_desc.base_radius}(rng);
float base_radius = random::uniform_distribution<float>{curve_desc.base_radius}(rng);
base_radius = std::min(base_radius, min_radius);
int segment_count = pcg::uniform_distribution<int>{curve_desc.segment_count(h)}(rng);
int segment_count = random::uniform_distribution<int>{curve_desc.segment_count(h)}(rng);
segment_count = std::min(max_segments, segment_count);
float expected_height = segment_count * curve_desc.segment_length.center();
@ -190,9 +190,9 @@ tree_description generate(tree_species_description const & species, RNG && rng)
{
float t = (i + 1.f) / segment_count;
float length = pcg::uniform_real_distribution<float>{curve_desc.segment_length}(rng);
float length = random::uniform_real_distribution<float>{curve_desc.segment_length}(rng);
float lean = geom::rad(pcg::uniform_real_distribution<float>{curve_desc.lean_angle}(rng));
float lean = geom::rad(random::uniform_real_distribution<float>{curve_desc.lean_angle}(rng));
f.z = geom::axis_rotation<float>{f.x, lean}(f.z);
@ -201,7 +201,7 @@ tree_description generate(tree_species_description const & species, RNG && rng)
else if (curve_desc.up_tendency < 0.f)
f.z = geom::slerp(f.z, geom::vector{0.f, 0.f, -1.f}, - t * curve_desc.up_tendency);
float rotation = geom::rad(pcg::uniform_real_distribution<float>{curve_desc.rotation_angle}(rng));
float rotation = geom::rad(random::uniform_real_distribution<float>{curve_desc.rotation_angle}(rng));
f.x = geom::axis_rotation<float>{f.z, rotation}(f.x);
@ -216,11 +216,11 @@ tree_description generate(tree_species_description const & species, RNG && rng)
{
available_branching_length -= branching_distance;
int children_count = pcg::uniform_distribution<int>{curve_desc.branching_children_count}(rng);
int children_count = random::uniform_distribution<int>{curve_desc.branching_children_count}(rng);
for (int c = 0; c < children_count; ++c)
{
float angle = pcg::uniform_distribution<float>{curve_desc.branching_angle}(rng);
float angle = random::uniform_distribution<float>{curve_desc.branching_angle}(rng);
float rotation = 0;
if (children_count > 1)
@ -236,9 +236,9 @@ tree_description generate(tree_species_description const & species, RNG && rng)
child_f.z = geom::axis_rotation<float>{f.z, branching_rotation + rotation}(child_f.z);
child_f.x = geom::normalized(geom::cross(y, child_f.z));
float multiplier = pcg::uniform_distribution<float>{curve_desc.branching_size_multiplier}(rng);
float multiplier = random::uniform_distribution<float>{curve_desc.branching_size_multiplier}(rng);
float branching_distance = pcg::uniform_distribution<float>{children_desc.initial_branching_distance}(rng);
float branching_distance = random::uniform_distribution<float>{children_desc.initial_branching_distance}(rng);
self(child_f, children_desc, children_desc, level + 1,
geom::lerp(result.branches[id].nodes.back().radius, new_radius, branch_t) * multiplier,
@ -247,8 +247,8 @@ tree_description generate(tree_species_description const & species, RNG && rng)
branching_distance, 0.f);
}
branching_rotation += geom::rad(pcg::uniform_distribution<float>{curve_desc.branching_rotation}(rng));
branching_distance = pcg::uniform_distribution<float>{curve_desc.branching_distance}(rng);
branching_rotation += geom::rad(random::uniform_distribution<float>{curve_desc.branching_rotation}(rng));
branching_distance = random::uniform_distribution<float>{curve_desc.branching_distance}(rng);
}
branching_distance -= available_branching_length;
@ -258,13 +258,13 @@ tree_description generate(tree_species_description const & species, RNG && rng)
result.branches[id].nodes.push_back({f.pos, new_radius});
if (i + 1 < segment_count && pcg::uniform_distribution<float>{}(rng) < curve_desc.splitting_probability)
if (i + 1 < segment_count && random::uniform_distribution<float>{}(rng) < curve_desc.splitting_probability)
{
frame f1 = f;
frame f2 = f;
float a1 = geom::rad(pcg::uniform_distribution<float>{curve_desc.splitting_angle}(rng));
float a2 = geom::rad(pcg::uniform_distribution<float>{curve_desc.splitting_angle}(rng));
float a1 = geom::rad(random::uniform_distribution<float>{curve_desc.splitting_angle}(rng));
float a2 = geom::rad(random::uniform_distribution<float>{curve_desc.splitting_angle}(rng));
f1.z = geom::axis_rotation<float>{f.x, a1}(f1.z);
f2.z = geom::axis_rotation<float>{f.x, -a2}(f2.z);
@ -284,11 +284,11 @@ tree_description generate(tree_species_description const & species, RNG && rng)
starting_frame.z = {0.f, 0.f, 1.f};
starting_frame.x = {1.f, 0.f, 0.f};
float initial_orientation = pcg::uniform_distribution<float>{0.f, 2.f * geom::pi}(rng);
float initial_orientation = random::uniform_distribution<float>{0.f, 2.f * geom::pi}(rng);
starting_frame.x = geom::axis_rotation<float>{starting_frame.z, initial_orientation}(starting_frame.x);
generate_curve(starting_frame, species.trunk, species.branch, 0, std::numeric_limits<float>::infinity(), 1024, 0.f,
pcg::uniform_distribution<float>{species.trunk.initial_branching_distance}(rng), 0.f);
random::uniform_distribution<float>{species.trunk.initial_branching_distance}(rng), 0.f);
return result;
}
@ -350,7 +350,7 @@ struct tree_app
tree_app()
: app("Tree")
{
tree_desc = generate(species, pcg::generator{seed, 0ull});
tree_desc = generate(species, random::generator{seed, 0ull});
update_mesh();
setup_camera();
@ -506,7 +506,7 @@ void tree_app::on_key_down(SDL_Keycode key)
{
++seed;
tree_desc = generate(species, pcg::generator{std::uint64_t{seed}, 0ull});
tree_desc = generate(species, random::generator{std::uint64_t{seed}, 0ull});
update_mesh();
}
}