ソースを参照

Does not work with more than 1 segment

Ghastrod 1 年間 前
コミット
0cdb66c910
4 ファイル変更25 行追加47 行削除
  1. 9 1
      src/lib.rs
  2. 1 1
      src/main.rs
  3. 14 44
      src/shaders/sky.wgsl
  4. 1 1
      src/sky/sky_pipeline.rs

+ 9 - 1
src/lib.rs

@@ -10,6 +10,7 @@ use winit::{
 };
 mod camera;
 mod object;
+mod sky;
 
 #[cfg(target_arch = "wasm32")]
 use wasm_bindgen::prelude::*;
@@ -33,6 +34,7 @@ struct State<'a> {
     num_vertices: u32,
     last_frame: Instant,
     frametime: f64,
+    //sky_pipeline: wgpu::RenderPipeline,
 }
 
 impl<'a> State<'a> {
@@ -107,7 +109,7 @@ impl<'a> State<'a> {
         
 
 
-        let plan1 = object::generate_plane(1,1,1.,1.);
+        let plan1 = object::generate_plane(2,2,1.,1.);
         let plan2 = plan1.clone();
         let vertex_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor{
             label: Some("Vertex Buffer 1"),
@@ -167,6 +169,8 @@ impl<'a> State<'a> {
         let last_frame = Instant::now();
         let delta = 0.2;
 
+        //let sky_pipeline = sky::sky_pipeline::new_sky_pipeline(&device, &config);
+
         Self {
             surface,
             vertex_buffer,
@@ -183,6 +187,7 @@ impl<'a> State<'a> {
             num_vertices: num_vertices,
             last_frame: last_frame,
             frametime: delta,
+            //sky_pipeline: sky_pipeline
         }
     }
 
@@ -238,6 +243,9 @@ impl<'a> State<'a> {
                 occlusion_query_set: None,
                 timestamp_writes: None,
             });
+            //render_pass.set_pipeline(&self.sky_pipeline);
+
+
             render_pass.set_pipeline(&self.render_pipeline);
             render_pass.set_vertex_buffer(0, self.vertex_buffer.slice(..));
             render_pass.set_bind_group(0, &self.camera_bind_group, &[]);

+ 1 - 1
src/main.rs

@@ -7,6 +7,6 @@ mod compute;
 mod sky;
 mod object;
 fn main() {
-    println!("Hello, world!");
+    println!("wgpu5 launched");
     pollster::block_on(run());
 }

+ 14 - 44
src/shaders/sky.wgsl

@@ -1,51 +1,21 @@
-struct Uniforms {
-  vec2 iResolution;  // Resolution of the screen
-  vec2 iMouse;       // Normalized mouse position (0.0 to 1.0)
+struct VertexOutput {
+    @builtin(position) clip_position: vec4<f32>,
 };
 
-fn getSky(uv: vec2<f32>) -> vec3<f32> {
-  let atmosphere = sqrt(1.0 - uv.y);
-  let skyColor = vec3<f32>(0.2, 0.4, 0.8);
-
-  let scatter = pow((uniforms.iMouse.y / uniforms.iResolution.y), 1.0 / 15.0);
-  let scatter = clamp(scatter, 0.8, 1.0);
-
-  let scatterColor = mix(vec3<f32>(1.0), vec3<f32>(1.0, 0.3, 0.0) * 1.5, scatter);
-  return mix(skyColor, scatterColor, atmosphere / 1.3);
-}
-
-fn getSun(uv: vec2<f32>) -> vec3<f32> {
-  let sun = 1.0 - distance(uv, uniforms.iMouse.xy / uniforms.iResolution.y);
-  let sun = clamp(sun, 0.0, 1.0);
-
-  let mut glow = sun;
-  glow = clamp(glow, 0.0, 1.0);
-
-  sun = pow(sun, 100.0);
-  sun *= 100.0;
-  sun = clamp(sun, 0.0, 1.0);
-
-  glow = pow(glow, 6.0) * 1.0;
-  glow = pow(glow, uv.y);
-  glow = clamp(glow, 0.0, 1.0);
-
-  sun *= pow(dot(uv.y, uv.y), 1.0 / 1.65);
-  glow *= pow(dot(uv.y, uv.y), 1.0 / 2.0);
-
-  sun += glow;
+struct VertexInput{
+  @location(0) position : vec3<f32>
+};
 
-  let sunColor = vec3<f32>(1.0, 0.6, 0.05) * sun;
-  return sunColor;
+@vertex
+fn vs_main(in: VertexInput) -> VertexOutput {
+  var output : VertexOutput;
+  output.clip_position = vec4<f32>(in.position, 1.0);
+  return output;
 }
 
-fn main_image(fragColor: out vec4<f32>, uv: in vec2<f32>) {
-  let sky = getSky(uv);
-  let sun = getSun(uv);
-
-  fragColor = vec4<f32>(sky + sun, 1.0);
-}
+@fragment
+fn fs_main() -> @location(0) vec4<f32> {
+  var color = smoothstep(0.0, 1.0, 0.5);
 
-// Entry point for the shader pipeline
-fn main() {
-  main_image(fragColor, gl_FragCoord.xy / uniforms.iResolution.y);
+  return vec4<f32>(color, 0.0, 0.0, 1.0); // red color
 }

+ 1 - 1
src/sky/sky_pipeline.rs

@@ -1,6 +1,6 @@
 use wgpu::{include_wgsl, RenderPipeline};
 
-pub fn new(device: &wgpu::Device, config: &wgpu::SurfaceConfiguration) -> RenderPipeline {
+pub fn new_sky_pipeline(device: &wgpu::Device, config: &wgpu::SurfaceConfiguration) -> RenderPipeline {
     let sky_shader = device.create_shader_module(include_wgsl!("../shaders/sky.wgsl"));
 
     let render_pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {