forked from nannou-org/nannou
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
84d62f8
commit f821270
Showing
6 changed files
with
104 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#import bevy_pbr::{ | ||
mesh_view_bindings::view, | ||
mesh_view_bindings::globals, | ||
forward_io::VertexOutput, | ||
} | ||
|
||
@group(2) @binding(0) var texture: texture_2d<f32>; | ||
@group(2) @binding(1) var texture_sampler: sampler; | ||
|
||
@fragment | ||
fn fragment( | ||
mesh: VertexOutput, | ||
) -> @location(0) vec4<f32> { | ||
let resolution = view.viewport.zw; | ||
let time = globals.time; | ||
var uv = mesh.uv * resolution; | ||
let cp = -1.0 + 2.0 * uv / resolution; | ||
let cl = length(cp); | ||
uv = uv / resolution + (cp / cl) * cos(cl * 12.0 - time * 1.0) * 0.02; | ||
let clamped_uv = clamp(uv, vec2<f32>(0.0), vec2<f32>(1.0)); | ||
let col = textureSample(texture, texture_sampler, clamped_uv).xyz; | ||
return vec4<f32>(col, 1.0); | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
use nannou::noise::NoiseFn; | ||
use nannou::prelude::*; | ||
|
||
fn main() { | ||
nannou::app(model) | ||
// Register our custom material to make it available for use in our drawing | ||
.init_custom_material::<VideoMaterial>() | ||
.run(); | ||
} | ||
|
||
#[derive(Reflect)] | ||
struct Model { | ||
window: Entity, | ||
camera: Entity, | ||
video: Handle<Video>, | ||
} | ||
|
||
// This struct defines the data that will be passed to your shader | ||
#[derive(Asset, TypePath, AsBindGroup, Debug, Clone, Default)] | ||
struct VideoMaterial { | ||
#[texture(0)] | ||
#[sampler(1)] | ||
texture: Handle<Image>, | ||
} | ||
|
||
impl Material for VideoMaterial { | ||
fn fragment_shader() -> ShaderRef { | ||
"draw_video_material.wgsl".into() | ||
} | ||
} | ||
|
||
fn model(app: &App) -> Model { | ||
let camera = app.new_camera().build(); | ||
let window = app | ||
.new_window() | ||
.camera(camera) | ||
.primary() | ||
.size_pixels(1024, 512) | ||
.view(view) | ||
.build(); | ||
|
||
let video = app.asset_server().load_with_settings( | ||
"video/file_example_MP4_640_3MG.mp4", | ||
|settings: &mut VideoLoaderSettings| { | ||
settings | ||
.options | ||
.insert("hwaccel".to_string(), "sasfd".to_string()); | ||
}, | ||
); | ||
Model { | ||
window, | ||
camera, | ||
video, | ||
} | ||
} | ||
|
||
fn view(app: &App, model: &Model) { | ||
let Some(video) = app.assets().get(&model.video) else { | ||
return; | ||
}; | ||
|
||
let draw = app | ||
.draw() | ||
// Initialize our draw instance with our custom material | ||
.material(VideoMaterial { texture: video.texture.clone() }); | ||
|
||
draw.rect() | ||
.w_h(640.0, 400.0); | ||
} |