Skip to content

Commit 9a405bf

Browse files
committed
still can't fucking see anything....
1 parent c977d59 commit 9a405bf

File tree

7 files changed

+43
-46
lines changed

7 files changed

+43
-46
lines changed

Diff for: assets/shaders/myshader.wgsl

+6-9
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,23 @@
22
//! The default 3d Shader.
33
//!
44
#import bevy_pbr::forward_io::VertexOutput, FragmentOutput
5-
#import bevy_pbr::mesh_view_bindings::globals;
5+
#import bevy_pbr::mesh_view_bindings::globals, View
66
#import bevy_pbr::utils PI
77
#import shadplay::shader_utils::common NEG_HALF_PI, shader_toy_default, rotate2D
88

99
@group(0) @binding(0) var<uniform> view: View;
10-
@group(1) @binding(100)var<uniform> color: vec4f;
10+
@group(1) @binding(1)var<uniform> color: vec4f;
1111

12-
@group(1) @binding(101) var texture: texture_2d<f32>;
13-
@group(1) @binding(102) var texture_sampler: sampler;
12+
@group(1) @binding(2) var texture: texture_2d<f32>;
13+
@group(1) @binding(3) var texture_sampler: sampler;
1414

1515
const SPEED:f32 = 1.0;
1616

1717
@fragment
18-
fn fragment(in: VertexOutput) -> @location(0) vec4<f32> {
18+
fn fragment(in: VertexOutput) -> @location(0) vec4f {
1919
// ensure our uv coords match shadertoy/the-lil-book-of-shaders
2020
let texture_uvs = in.uv;
21-
2221
let tex: vec4f = textureSample(texture, texture_sampler, texture_uvs); // textureSample is provided by wgsl?
23-
24-
// return tex;
25-
return color;
22+
return tex;
2623

2724
}

Diff for: assets/shaders/myshader_2d.wgsl

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ fn fragment(mesh: VertexOutput) -> @location(0) vec4<f32> {
2222
uv.x *= resolution.x / resolution.y;
2323
uv *= rotate2D(NEG_HALF_PI);
2424

25-
return vec4f(shader_toy_default(t, uv), 1.0);
25+
return vec4f(shader_toy_default(t, uv), 0.3);
2626
}
2727

Diff for: src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
///
22
/// ShadPlay
33
///
4-
use bevy::{input::keyboard::KeyboardInput, prelude::*, window::WindowResized};
4+
use bevy::{prelude::*, window::WindowResized};
55

66
use shadplay::{plugin::ShadPlayPlugin, system::config::UserSession};
77

Diff for: src/plugin.rs

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pub struct ShadPlayPlugin;
1212
impl Plugin for ShadPlayPlugin {
1313
fn build(&self, app: &mut bevy::prelude::App) {
1414
app.insert_state(AppState::TwoD) // we start always in 2d mode
15+
// .insert_state(AppState::ThreeD)
1516
.add_plugins(ShadplayShaderLibrary) // Something of a library with common functions.
1617
.add_plugins(crate::system::ScreenshotPlugin) //NOTE: this is not Bevy's one!
1718
.add_plugins(ColourPickerPlugin)

Diff for: src/shader_utils/mod.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@ pub struct DragNDropShader {
1818
// ************************************ //
1919
/// The 3D shader.
2020
#[derive(Asset, AsBindGroup, TypePath, Debug, Clone)]
21-
// #[uuid = "a3d71c04-d054-4946-80f8-ba6cfbc90cad"]
2221
pub struct YourShader {
23-
#[uniform(100)]
22+
#[uniform(0)]
2423
pub color: LinearRgba, //RGBA
2524

26-
#[texture(101, dimension = "2d")]
27-
#[sampler(102)]
25+
#[texture(1, dimension = "2d")]
26+
#[sampler(2)]
2827
pub img: Handle<Image>,
2928
}
3029
// 3d impl
@@ -39,13 +38,12 @@ impl Material for YourShader {
3938
// ************************************ //
4039
/// The 2D shadertoy like shader
4140
#[derive(Asset, AsBindGroup, TypePath, Debug, Clone)]
42-
// #[uuid = "f528511f-dcf2-4b0b-9522-a9df3a1a795b"]
4341
pub struct YourShader2D {
44-
#[uniform(100)]
42+
#[uniform(0)]
4543
pub(crate) mouse_pos: MousePos,
4644

47-
#[texture(101, dimension = "2d")]
48-
#[sampler(102)]
45+
#[texture(1, dimension = "2d")]
46+
#[sampler(2)]
4947
pub img: Handle<Image>,
5048
}
5149

Diff for: src/system/config.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,10 @@ impl UserSession {
100100
Window {
101101
title: "shadplay".into(),
102102
resolution: self.window_dims.into(),
103-
transparent: true,
104-
decorations: self.decorations,
103+
// transparent: true,
104+
// decorations: self.decorations,
105+
transparent: false,
106+
decorations: true,
105107
// Mac only
106108
#[cfg(target_os = "macos")]
107109
composite_alpha_mode: CompositeAlphaMode::PostMultiplied,

Diff for: src/utils.rs

+24-25
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use bevy::{
55
};
66
use bevy_panorbit_camera::PanOrbitCamera;
77

8-
use crate::prelude::*;
8+
use crate::{prelude::*, shader_utils::YourShader};
99
/// State: Used to transition between 2d and 3d mode.
1010
/// Used by: cam_switch_system, screenshot
1111
#[derive(Debug, Clone, Copy, Default, Eq, PartialEq, Hash, States)]
@@ -186,7 +186,6 @@ pub fn switch_shape(
186186
mut commands: Commands,
187187
query: Query<Entity, With<Shape>>,
188188
) {
189-
info!("Switch shape system is running...");
190189
if input.just_pressed(KeyCode::KeyS) {
191190
info!("Shape change requested...");
192191
// Old
@@ -241,41 +240,41 @@ pub fn init_shapes(
241240
) {
242241
let texture: Handle<Image> = asset_server.load("textures/space.jpg");
243242
user_textures.insert(0, texture.clone());
244-
let mat = materials.add(crate::shader_utils::YourShader {
243+
let mat = materials.add(YourShader {
245244
color: Color::default().into(),
246245
img: texture.clone(),
247246
});
248247
info!("{texture:#?} (space.jpg) texture added!");
249248

250-
shape_options.0.push((
251-
false,
252-
Mesh3d(meshes.add(Mesh::from(Torus {
253-
major_radius: 2.,
254-
minor_radius: 0.2,
255-
}))),
256-
MeshMaterial3d(mat.clone_weak()),
257-
Transform::from_xyz(0.0, 0.3, 0.0),
258-
Shape,
259-
));
260-
info!("Torus added");
249+
// shape_options.0.push((
250+
// false,
251+
// Mesh3d(meshes.add(Mesh::from(Torus {
252+
// major_radius: 2.,
253+
// minor_radius: 0.2,
254+
// }))),
255+
// MeshMaterial3d(mat.clone()),
256+
// Transform::from_xyz(0.0, 0.3, 0.0),
257+
// Shape,
258+
// ));
259+
// info!("Torus added");
261260

262261
shape_options.0.push((
263262
true,
264-
Mesh3d(meshes.add(Mesh::from(Cuboid::new(1.85, 1.85, 1.85)))),
265-
MeshMaterial3d(mat.clone_weak()),
263+
Mesh3d(meshes.add(Mesh::from(Cuboid::default()))),
264+
MeshMaterial3d(mat.clone()),
266265
Transform::from_xyz(0.0, 0.3, 0.0),
267266
Shape,
268267
));
269268
info!("Cube added");
270269

271-
shape_options.0.push((
272-
false,
273-
Mesh3d(meshes.add(Sphere { radius: 1.40 })),
274-
MeshMaterial3d(mat.clone_weak()),
275-
Transform::from_xyz(0.0, 0.3, 0.0),
276-
Shape,
277-
));
278-
info!("Sphere added");
270+
// shape_options.0.push((
271+
// false,
272+
// Mesh3d(meshes.add(Sphere { radius: 1.40 })),
273+
// MeshMaterial3d(mat.clone()),
274+
// Transform::from_xyz(0.0, 0.3, 0.0),
275+
// Shape,
276+
// ));
277+
// info!("Sphere added");
279278

280279
info!("Shapes initialised!");
281280
}
@@ -286,7 +285,7 @@ pub fn setup_3d(mut commands: Commands, shape_options: Res<ShapeOptions>) {
286285
commands.spawn((
287286
Name::new("Cam3D"),
288287
Camera3d::default(),
289-
Transform::from_translation(Vec3::new(0.0, 1.5, 5.0)).looking_at(Vec3::ZERO, Vec3::Y),
288+
Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
290289
));
291290
info!("Spawned Cam3d");
292291

0 commit comments

Comments
 (0)