Skip to content

Commit

Permalink
support for new trees
Browse files Browse the repository at this point in the history
  • Loading branch information
gro-ove committed Oct 25, 2022
1 parent a391fc4 commit faa58cd
Show file tree
Hide file tree
Showing 15 changed files with 613 additions and 72 deletions.
14 changes: 13 additions & 1 deletion bakeryoptix/bake_ao_optix_prime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ static void dump_obj(const utils::path& filename, const std::vector<bake::Mesh*>
}
}

void bake::ao_optix_prime(const std::vector<Mesh*>& blockers, const AOSamples& ao_samples, const int rays_per_sample, const float albedo, const uint bounce_counts,
void bake::ao_optix_prime(const std::vector<Mesh*>& blockers,
const AOSamples& ao_samples, const int rays_per_sample, const float albedo, const uint bounce_counts,
const float scene_offset_scale_horizontal, const float scene_offset_scale_vertical, const float trees_light_pass_chance,
uint stack_size, size_t batch_size, bool debug_mode, float* ao_values)
{
Expand All @@ -178,6 +179,7 @@ void bake::ao_optix_prime(const std::vector<Mesh*>& blockers, const AOSamples& a
const auto hit_emissive = load_program(ctx, "rayhit_emissive", ptx_program_rayhit_emissive());
const auto anyhit = load_program(ctx, "rayanyhit", ptx_program_rayanyhit());
const auto anyhit_tree = load_program(ctx, "rayanyhit_tree", ptx_program_rayanyhit_tree());
const auto anyhit_proctree = load_program(ctx, "rayanyhit_proctree", ptx_program_rayanyhit_proctree());

auto mat_opaque = ctx->createMaterial();
mat_opaque->setClosestHitProgram(0, hit);
Expand All @@ -190,6 +192,10 @@ void bake::ao_optix_prime(const std::vector<Mesh*>& blockers, const AOSamples& a
mat_foliage->setAnyHitProgram(0, anyhit_tree);
mat_foliage->setClosestHitProgram(0, hit);

auto mat_proc_foliage = ctx->createMaterial();
mat_proc_foliage->setAnyHitProgram(0, anyhit_proctree);
mat_proc_foliage->setClosestHitProgram(0, hit);

auto mat_emissive = ctx->createMaterial();
mat_emissive->setClosestHitProgram(0, hit_emissive);

Expand Down Expand Up @@ -280,6 +286,11 @@ void bake::ao_optix_prime(const std::vector<Mesh*>& blockers, const AOSamples& a
mesh_instance->setMaterial(0, mat_opaque);
mesh_instance["parMaterialAlbedo"]->setFloat(0.2f);
}
else if (m->name == "trees")
{
mesh_instance->setMaterial(0, mat_proc_foliage);
mesh_instance["parMaterialAlbedo"]->setFloat(0.2f);
}
else if (m->name == "emissive")
{
mesh_instance->setMaterial(0, mat_emissive);
Expand Down Expand Up @@ -346,6 +357,7 @@ void bake::ao_optix_prime(const std::vector<Mesh*>& blockers, const AOSamples& a
ctx["bounceCounts"]->setUint(bounce_counts);
ctx["sceneOffsetHorizontal"]->setFloat(scene_offset_scale_horizontal);
ctx["sceneOffsetVertical"]->setFloat(scene_offset_scale_vertical);
ctx["rayDirAlign"]->setFloat(ao_samples.align_rays);
ctx["baseSeed"]->setUint(seed);
ctx["sqrtPasses"]->setInt(sqrt_rays_per_sample);

Expand Down
3 changes: 2 additions & 1 deletion bakeryoptix/bake_ao_optix_prime.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@

namespace bake
{
void ao_optix_prime(const std::vector<Mesh*>& blockers, const AOSamples& ao_samples, int rays_per_sample, float albedo, uint32_t bounce_counts,
void ao_optix_prime(const std::vector<Mesh*>& blockers,
const AOSamples& ao_samples, int rays_per_sample, float albedo, uint32_t bounce_counts,
float scene_offset_scale_horizontal, float scene_offset_scale_vertical, float trees_light_pass_chance,
uint32_t stack_size, size_t batch_size, bool debug_mode, float* ao_values);
}
7 changes: 4 additions & 3 deletions bakeryoptix/bake_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,17 @@
*/

#include <cassert>
#include <vector_types.h>
#include <optixu/optixu_matrix_namespace.h>

#include <utils/load_util.h>
#include <utils/vector_operations.h>
#include <bake_api.h>
#include <bake_filter.h>
#include <bake_filter_least_squares.h>
#include <assert.h>
#include <iostream>

#include <utils/load_util.h>
#include <utils/vector_operations.h>

using namespace optix;
using namespace bake;

Expand Down
16 changes: 15 additions & 1 deletion bakeryoptix/bake_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <vector>
#include <array>
#include <memory>
#include <vector_types.h>
#include <utils/std_ext.h>

// ReSharper disable once CppUnusedIncludeDirective
Expand Down Expand Up @@ -135,11 +136,22 @@ namespace bake
struct Vec3
{
float x, y, z;

Vec3 operator *(float v) const { return {x * v, y * v, z * v}; }
Vec3 operator +(const Vec3& v) const { return {x + v.x, y + v.y, z + v.z}; }
Vec3 operator -(const Vec3& v) const { return {x - v.x, y - v.y, z - v.z}; }
float operator &(const Vec3& v) const { return x * v.x + y * v.y + z * v.z; }
Vec3 normalize() { return *this * (1.f / sqrtf(*this & *this)); }
};

struct Vec4
{
float x, y, z, w;

Vec4 operator *(float v) const { return {x * v, y * v, z * v, w * v}; }
Vec4 operator +(const Vec4& v) const { return {x + v.x, y + v.y, z + v.z, w + v.w}; }
Vec4 operator -(const Vec4& v) const { return {x - v.x, y - v.y, z - v.z, w - v.w}; }
Vec4 operator &(const Vec4& v) const { return {x * v.x, y * v.y, z * v.z, w * v.w}; }
};

struct __declspec(align(4)) MeshVertex
Expand Down Expand Up @@ -274,9 +286,10 @@ namespace bake
Scene(const std::shared_ptr<Node>& root);
Scene(const std::vector<std::shared_ptr<Node>>& nodes);
Scene(std::vector<std::shared_ptr<Mesh>> receivers, SceneBlockers blockers);

std::vector<std::shared_ptr<Mesh>> receivers;
std::vector<Vec3> extra_receive_points;
std::vector<std::pair<Vec3, Vec3>> extra_receive_directed_points;
SceneBlockers blockers;

float bbox_min[3]{FLT_MAX, FLT_MAX, FLT_MAX};
Expand Down Expand Up @@ -311,6 +324,7 @@ namespace bake
float* sample_normals;
float* sample_face_normals;
SampleInfo* sample_infos;
float align_rays{};
};

enum VertexFilterMode
Expand Down
29 changes: 28 additions & 1 deletion bakeryoptix/bake_wrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ static void destroy_ao_samples(bake::AOSamples& ao_samples)
ao_samples.num_samples = 0;
}

baked_data bake_wrap::bake_scene(const std::shared_ptr<bake::Scene>& scene, const std::vector<std::shared_ptr<bake::Mesh>>& blockers,
baked_data bake_wrap::bake_scene(const std::shared_ptr<bake::Scene>& scene,
const std::vector<std::shared_ptr<bake::Mesh>>& blockers,
const bake_params& config, bool verbose)
{
#undef PERF
Expand Down Expand Up @@ -175,6 +176,24 @@ baked_data bake_wrap::bake_scene(const std::shared_ptr<bake::Scene>& scene, cons
sample_index++;
}
}
else if (!scene->extra_receive_directed_points.empty())
{
total_samples = scene->extra_receive_directed_points.size();
allocate_ao_samples(ao_samples, total_samples);
ao_samples.align_rays = 4.f;

auto sample_index = 0;
const auto sample_positions = reinterpret_cast<bake::Vec3*>(ao_samples.sample_positions);
const auto sample_norms = reinterpret_cast<bake::Vec3*>(ao_samples.sample_normals);
const auto sample_face_norms = reinterpret_cast<bake::Vec3*>(ao_samples.sample_face_normals);
for (const auto& p : scene->extra_receive_directed_points)
{
sample_positions[sample_index] = {p.first.x + config.sample_offset.x, p.first.y + config.sample_offset.y, p.first.z + config.sample_offset.z};
sample_norms[sample_index] = p.second;
sample_face_norms[sample_index] = p.second;
sample_index++;
}
}
else if (config.sample_on_points)
{
total_samples = 0;
Expand Down Expand Up @@ -259,6 +278,14 @@ baked_data bake_wrap::bake_scene(const std::shared_ptr<bake::Scene>& scene, cons
result.extra_points_ao[i] = ao_values[i];
}
}
else if (!scene->extra_receive_directed_points.empty())
{
result.extra_points_ao.resize(scene->extra_receive_directed_points.size());
for (auto i = 0U; i < scene->extra_receive_directed_points.size(); ++i)
{
result.extra_points_ao[i] = ao_values[i];
}
}
else if (config.sample_on_points)
{
auto index = 0U;
Expand Down
3 changes: 2 additions & 1 deletion bakeryoptix/bake_wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ struct bake_params {

struct bake_wrap final
{
static baked_data bake_scene(const std::shared_ptr<bake::Scene>& scene, const std::vector<std::shared_ptr<bake::Mesh>>& blockers,
static baked_data bake_scene(const std::shared_ptr<bake::Scene>& scene,
const std::vector<std::shared_ptr<bake::Mesh>>& blockers,
const bake_params& config, bool verbose = false);
};
4 changes: 4 additions & 0 deletions bakeryoptix/bakeryoptix.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@
<CompileOut Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutDir)%(Filename)%(Extension).ptx</CompileOut>
<NvccCompilation Condition="'$(Configuration)|$(Platform)'=='Release|x64'">ptx</NvccCompilation>
</CudaCompile>
<CudaCompile Include="rayanyhit_proctree.cu">
<CompileOut Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutDir)%(Filename)%(Extension).ptx</CompileOut>
<NvccCompilation Condition="'$(Configuration)|$(Platform)'=='Release|x64'">ptx</NvccCompilation>
</CudaCompile>
<CudaCompile Include="rayanyhit_tree.cu">
<CompileOut Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutDir)%(Filename)%(Extension).ptx</CompileOut>
<NvccCompilation Condition="'$(Configuration)|$(Platform)'=='Release|x64'">ptx</NvccCompilation>
Expand Down
1 change: 1 addition & 0 deletions bakeryoptix/bakeryoptix.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -986,5 +986,6 @@
<CudaCompile Include="rayanyhit.cu" />
<CudaCompile Include="rayanyhit_tree.cu" />
<CudaCompile Include="rayhit_emissive.cu" />
<CudaCompile Include="rayanyhit_proctree.cu" />
</ItemGroup>
</Project>

0 comments on commit faa58cd

Please sign in to comment.