diff --git a/src/effect/mod.rs b/src/effect/mod.rs index f1aff0f..f1399c1 100644 --- a/src/effect/mod.rs +++ b/src/effect/mod.rs @@ -338,26 +338,38 @@ impl EffectParamsCustom { } pub struct EffectParams { + pub frame: EffectParamInt, + pub framerate: EffectParamFloat, pub elapsed_time: EffectParamFloat, + pub elapsed_time_previous: EffectParamFloat, pub uv_size: EffectParamIVec2, pub custom: EffectParamsCustom, } impl EffectParams { pub fn stage_values(&mut self, graphics_context: &GraphicsContext) { + self.frame.stage_value(graphics_context); + self.framerate.stage_value(graphics_context); self.elapsed_time.stage_value(graphics_context); + self.elapsed_time_previous.stage_value(graphics_context); self.uv_size.stage_value(graphics_context); self.custom.stage_values(graphics_context); } pub fn assign_values(&mut self, graphics_context: &FilterContext) { + self.frame.assign_value(graphics_context); + self.framerate.assign_value(graphics_context); self.elapsed_time.assign_value(graphics_context); + self.elapsed_time_previous.assign_value(graphics_context); self.uv_size.assign_value(graphics_context); self.custom.assign_values(graphics_context); } pub fn enable_and_drop(self, graphics_context: &GraphicsContext) { + self.frame.enable_and_drop(graphics_context); + self.framerate.enable_and_drop(graphics_context); self.elapsed_time.enable_and_drop(graphics_context); + self.elapsed_time_previous.enable_and_drop(graphics_context); self.uv_size.enable_and_drop(graphics_context); self.custom.enable_and_drop(graphics_context); } diff --git a/src/effect_template.effect b/src/effect_template.effect index 9ac7853..46e6c07 100644 --- a/src/effect_template.effect +++ b/src/effect_template.effect @@ -1,7 +1,10 @@ uniform float4x4 ViewProj; uniform texture2d image; +uniform int builtin_frame; +uniform float builtin_framerate; uniform float builtin_elapsed_time; +uniform float builtin_elapsed_time_previous; uniform int2 builtin_uv_size; sampler_state builtin_texture_sampler { diff --git a/src/lib.rs b/src/lib.rs index 5e3ce65..6314c35 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -394,7 +394,10 @@ impl GlobalState { struct Data { source: SourceContext, effect: Option, + creation: Instant, + next_frame: u32, + elapsed_time_previous: Option, property_shader: PropertyDescriptor, property_shader_reload: PropertyDescriptor, @@ -410,6 +413,8 @@ impl Data { source, effect: None, creation: Instant::now(), + next_frame: 0, + elapsed_time_previous: None, property_shader: PropertyDescriptor { name: CString::new("shader").unwrap(), description: CString::new("The shader to use.").unwrap(), @@ -491,10 +496,20 @@ impl VideoTickSource for ScrollFocusFilter { return; }; + let frame = data.next_frame; + data.next_frame += 1; + let framerate = ObsVideoInfo::get().map(|info| info.framerate().as_f32()).unwrap_or(0.0); + let elapsed_time = data.creation.elapsed().as_secs_f32(); + let elapsed_time_previous = data.elapsed_time_previous.replace(elapsed_time) + .unwrap_or(elapsed_time); + if let Some(effect) = data.effect.as_mut() { let params = &mut effect.params; - params.elapsed_time.prepare_value(data.creation.elapsed().as_secs_f32()); + params.frame.prepare_value(frame as i32); + params.framerate.prepare_value(framerate); + params.elapsed_time.prepare_value(elapsed_time); + params.elapsed_time_previous.prepare_value(elapsed_time_previous); params.uv_size.prepare_value([ data.source.get_base_width() as i32, data.source.get_base_height() as i32, @@ -638,7 +653,10 @@ impl UpdateSource for ScrollFocusFilter { } let mut params = EffectParams { + frame: builtin_effect!("builtin_frame"), + framerate: builtin_effect!("builtin_framerate"), elapsed_time: builtin_effect!("builtin_elapsed_time"), + elapsed_time_previous: builtin_effect!("builtin_elapsed_time_previous"), uv_size: builtin_effect!("builtin_uv_size"), custom: Default::default(), };