diff --git a/scenes/sun.json b/scenes/sun.json index 9bd6c8e87..cb97de323 100644 --- a/scenes/sun.json +++ b/scenes/sun.json @@ -1,7 +1,8 @@ { "technique": { "type": "path", - "max_depth": 64 + "max_depth": 64, + "nee": true }, "camera": { "type": "perspective", @@ -43,6 +44,6 @@ {"name":"Pillar","shape":"Pillar", "bsdf":"mat-Pillar", "transform": [ 0.25,0,0,0, 0,0.5,0,-1, 0,0,0.25,0, 0,0,0,1 ]} ], "lights": [ - {"type":"directional", "name":"Sun", "radius": 100, "direction": [1, -0.25, 0]} + {"type":"sun", "name":"Sun", "direction": [1, -0.25, 0]} ] } diff --git a/src/artic/light/perez.art b/src/artic/light/perez.art index 3f0d2b4b4..a462d533d 100644 --- a/src/artic/light/perez.art +++ b/src/artic/light/perez.art @@ -335,7 +335,7 @@ fn @make_perez_light_from_model(id: i32, scene_bbox: BBox, sun_dir: Vec3, tint_c color_add(if has_sun && model.clearness > 1 { color_mulf(sun_color, math_builtins::fabs(sin_altitude) / flt_pi) } else { color_builtins::black }, color_mulf(zenith, normfactor))); - let actual_sun = if model.clearness > 1 { color_mulf(sun_color, sun_factor) } else { color_builtins::black }; + let actual_sun = if has_sun && model.clearness > 1 { color_mulf(sun_color, sun_factor) } else { color_builtins::black }; make_perez_light_raw(id, scene_bbox, sun_dir, sky_color, actual_ground, math_builtins::cos(rad(flt_sun_radius_deg / 2)), actual_sun, model.params, has_ground, has_sun, transform) diff --git a/src/artic/light/sun.art b/src/artic/light/sun.art index ac6a5242e..d7da7d130 100644 --- a/src/artic/light/sun.art +++ b/src/artic/light/sun.art @@ -3,7 +3,7 @@ static flt_sun_radius_deg = 0.533:f32; // Sun solid angle seen from earth given fn @sun_cos_angle_from_radius(radius: f32) = 1 / math_builtins::sqrt(radius * radius + 1); // cos(atan(R)) fn @sun_radius_from_cos_angle(cos_angle: f32) = math_builtins::sqrt(1 - cos_angle * cos_angle) / cos_angle; // tan(acos(C)) -fn @make_sun_light(id: i32, sun_dir: Vec3, scene_bbox: BBox, cos_sun_angle: f32, color: Color, handle_as_delta: bool) -> Light { +fn @make_sun_light(id: i32, sun_dir: Vec3 /* Scene to Light */, scene_bbox: BBox, cos_sun_angle: f32, color: Color, handle_as_delta: bool) -> Light { let scene_radius = bbox_radius(scene_bbox) * 1.01; let frame = make_orthonormal_mat3x3(sun_dir); let sun_radius = sun_radius_from_cos_angle(cos_sun_angle); @@ -11,7 +11,7 @@ fn @make_sun_light(id: i32, sun_dir: Vec3, scene_bbox: BBox, cos_sun_angle: f32, let dir_pdf = uniform_cone_pdf(cos_sun_angle); - fn @check_if_hit(gdir: Vec3) = mat3x3_left_mul(frame, gdir).z <= cos_sun_angle; + fn @check_if_hit(gdir: Vec3) = vec3_dot(sun_dir, gdir) >= cos_sun_angle; Light { id = id, @@ -26,18 +26,14 @@ fn @make_sun_light(id: i32, sun_dir: Vec3, scene_bbox: BBox, cos_sun_angle: f32, let (pos, pos_pdf) = env_sample_pos(rnd, ndir, bbox_center(scene_bbox), scene_radius); make_emission_sample(pos, vec3_neg(ndir), color_mulf(color, safe_div(1, pos_pdf * sun_area * sample.pdf)), pos_pdf, sun_area * sample.pdf, sample.dir.z) }, - emission = @ |ctx| { - if handle_as_delta { - color_builtins::black + emission = @ |ctx| { + if !handle_as_delta && check_if_hit(ctx.ray.dir) { + color } else { - if check_if_hit(ctx.ray.dir) { - color - } else { - color_builtins::black - } + color_builtins::black } }, - pdf_direct = @ |ray, _| { + pdf_direct = @ |ray, _| { if handle_as_delta { make_delta_pdf() } else { diff --git a/src/runtime/light/PerezLight.cpp b/src/runtime/light/PerezLight.cpp index 8adcf5060..e9f22e223 100644 --- a/src/runtime/light/PerezLight.cpp +++ b/src/runtime/light/PerezLight.cpp @@ -69,9 +69,9 @@ void PerezLight::serialize(const SerializationInput& input) const << ", " << LoaderUtils::inlineSceneBBox(input.Tree.context()); if (mLight->hasProperty("direction")) - input.Stream << ", " << input.Tree.getInline("direction"); + input.Stream << ", vec3_normalize(" << input.Tree.getInline("direction") << ")"; else - input.Stream << ", " << LoaderUtils::inlineVector(mSunDirection); + input.Stream << ", vec3_normalize(" << LoaderUtils::inlineVector(mSunDirection) << ")"; input.Stream << ", " << input.Tree.getInline("color") << ", " << input.Tree.getInline("ground"); @@ -93,7 +93,7 @@ void PerezLight::serialize(const SerializationInput& input) const << ", " << (mHasSun ? "true" : "false"); if (mLight->hasProperty("up")) { - input.Stream << ", make_cie_sky_transform(" << input.Tree.getInline("up") << ")"; + input.Stream << ", make_cie_sky_transform(vec3_normalize(" << input.Tree.getInline("up") << "))"; } else { const Matrix3f trans = mLight->property("transform").getTransform().linear().transpose().inverse(); input.Stream << ", " << LoaderUtils::inlineMatrix(trans); diff --git a/src/runtime/light/SunLight.cpp b/src/runtime/light/SunLight.cpp index ba70dbd64..395aa803c 100644 --- a/src/runtime/light/SunLight.cpp +++ b/src/runtime/light/SunLight.cpp @@ -44,9 +44,9 @@ void SunLight::serialize(const SerializationInput& input) const << " let light_" << light_id << " = make_sun_light(" << input.ID; if (mLight->hasProperty("direction")) - input.Stream << ", " << input.Tree.getInline("direction"); + input.Stream << ", vec3_normalize(" << input.Tree.getInline("direction") << ")"; else - input.Stream << ", " << LoaderUtils::inlineVector(mDirection); + input.Stream << ", vec3_normalize(" << LoaderUtils::inlineVector(mDirection) << ")"; input.Stream << ", " << LoaderUtils::inlineSceneBBox(input.Tree.context());