transparency for textures
This commit is contained in:
parent
e9f0dfde27
commit
49513bfbe9
@ -2,9 +2,9 @@ use std::sync::Arc;
|
|||||||
|
|
||||||
use bytemuck::{Pod, Zeroable};
|
use bytemuck::{Pod, Zeroable};
|
||||||
use wgpu::{include_wgsl, util::DeviceExt, BindGroup, Buffer, Device, Queue, RenderPipeline, Surface, SurfaceConfiguration, VertexBufferLayout};
|
use wgpu::{include_wgsl, util::DeviceExt, BindGroup, Buffer, Device, Queue, RenderPipeline, Surface, SurfaceConfiguration, VertexBufferLayout};
|
||||||
use winit::{event::{Event, WindowEvent}, window::Window};
|
use winit::{event::WindowEvent, window::Window};
|
||||||
|
|
||||||
use crate::{state::State, App};
|
use crate::state::State;
|
||||||
|
|
||||||
mod texture;
|
mod texture;
|
||||||
use texture::{Texture, TEXTURE_DIMENSIONS};
|
use texture::{Texture, TEXTURE_DIMENSIONS};
|
||||||
@ -14,14 +14,17 @@ use texture::{Texture, TEXTURE_DIMENSIONS};
|
|||||||
pub struct Vertex {
|
pub struct Vertex {
|
||||||
pub pos: [f32; 2],
|
pub pos: [f32; 2],
|
||||||
/// Rgba color by default but if texture flag is not set.
|
/// Rgba color by default but if texture flag is not set.
|
||||||
/// Else the first 2 f32 are texture coordinates and the 2 last are not important
|
/// Else the first 2 f32 are texture coordinates and the 2 last are not used
|
||||||
pub color: [f32; 4],
|
pub color: [f32; 4],
|
||||||
/// Each bit is used as a flag :
|
/// Each bit is used as a flag :
|
||||||
|
///
|
||||||
/// 1: Scaled and moved according to camera
|
/// 1: Scaled and moved according to camera
|
||||||
|
///
|
||||||
/// 2: Grayscale
|
/// 2: Grayscale
|
||||||
|
///
|
||||||
/// 4: Texture instead of color
|
/// 4: Texture instead of color
|
||||||
///
|
///
|
||||||
/// For exemple 0b01 corresponds to Scaled and 0b11 to Scaled and Grayscale
|
/// For example 0b001 corresponds to Scaled and 0b011 to Scaled and Grayscale
|
||||||
pub effect: u32,
|
pub effect: u32,
|
||||||
}
|
}
|
||||||
impl Vertex {
|
impl Vertex {
|
||||||
@ -205,7 +208,22 @@ impl<'a> Graphics<'a> {
|
|||||||
module: &shader,
|
module: &shader,
|
||||||
entry_point: "fs_main",
|
entry_point: "fs_main",
|
||||||
compilation_options: Default::default(),
|
compilation_options: Default::default(),
|
||||||
targets: &[Some(swapchain_format.into())],
|
targets: &[Some(wgpu::ColorTargetState {
|
||||||
|
format: swapchain_format,
|
||||||
|
blend: Some(wgpu::BlendState {
|
||||||
|
color: wgpu::BlendComponent {
|
||||||
|
src_factor: wgpu::BlendFactor::SrcAlpha,
|
||||||
|
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
|
||||||
|
operation: wgpu::BlendOperation::Add
|
||||||
|
},
|
||||||
|
alpha: wgpu::BlendComponent {
|
||||||
|
src_factor: wgpu::BlendFactor::One,
|
||||||
|
dst_factor: wgpu::BlendFactor::One,
|
||||||
|
operation: wgpu::BlendOperation::Add
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
write_mask: wgpu::ColorWrites::ALL,
|
||||||
|
})],
|
||||||
}),
|
}),
|
||||||
primitive: wgpu::PrimitiveState::default(),
|
primitive: wgpu::PrimitiveState::default(),
|
||||||
depth_stencil: None,
|
depth_stencil: None,
|
||||||
@ -265,27 +283,6 @@ impl<'a> Graphics<'a> {
|
|||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn event(&mut self, event: &Event<()>, window: &Window) {
|
|
||||||
match event {
|
|
||||||
Event::WindowEvent {
|
|
||||||
event: WindowEvent::Resized(new_size),
|
|
||||||
..
|
|
||||||
} => {
|
|
||||||
// Reconfigure the surface with the new size
|
|
||||||
self.surface_config.width = new_size.width;
|
|
||||||
self.surface_config.height = new_size.height;
|
|
||||||
self.surface.configure(&self.device, &self.surface_config);
|
|
||||||
// On macos the window needs to be redrawn manually after resizing
|
|
||||||
window.request_redraw();
|
|
||||||
},
|
|
||||||
Event::AboutToWait => {
|
|
||||||
// RedrawRequested will only trigger once unless we manually
|
|
||||||
// request it.
|
|
||||||
window.request_redraw();
|
|
||||||
},
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pub fn render(&self, state: &State) {
|
pub fn render(&self, state: &State) {
|
||||||
let frame = self.surface
|
let frame = self.surface
|
||||||
.get_current_texture()
|
.get_current_texture()
|
||||||
|
Loading…
Reference in New Issue
Block a user