MCPcopy Create free account
hub / github.com/Rust-GPU/rust-cuda / __raygen__render

Function __raygen__render

examples/cuda/gpu/path_tracer_gpu/src/optix.rs:102–155  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

100#[cfg(feature = "optix")]
101#[kernel]
102pub unsafe fn __raygen__render() {
103 let i = get_launch_index().xy();
104 let size = PARAMS.size;
105
106 let idx = i.x + i.y * size.x;
107
108 let rng = PARAMS.rand_states.add(idx as usize);
109 let offset = (*rng).normal_f32_2();
110 let mut cur_ray = generate_ray(Vec2::from(i.to_array()), &PARAMS.viewport, offset.into());
111
112 let mut attenuation = Vec3::one();
113 let mut color = Vec3::zero();
114
115 for _ in 0..MAX_BOUNCES {
116 let mut prd = PerRayData {
117 hit: false,
118 attenuation,
119 rand: rng,
120 scattered: None,
121 };
122
123 let (mut p0, mut p1) = pack_pointer(core::ptr::addr_of_mut!(prd));
124
125 raygen::trace(
126 PARAMS.handle,
127 (cur_ray.origin.into_array()).into(),
128 (cur_ray.dir.into_array()).into(),
129 0.001,
130 1e20,
131 0.0,
132 255,
133 RayFlags::empty(),
134 0,
135 1,
136 0,
137 [&mut p0, &mut p1],
138 );
139
140 if !prd.hit {
141 let miss_color = render::color(cur_ray);
142 color = attenuation * miss_color;
143 break;
144 }
145
146 if let Some(scatter) = prd.scattered {
147 cur_ray = scatter;
148 attenuation *= prd.attenuation;
149 } else {
150 break;
151 }
152 }
153
154 *PARAMS.image_buf.add(idx as usize) += color;
155}

Callers

nothing calls this directly

Calls 9

get_launch_indexFunction · 0.85
generate_rayFunction · 0.85
pack_pointerFunction · 0.85
traceFunction · 0.85
colorFunction · 0.85
addMethod · 0.80
normal_f32_2Method · 0.80
xyMethod · 0.45
into_arrayMethod · 0.45

Tested by

no test coverage detected