Skip to content

Commit f35d26f

Browse files
committed
checkpoint
1 parent 8730f76 commit f35d26f

File tree

5 files changed

+109
-14
lines changed

5 files changed

+109
-14
lines changed

blender/pedestal.blend

32 KB
Binary file not shown.
0 Bytes
Binary file not shown.

crates/renderling/src/light.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ impl SpotLightCalculation {
223223
let frag_to_light = light_position - frag_position;
224224
let frag_to_light_distance = frag_to_light.length();
225225
if frag_to_light_distance == 0.0 {
226+
crate::println!("frag_to_light_distance: {frag_to_light_distance}");
226227
return Self::default();
227228
}
228229
let frag_to_light = frag_to_light.alt_norm_or_zero();

crates/renderling/src/light/cpu/test.rs

Lines changed: 102 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,13 @@ use crate::{
2525
light::{
2626
LightTile, LightTiling, LightTilingDescriptor, LightTilingInvocation, SpotLightCalculation,
2727
},
28-
math::{hex_to_vec4, scaled_f32_to_u8, ConstTexture, CpuTexture2d, GpuRng, NonAtomicSlab},
28+
math::{
29+
hex_to_vec4, scaled_f32_to_u8, ConstTexture, CpuTexture2d, CpuTexture2dArray, GpuRng,
30+
IsVector, NonAtomicSlab,
31+
},
2932
pbr::Material,
3033
prelude::Transform,
31-
stage::{Renderlet, Stage, Vertex},
34+
stage::{Renderlet, RenderletPbrVertexInfo, Stage, Vertex},
3235
};
3336

3437
use super::*;
@@ -736,6 +739,17 @@ fn pedestal() {
736739
.join("pedestal.glb"),
737740
)
738741
.unwrap();
742+
let materials = doc.materials.get_vec();
743+
log::info!("materials: {materials:#?}");
744+
doc.materials.set_item(
745+
0,
746+
Material {
747+
albedo_factor: Vec4::ONE,
748+
roughness_factor: 1.0,
749+
metallic_factor: 0.0,
750+
..Default::default()
751+
},
752+
);
739753
let camera = doc.cameras.first().unwrap();
740754
camera.camera.modify(|cam| {
741755
cam.set_projection(Mat4::perspective_rh(
@@ -747,9 +761,10 @@ fn pedestal() {
747761
});
748762

749763
let color = {
750-
let mut c = hex_to_vec4(0xEEDF7AFF);
751-
linear_xfer_vec4(&mut c);
752-
c
764+
// let mut c = hex_to_vec4(0xEEDF7AFF);
765+
// linear_xfer_vec4(&mut c);
766+
// c
767+
Vec4::ONE
753768
};
754769
let position = Vec3::new(0.0, 1.0, 0.0);
755770
let transform = stage.new_nested_transform();
@@ -790,14 +805,89 @@ fn pedestal() {
790805
..Default::default()
791806
})
792807
.build();
808+
{
809+
log::info!("adding spot light");
810+
let spot_desc = SpotLightDescriptor {
811+
position,
812+
direction: Vec3::NEG_Y,
813+
color,
814+
intensity: 5.0,
815+
..Default::default()
816+
};
817+
let spot = stage.new_analytical_light(spot_desc, None);
818+
snapshot(&ctx, &stage, "light/pedestal/spot.png");
793819

794-
let light_descriptor = PointLightDescriptor {
795-
position: Vec3::ZERO,
796-
color,
797-
intensity: 10.0,
798-
};
799-
let _light = stage.new_analytical_light(light_descriptor, Some(transform));
800-
snapshot(&ctx, &stage, "light/pedestal/point.png");
820+
let geometry_slab =
821+
futures_lite::future::block_on(stage.geometry.slab_allocator().read(..)).unwrap();
822+
823+
let renderlet = doc.renderlets_iter().next().unwrap();
824+
log::info!("renderlet: {renderlet:#?}");
825+
let mut info = RenderletPbrVertexInfo::default();
826+
827+
for vertex_index in 0..renderlet.get().vertices_array.len() {
828+
crate::stage::renderlet_vertex(
829+
renderlet.id(),
830+
vertex_index as u32,
831+
&geometry_slab,
832+
&mut Default::default(),
833+
&mut Default::default(),
834+
&mut Default::default(),
835+
&mut Default::default(),
836+
&mut Default::default(),
837+
&mut Default::default(),
838+
&mut Default::default(),
839+
&mut Default::default(),
840+
&mut Default::default(),
841+
&mut info,
842+
);
843+
844+
if info.out_pos.y == 0.0 {
845+
break;
846+
}
847+
}
848+
log::info!("info: {info:#?}");
849+
850+
let texture = ConstTexture::new(Vec4::ONE);
851+
let material_slab =
852+
futures_lite::future::block_on(stage.materials.slab_allocator().read(..)).unwrap();
853+
let lighting_slab =
854+
futures_lite::future::block_on(stage.lighting.slab_allocator().read(..)).unwrap();
855+
let mut fragment = Vec4::ZERO;
856+
crate::pbr::fragment_impl(
857+
&texture,
858+
&(),
859+
&texture,
860+
&(),
861+
&texture,
862+
&(),
863+
&texture,
864+
&(),
865+
&texture,
866+
&(),
867+
&geometry_slab,
868+
&material_slab,
869+
&lighting_slab,
870+
info.renderlet_id,
871+
info.out_color,
872+
info.out_uv0,
873+
info.out_uv1,
874+
info.out_norm,
875+
info.out_tangent,
876+
info.out_bitangent,
877+
info.out_pos,
878+
&mut fragment,
879+
);
880+
881+
log::info!("fragment: {fragment}");
882+
}
883+
884+
// let light_descriptor = PointLightDescriptor {
885+
// position: Vec3::ZERO,
886+
// color,
887+
// intensity: 10.0,
888+
// };
889+
// let _light = stage.new_analytical_light(light_descriptor, Some(transform));
890+
// snapshot(&ctx, &stage, "light/pedestal/point.png");
801891

802892
// light.transform.modify(|t| t.translation = position);
803893

crates/renderling/src/pbr.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ fn fresnel_schlick_roughness(cos_theta: f32, f0: Vec3, roughness: f32) -> Vec3 {
136136
}
137137

138138
#[allow(clippy::too_many_arguments)]
139-
fn outgoing_radiance(
139+
pub fn outgoing_radiance(
140140
light_color: Vec4,
141141
albedo: Vec3,
142142
attenuation: f32,
@@ -584,6 +584,7 @@ where
584584
let light_id = light_slab.read(analytical_lights_array.at(i));
585585
let light = light_slab.read(light_id);
586586
let transform = light_slab.read(light.transform_id);
587+
crate::println!("transform: {transform:?}");
587588
let transform = Mat4::from(transform);
588589

589590
// determine the light ray and the radiance
@@ -602,7 +603,7 @@ where
602603
continue;
603604
}
604605
let l = frag_to_light.alt_norm_or_zero();
605-
let attenuation = intensity * 1.0 / (distance * distance);
606+
let attenuation = intensity / (distance * distance);
606607
let radiance =
607608
outgoing_radiance(color, albedo, attenuation, v, l, n, metallic, roughness);
608609
let shadow = if light.shadow_map_desc_id.is_some() {
@@ -624,6 +625,7 @@ where
624625
let spot_light_descriptor = light_slab.read(light.into_spot_id());
625626
let calculation =
626627
SpotLightCalculation::new(spot_light_descriptor, transform, in_pos);
628+
crate::println!("calculation: {calculation:#?}");
627629
if calculation.frag_to_light_distance == 0.0 {
628630
continue;
629631
}
@@ -672,6 +674,8 @@ where
672674
(radiance, shadow)
673675
}
674676
};
677+
crate::println!("radiance: {radiance}");
678+
crate::println!("shadow: {shadow}");
675679
lo += radiance * (1.0 - shadow);
676680
}
677681

0 commit comments

Comments
 (0)