Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ if(MSVC)
-Wno-microsoft-enum-forward-reference")
endif()
if (NOT DEFINED CMAKE_CXX_FLAGS_ASAN OR CMAKE_CXX_FLAGS_ASAN STREQUAL "")
set(CMAKE_CXX_FLAGS_ASAN "/MTd /Zi /Od /RTC1 /fsanitize=address")
set(CMAKE_CXX_FLAGS_ASAN "/MTd /Zi /Od /RTC1 /fsanitize=address /analyze /WX /wd6993")
set(CMAKE_EXE_LINKER_FLAGS_ASAN "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /INCREMENTAL:NO")
endif()
if (NOT DEFINED CMAKE_CXX_FLAGS_TSAN OR CMAKE_CXX_FLAGS_TSAN STREQUAL "")
Expand Down
43 changes: 21 additions & 22 deletions internal/AtmosphereRef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,17 +520,17 @@ std::pair<Ray::Ref::fvec4, Ray::Ref::fvec4> Ray::Ref::IntegrateScatteringMain(
LutTransmittanceParamsToUv(params, local_height + params.planet_radius, view_zenith_cos_angle);
const fvec4 light_transmittance = SampleTransmittanceLUT(transmittance_lut, uv);

const fvec2 planet_intersection = PlanetIntersection(params, local_position, light_dir);
const float planet_shadow = planet_intersection.get<0>() > 0 ? 0.0f : 1.0f;
const fvec2 _planet_intersection = PlanetIntersection(params, local_position, light_dir);
const float planet_shadow = _planet_intersection.get<0>() > 0 ? 0.0f : 1.0f;

fvec4 multiscattered_lum = 0.0f;
if (!multiscatter_lut.empty()) {
fvec2 uv =
fvec2 _uv =
saturate(fvec2(view_zenith_cos_angle * 0.5f + 0.5f, local_height / params.atmosphere_height));
uv = fvec2(from_unit_to_sub_uvs(uv.get<0>(), SKY_MULTISCATTER_LUT_RES),
from_unit_to_sub_uvs(uv.get<1>(), SKY_MULTISCATTER_LUT_RES));
_uv = fvec2(from_unit_to_sub_uvs(_uv.get<0>(), SKY_MULTISCATTER_LUT_RES),
from_unit_to_sub_uvs(_uv.get<1>(), SKY_MULTISCATTER_LUT_RES));

multiscattered_lum = SampleMultiscatterLUT(multiscatter_lut, uv);
multiscattered_lum = SampleMultiscatterLUT(multiscatter_lut, _uv);
}

const fvec4 phase_times_scattering =
Expand All @@ -548,12 +548,12 @@ std::pair<Ray::Ref::fvec4, Ray::Ref::fvec4> Ray::Ref::IntegrateScatteringMain(

fvec4 multiscattered_lum = 0.0f;
if (!multiscatter_lut.empty()) {
fvec2 uv =
fvec2 _uv =
saturate(fvec2(view_zenith_cos_angle * 0.5f + 0.5f, local_height / params.atmosphere_height));
uv = fvec2(from_unit_to_sub_uvs(uv.get<0>(), SKY_MULTISCATTER_LUT_RES),
from_unit_to_sub_uvs(uv.get<1>(), SKY_MULTISCATTER_LUT_RES));
_uv = fvec2(from_unit_to_sub_uvs(_uv.get<0>(), SKY_MULTISCATTER_LUT_RES),
from_unit_to_sub_uvs(_uv.get<1>(), SKY_MULTISCATTER_LUT_RES));

multiscattered_lum = SampleMultiscatterLUT(multiscatter_lut, uv);
multiscattered_lum = SampleMultiscatterLUT(multiscatter_lut, _uv);
}

const fvec4 phase_times_scattering =
Expand Down Expand Up @@ -686,12 +686,12 @@ Ray::Ref::fvec4 Ray::Ref::IntegrateScattering(const atmosphere_params_t &params,
light_transmittance = SampleTransmittanceLUT(transmittance_lut, uv);

if (!multiscatter_lut.empty()) {
fvec2 uv = saturate(
fvec2 _uv = saturate(
fvec2(view_zenith_cos_angle * 0.5f + 0.5f, local_height / params.atmosphere_height));
uv = fvec2(from_unit_to_sub_uvs(uv.get<0>(), SKY_MULTISCATTER_LUT_RES),
from_unit_to_sub_uvs(uv.get<1>(), SKY_MULTISCATTER_LUT_RES));
_uv = fvec2(from_unit_to_sub_uvs(_uv.get<0>(), SKY_MULTISCATTER_LUT_RES),
from_unit_to_sub_uvs(_uv.get<1>(), SKY_MULTISCATTER_LUT_RES));

multiscattered_lum = SampleMultiscatterLUT(multiscatter_lut, uv);
multiscattered_lum = SampleMultiscatterLUT(multiscatter_lut, _uv);
}
}
{
Expand All @@ -701,12 +701,12 @@ Ray::Ref::fvec4 Ray::Ref::IntegrateScattering(const atmosphere_params_t &params,
moon_transmittance = SampleTransmittanceLUT(transmittance_lut, uv);

if (!multiscatter_lut.empty()) {
fvec2 uv = saturate(
fvec2 _uv = saturate(
fvec2(view_zenith_cos_angle * 0.5f + 0.5f, local_height / params.atmosphere_height));
uv = fvec2(from_unit_to_sub_uvs(uv.get<0>(), SKY_MULTISCATTER_LUT_RES),
from_unit_to_sub_uvs(uv.get<1>(), SKY_MULTISCATTER_LUT_RES));
_uv = fvec2(from_unit_to_sub_uvs(_uv.get<0>(), SKY_MULTISCATTER_LUT_RES),
from_unit_to_sub_uvs(_uv.get<1>(), SKY_MULTISCATTER_LUT_RES));

moon_multiscattered_lum = SampleMultiscatterLUT(multiscatter_lut, uv);
moon_multiscattered_lum = SampleMultiscatterLUT(multiscatter_lut, _uv);
}
}
}
Expand All @@ -724,8 +724,8 @@ Ray::Ref::fvec4 Ray::Ref::IntegrateScattering(const atmosphere_params_t &params,

if (light_dir.get<1>() > -0.025f) {
// main light contribution
const fvec2 planet_intersection = PlanetIntersection(params, local_position, light_dir);
const float planet_shadow = planet_intersection.get<0>() > 0 ? 0.0f : 1.0f;
const fvec2 _planet_intersection = PlanetIntersection(params, local_position, light_dir);
const float planet_shadow = _planet_intersection.get<0>() > 0 ? 0.0f : 1.0f;
const float cloud_shadow = TraceCloudShadow(params, rand_hash, local_position, light_dir);

clouds += total_transmittance *
Expand Down Expand Up @@ -970,8 +970,7 @@ void Ray::Ref::ShadeSky(const pass_settings_t &ps, const float limit, Span<const
}
} else if (sc.env.atmosphere.stars_brightness > 0.0f) {
// Use fake lightsource (to light up the moon)
const fvec4 light_dir = {0.0f, -1.0f, 0.0f, 0.0f},
light_col = {144809.859f, 129443.617f, 127098.89f, 0.0f};
const fvec4 light_dir = {0.0f, -1.0f, 0.0f, 0.0f}, light_col = {144809.859f, 129443.617f, 127098.89f, 0.0f};

color += IntegrateScattering(sc.env.atmosphere, fvec4{0.0f, sc.env.atmosphere.viewpoint_height, 0.0f, 0.0f},
I, MAX_DIST, light_dir, 0.0f, light_col, sc.sky_transmittance_lut,
Expand Down
5 changes: 5 additions & 0 deletions internal/BVHSplit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

#include "SmallVector.h"

#pragma warning(push)
#pragma warning(disable : 6262) // Function uses a lot of stack

namespace Ray {
const int BinningThreshold = 1024;
const int BinsCount = 256;
Expand Down Expand Up @@ -498,3 +501,5 @@ Ray::split_data_t Ray::SplitPrimitives_SAH(const prim_t *primitives, Span<const
{res_right_bounds.min, res_right_bounds.max}};
}
}

#pragma warning(pop)
7 changes: 6 additions & 1 deletion internal/Convolution.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

#include "../Types.h"

#pragma warning(push)
#pragma warning(disable : 6294) // Ill-defined for-loop

namespace Ray {
namespace NS {
void ClearBorders(const rect_t &rect, const int w, const int h, const bool downscaled, const int out_channels,
Expand Down Expand Up @@ -584,4 +587,6 @@ void ConvolutionConcat3x3(const float *restrict data1, const float *restrict dat
#undef index1
}
} // namespace NS
} // namespace Ray
} // namespace Ray

#pragma warning(pop)
60 changes: 33 additions & 27 deletions internal/CoreRef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#include "RadCacheRef.h"
#include "TextureStorageCPU.h"

#pragma warning(push)
#pragma warning(disable : 6326) // potential comparison of a constant with another constant

namespace Ray {
#define VECTORIZE_BBOX_INTERSECTION 1
#define VECTORIZE_TRI_INTERSECTION 1
Expand Down Expand Up @@ -51,8 +54,8 @@ force_inline void IntersectTri(const float ro[3], const float rd[3], const tri_a
force_inline void IntersectTri(const float ro[3], const float rd[3], const mtri_accel_t &tri, const uint32_t prim_index,
hit_data_t &inter) {
#if VECTORIZE_TRI_INTERSECTION
ivec4 _mask = 0, _prim_index;
fvec4 _t = inter.t, _u, _v;
ivec4 _mask = 0, _prim_index = 0;
fvec4 _t = inter.t, _u = 0.0f, _v = 0.0f;
for (int i = 0; i < 8; i += 4) {
fvec4 det = rd[0] * fvec4{&tri.n_plane[0][i], vector_aligned} +
rd[1] * fvec4{&tri.n_plane[1][i], vector_aligned} +
Expand Down Expand Up @@ -998,21 +1001,22 @@ void calc_lnode_importance(const light_wbvh_node_t &n, const fvec4 &P, float imp
}

void calc_lnode_importance(const light_cwbvh_node_t &n, const fvec4 &P, float importance[8]) {
// Unpack bounds
const float ext[3] = {(n.bbox_max[0] - n.bbox_min[0]) / 255.0f, (n.bbox_max[1] - n.bbox_min[1]) / 255.0f,
(n.bbox_max[2] - n.bbox_min[2]) / 255.0f};
alignas(16) float bbox_min[3][8], bbox_max[3][8];
for (int i = 0; i < 8; ++i) {
bbox_min[0][i] = bbox_min[1][i] = bbox_min[2][i] = -MAX_DIST;
bbox_max[0][i] = bbox_max[1][i] = bbox_max[2][i] = MAX_DIST;
if (n.ch_bbox_min[0][i] != 0xff || n.ch_bbox_max[0][i] != 0) {
bbox_min[0][i] = n.bbox_min[0] + n.ch_bbox_min[0][i] * ext[0];
bbox_min[1][i] = n.bbox_min[1] + n.ch_bbox_min[1][i] * ext[1];
bbox_min[2][i] = n.bbox_min[2] + n.ch_bbox_min[2][i] * ext[2];

bbox_max[0][i] = n.bbox_min[0] + n.ch_bbox_max[0][i] * ext[0];
bbox_max[1][i] = n.bbox_min[1] + n.ch_bbox_max[1][i] * ext[1];
bbox_max[2][i] = n.bbox_min[2] + n.ch_bbox_max[2][i] * ext[2];
{ // Unpack bounds
const float ext[3] = {(n.bbox_max[0] - n.bbox_min[0]) / 255.0f, (n.bbox_max[1] - n.bbox_min[1]) / 255.0f,
(n.bbox_max[2] - n.bbox_min[2]) / 255.0f};
for (int i = 0; i < 8; ++i) {
bbox_min[0][i] = bbox_min[1][i] = bbox_min[2][i] = -MAX_DIST;
bbox_max[0][i] = bbox_max[1][i] = bbox_max[2][i] = MAX_DIST;
if (n.ch_bbox_min[0][i] != 0xff || n.ch_bbox_max[0][i] != 0) {
bbox_min[0][i] = n.bbox_min[0] + n.ch_bbox_min[0][i] * ext[0];
bbox_min[1][i] = n.bbox_min[1] + n.ch_bbox_min[1][i] * ext[1];
bbox_min[2][i] = n.bbox_min[2] + n.ch_bbox_min[2][i] * ext[2];

bbox_max[0][i] = n.bbox_min[0] + n.ch_bbox_max[0][i] * ext[0];
bbox_max[1][i] = n.bbox_min[1] + n.ch_bbox_max[1][i] * ext[1];
bbox_max[2][i] = n.bbox_min[2] + n.ch_bbox_max[2][i] * ext[2];
}
}
}

Expand Down Expand Up @@ -1315,7 +1319,7 @@ Ray::Ref::fvec2 Ray::Ref::get_scrambled_2d_rand(const uint32_t dim, const uint32
rand_seq[shuffled_dim * 2 * RAND_SAMPLES_COUNT + 2 * shuffled_i + 1])};
}

void Ray::Ref::GeneratePrimaryRays(const camera_t &cam, const rect_t &r, const int w, const int h,
void Ray::Ref::GeneratePrimaryRays(const camera_t &cam, const rect_t &rect, const int w, const int h,
const uint32_t rand_seq[], const uint32_t rand_seed, const float filter_table[],
const int iteration, const uint16_t required_samples[],
aligned_vector<ray_data_t> &out_rays, aligned_vector<hit_data_t> &out_inters) {
Expand Down Expand Up @@ -1352,11 +1356,11 @@ void Ray::Ref::GeneratePrimaryRays(const camera_t &cam, const rect_t &r, const i
};

size_t i = 0;
out_rays.resize(size_t(r.w) * r.h);
out_inters.resize(size_t(r.w) * r.h);
out_rays.resize(size_t(rect.w) * rect.h);
out_inters.resize(size_t(rect.w) * rect.h);

for (int y = r.y; y < r.y + r.h; ++y) {
for (int x = r.x; x < r.x + r.w; ++x) {
for (int y = rect.y; y < rect.y + rect.h; ++y) {
for (int x = rect.x; x < rect.x + rect.w; ++x) {
if (required_samples && required_samples[y * w + x] < iteration) {
continue;
}
Expand Down Expand Up @@ -3496,9 +3500,9 @@ void Ray::Ref::SampleLightSource(const fvec4 &P, const fvec4 &T, const fvec4 &B,

void Ray::Ref::IntersectAreaLights(Span<const ray_data_t> rays, Span<const light_t> lights,
Span<const light_cwbvh_node_t> nodes, Span<hit_data_t> inout_inters) {
for (int i = 0; i < rays.size(); ++i) {
const ray_data_t &ray = rays[i];
hit_data_t &inout_inter = inout_inters[i];
for (int _i = 0; _i < rays.size(); ++_i) {
const ray_data_t &ray = rays[_i];
hit_data_t &inout_inter = inout_inters[_i];

const fvec4 ro = make_fvec3(ray.o);
const fvec4 rd = make_fvec3(ray.d);
Expand Down Expand Up @@ -3742,9 +3746,9 @@ void Ray::Ref::IntersectAreaLights(Span<const ray_data_t> rays, Span<const light

void Ray::Ref::IntersectAreaLights(Span<const ray_data_t> rays, Span<const light_t> lights,
Span<const light_wbvh_node_t> nodes, Span<hit_data_t> inout_inters) {
for (int i = 0; i < rays.size(); ++i) {
const ray_data_t &ray = rays[i];
hit_data_t &inout_inter = inout_inters[i];
for (int _i = 0; _i < rays.size(); ++_i) {
const ray_data_t &ray = rays[_i];
hit_data_t &inout_inter = inout_inters[_i];

const fvec4 ro = make_fvec3(ray.o);
const fvec4 rd = make_fvec3(ray.d);
Expand Down Expand Up @@ -4762,6 +4766,8 @@ void Ray::Ref::TraceShadowRays(Span<const shadow_ray_t> rays, int max_transp_dep
}
}

#pragma warning(pop)

#undef VECTORIZE_BBOX_INTERSECTION
#undef FORCE_TEXTURE_LOD
#undef USE_STOCH_TEXTURE_FILTERING
Loading