pub struct BasicColorModifiersBuffer(/* private fields */);Expand description
The basic color modifiers buffer for the BasicModifierBundle.
This buffer holds the data for basic color modifications, including RGB override or HSV modifications, alpha, contrast, exposure, and gamma adjustments.
Implementations§
Source§impl BasicColorModifiersBuffer
impl BasicColorModifiersBuffer
Sourcepub fn update(
&self,
queue: &Queue,
rgb_or_hsv: BasicColorRgbOverrideOrHsvModifiersPod,
alpha: f32,
contrast: f32,
exposure: f32,
gamma: f32,
)
pub fn update( &self, queue: &Queue, rgb_or_hsv: BasicColorRgbOverrideOrHsvModifiersPod, alpha: f32, contrast: f32, exposure: f32, gamma: f32, )
Update the basic color modifiers.
Examples found in repository?
examples/modify.rs (lines 123-133)
76async fn main() {
77 env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
78
79 let args = Args::parse();
80 let model_path = &args.model;
81
82 log::debug!("Creating wgpu instance");
83 let instance =
84 wgpu::Instance::new(wgpu::InstanceDescriptor::new_without_display_handle_from_env());
85
86 log::debug!("Requesting adapter");
87 let adapter = instance
88 .request_adapter(&wgpu::RequestAdapterOptions::default())
89 .await
90 .expect("adapter");
91
92 log::debug!("Requesting device");
93 let (device, queue) = adapter
94 .request_device(&wgpu::DeviceDescriptor {
95 label: Some("Device"),
96 required_limits: adapter.limits(),
97 ..Default::default()
98 })
99 .await
100 .expect("device");
101
102 log::debug!("Creating gaussians");
103 let gaussians = [
104 gs::core::GaussiansSource::Ply,
105 gs::core::GaussiansSource::Spz,
106 ]
107 .into_iter()
108 .find_map(|source| gs::core::Gaussians::read_from_file(model_path, source).ok())
109 .expect("gaussians");
110
111 log::debug!("Creating editor");
112 let editor = gs::Editor::<GaussianPod>::new(&device, &gaussians);
113
114 log::debug!("Creating basic modifier");
115 let basic_modifier = gs::BasicModifier::<GaussianPod>::new(
116 &device,
117 &editor.gaussians_buffer,
118 &editor.model_transform_buffer,
119 &editor.gaussian_transform_buffer,
120 );
121
122 log::debug!("Configuring modifiers");
123 basic_modifier.basic_color_modifiers_buffer.update(
124 &queue,
125 match args.override_rgb {
126 true => gs::BasicColorRgbOverrideOrHsvModifiersPod::new_rgb_override,
127 false => gs::BasicColorRgbOverrideOrHsvModifiersPod::new_hsv_modifiers,
128 }(Vec3::from_slice(&args.rgb_or_hsv)),
129 args.alpha,
130 args.contrast,
131 args.exposure,
132 args.gamma,
133 );
134
135 log::info!("Starting editing process");
136 let time = std::time::Instant::now();
137
138 log::debug!("Editing Gaussians");
139 let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor {
140 label: Some("Edit Encoder"),
141 });
142
143 editor.apply(
144 &device,
145 &mut encoder,
146 [&basic_modifier as &dyn gs::Modifier<GaussianPod>],
147 );
148
149 queue.submit(Some(encoder.finish()));
150
151 device
152 .poll(wgpu::PollType::wait_indefinitely())
153 .expect("poll");
154
155 log::info!("Editing process completed in {:?}", time.elapsed());
156
157 log::debug!("Downloading Gaussians");
158 let modified_gaussians = editor
159 .gaussians_buffer
160 .download_gaussians(&device, &queue)
161 .await
162 .map(|gs| {
163 match &args.output[args.output.len().saturating_sub(4)..] {
164 ".ply" => {
165 gs::core::Gaussians::Ply(gs::core::PlyGaussians::from_iter(gs.into_iter()))
166 }
167 ".spz" => {
168 gs::core::Gaussians::Spz(
169 gs::core::SpzGaussians::from_gaussians_with_options(
170 gs,
171 &gs::core::SpzGaussiansFromGaussianSliceOptions {
172 version: 2, // Version 2 is more widely supported as of now
173 ..Default::default()
174 },
175 )
176 .expect("SpzGaussians from gaussians"),
177 )
178 }
179 _ => panic!("Unsupported output file extension, expected .ply or .spz"),
180 }
181 })
182 .expect("gaussians download");
183
184 log::debug!("Writing modified Gaussians to output file");
185 modified_gaussians
186 .write_to_file(&args.output)
187 .expect("write modified Gaussians to output file");
188
189 log::info!("Modified Gaussians written to {}", args.output);
190}More examples
examples/modify_selection.rs (lines 200-210)
137async fn main() {
138 env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
139
140 let args = Args::parse();
141 let model_path = &args.model;
142 let pos = Vec3::from_slice(&args.pos);
143 let rot = Quat::from_slice(&args.rot);
144 let scale = Vec3::from_slice(&args.scale);
145 let shape = match args.shape {
146 Shape::Sphere => gs::SelectionBundle::<GaussianPod>::create_sphere_bundle,
147 Shape::Box => gs::SelectionBundle::<GaussianPod>::create_box_bundle,
148 };
149 let repeat = args.repeat;
150 let offset = Vec3::from_slice(&args.offset);
151
152 log::debug!("Creating wgpu instance");
153 let instance =
154 wgpu::Instance::new(wgpu::InstanceDescriptor::new_without_display_handle_from_env());
155
156 log::debug!("Requesting adapter");
157 let adapter = instance
158 .request_adapter(&wgpu::RequestAdapterOptions::default())
159 .await
160 .expect("adapter");
161
162 log::debug!("Requesting device");
163 let (device, queue) = adapter
164 .request_device(&wgpu::DeviceDescriptor {
165 label: Some("Device"),
166 required_limits: adapter.limits(),
167 ..Default::default()
168 })
169 .await
170 .expect("device");
171
172 log::debug!("Creating gaussians");
173 let gaussians = [
174 gs::core::GaussiansSource::Ply,
175 gs::core::GaussiansSource::Spz,
176 ]
177 .into_iter()
178 .find_map(|source| gs::core::Gaussians::read_from_file(model_path, source).ok())
179 .expect("gaussians");
180
181 log::debug!("Creating editor");
182 let editor = gs::Editor::<GaussianPod>::new(&device, &gaussians);
183
184 log::debug!("Creating shape selection compute bundle");
185 let shape_selection = shape(&device);
186
187 log::debug!("Creating basic selection modifier");
188 let mut basic_selection_modifier = gs::SelectionModifier::new_with_basic_modifier(
189 &device,
190 &editor.gaussians_buffer,
191 &editor.model_transform_buffer,
192 &editor.gaussian_transform_buffer,
193 vec![shape_selection],
194 );
195
196 log::debug!("Configuring modifiers");
197 basic_selection_modifier
198 .modifier
199 .basic_color_modifiers_buffer
200 .update(
201 &queue,
202 match args.override_rgb {
203 true => gs::BasicColorRgbOverrideOrHsvModifiersPod::new_rgb_override,
204 false => gs::BasicColorRgbOverrideOrHsvModifiersPod::new_hsv_modifiers,
205 }(Vec3::from_slice(&args.rgb_or_hsv)),
206 args.alpha,
207 args.contrast,
208 args.exposure,
209 args.gamma,
210 );
211
212 log::debug!("Creating shape selection buffers");
213 let shape_selection_buffers = (0..repeat)
214 .map(|i| {
215 let offset_pos = pos + offset * i as f32;
216 let buffer = gs::InvTransformBuffer::new(&device);
217 buffer.update_with_scale_rot_pos(&queue, scale, rot, offset_pos);
218 buffer
219 })
220 .collect::<Vec<_>>();
221
222 log::debug!("Creating shape selection bind groups");
223 let shape_selection_bind_groups = shape_selection_buffers
224 .iter()
225 .map(|buffer| {
226 basic_selection_modifier.selection.bundles[0]
227 .create_bind_group(
228 &device,
229 // index 0 is the Gaussians buffer, so we use 1,
230 // see docs of create_sphere_bundle or create_box_bundle
231 1,
232 [buffer.buffer().as_entire_binding()],
233 )
234 .expect("bind group")
235 })
236 .collect::<Vec<_>>();
237
238 log::debug!("Creating selection expression");
239 basic_selection_modifier.selection_expr = shape_selection_bind_groups.into_iter().fold(
240 gs::SelectionExpr::Identity,
241 |acc, bind_group| {
242 acc.union(gs::SelectionExpr::selection(
243 0, // the 0 here is the bundle index in the selection bundle
244 vec![bind_group],
245 ))
246 },
247 );
248
249 log::info!("Starting editing process");
250 let time = std::time::Instant::now();
251
252 log::debug!("Editing Gaussians");
253 let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor {
254 label: Some("Edit Encoder"),
255 });
256
257 editor.apply(
258 &device,
259 &mut encoder,
260 [&basic_selection_modifier as &dyn gs::Modifier<GaussianPod>],
261 );
262
263 queue.submit(Some(encoder.finish()));
264
265 device
266 .poll(wgpu::PollType::wait_indefinitely())
267 .expect("poll");
268
269 log::info!("Editing process completed in {:?}", time.elapsed());
270
271 log::debug!("Downloading Gaussians");
272 let modified_gaussians = editor
273 .gaussians_buffer
274 .download_gaussians(&device, &queue)
275 .await
276 .map(|gs| {
277 match &args.output[args.output.len().saturating_sub(4)..] {
278 ".ply" => {
279 gs::core::Gaussians::Ply(gs::core::PlyGaussians::from_iter(gs.into_iter()))
280 }
281 ".spz" => {
282 gs::core::Gaussians::Spz(
283 gs::core::SpzGaussians::from_gaussians_with_options(
284 gs,
285 &gs::core::SpzGaussiansFromGaussianSliceOptions {
286 version: 2, // Version 2 is more widely supported as of now
287 ..Default::default()
288 },
289 )
290 .expect("SpzGaussians from gaussians"),
291 )
292 }
293 _ => panic!("Unsupported output file extension, expected .ply or .spz"),
294 }
295 })
296 .expect("gaussians download");
297
298 log::debug!("Writing modified Gaussians to output file");
299 modified_gaussians
300 .write_to_file(&args.output)
301 .expect("write modified Gaussians to output file");
302
303 log::info!("Modified Gaussians written to {}", args.output);
304}Sourcepub fn update_with_pod(&self, queue: &Queue, pod: &BasicColorModifiersPod)
pub fn update_with_pod(&self, queue: &Queue, pod: &BasicColorModifiersPod)
Update the basic color modifiers buffer with BasicColorModifiersPod.
Trait Implementations§
Source§impl BufferWrapper for BasicColorModifiersBuffer
impl BufferWrapper for BasicColorModifiersBuffer
Source§const DEFAULT_USAGES: BufferUsages = _
const DEFAULT_USAGES: BufferUsages = _
The default usages.
Source§fn download<'life0, 'life1, 'life2, 'async_trait, T>(
&'life0 self,
device: &'life1 Device,
queue: &'life2 Queue,
) -> Pin<Box<dyn Future<Output = Result<Vec<T>, DownloadBufferError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: Send + Sync + 'async_trait,
T: 'async_trait + NoUninit + AnyBitPattern,
fn download<'life0, 'life1, 'life2, 'async_trait, T>(
&'life0 self,
device: &'life1 Device,
queue: &'life2 Queue,
) -> Pin<Box<dyn Future<Output = Result<Vec<T>, DownloadBufferError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: Send + Sync + 'async_trait,
T: 'async_trait + NoUninit + AnyBitPattern,
Download the buffer data into a
Vec.Source§fn prepare_download(
&self,
device: &Device,
encoder: &mut CommandEncoder,
) -> Buffer
fn prepare_download( &self, device: &Device, encoder: &mut CommandEncoder, ) -> Buffer
Prepare for downloading the buffer data. Read more
Source§fn map_download<'life0, 'life1, 'async_trait, T>(
download: &'life0 Buffer,
device: &'life1 Device,
) -> Pin<Box<dyn Future<Output = Result<Vec<T>, DownloadBufferError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
T: 'async_trait + NoUninit + AnyBitPattern,
Self: Send + 'async_trait,
fn map_download<'life0, 'life1, 'async_trait, T>(
download: &'life0 Buffer,
device: &'life1 Device,
) -> Pin<Box<dyn Future<Output = Result<Vec<T>, DownloadBufferError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
T: 'async_trait + NoUninit + AnyBitPattern,
Self: Send + 'async_trait,
Map the download buffer to read the buffer data. Read more
Source§fn map_download_with_poll_type<'life0, 'life1, 'async_trait, T>(
download: &'life0 Buffer,
device: &'life1 Device,
poll_type: PollType<SubmissionIndex>,
) -> Pin<Box<dyn Future<Output = Result<Vec<T>, DownloadBufferError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
T: 'async_trait + NoUninit + AnyBitPattern,
fn map_download_with_poll_type<'life0, 'life1, 'async_trait, T>(
download: &'life0 Buffer,
device: &'life1 Device,
poll_type: PollType<SubmissionIndex>,
) -> Pin<Box<dyn Future<Output = Result<Vec<T>, DownloadBufferError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
T: 'async_trait + NoUninit + AnyBitPattern,
Map the download buffer to read the buffer data with custom
wgpu::PollType. Read moreSource§impl Clone for BasicColorModifiersBuffer
impl Clone for BasicColorModifiersBuffer
Source§fn clone(&self) -> BasicColorModifiersBuffer
fn clone(&self) -> BasicColorModifiersBuffer
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for BasicColorModifiersBuffer
impl Debug for BasicColorModifiersBuffer
Source§impl FixedSizeBufferWrapper for BasicColorModifiersBuffer
impl FixedSizeBufferWrapper for BasicColorModifiersBuffer
Source§type Pod = BasicColorModifiersPod
type Pod = BasicColorModifiersPod
The POD element type that defines the layout/size.
Source§fn verify_buffer_size(
buffer: &Buffer,
) -> Result<(), FixedSizeBufferWrapperError>
fn verify_buffer_size( buffer: &Buffer, ) -> Result<(), FixedSizeBufferWrapperError>
Check if the given buffer matches the expected size. Read more
Source§fn download_single(
&self,
device: &Device,
queue: &Queue,
) -> impl Future<Output = Result<Self::Pod, DownloadBufferError>> + Send
fn download_single( &self, device: &Device, queue: &Queue, ) -> impl Future<Output = Result<Self::Pod, DownloadBufferError>> + Send
Download a single
FixedSizeBufferWrapper::Pod.Source§impl From<BasicColorModifiersBuffer> for Buffer
impl From<BasicColorModifiersBuffer> for Buffer
Source§fn from(wrapper: BasicColorModifiersBuffer) -> Self
fn from(wrapper: BasicColorModifiersBuffer) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl Freeze for BasicColorModifiersBuffer
impl !RefUnwindSafe for BasicColorModifiersBuffer
impl Send for BasicColorModifiersBuffer
impl Sync for BasicColorModifiersBuffer
impl Unpin for BasicColorModifiersBuffer
impl UnsafeUnpin for BasicColorModifiersBuffer
impl !UnwindSafe for BasicColorModifiersBuffer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more