Skip to content

Commit

Permalink
feat: Texture blending (transparency)
Browse files Browse the repository at this point in the history
FIXES #56
  • Loading branch information
suspistew committed Mar 24, 2021
1 parent c3c5cb3 commit 9f6380c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 33 deletions.
30 changes: 8 additions & 22 deletions examples/tetris/main.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,20 @@
use scion::game_layer::{GameLayer, GameLayerController, SimpleGameLayer};
use scion::legion::{Resources, system, World};
use scion::rendering::bidimensional::{Camera2D, Material2D, Position2D, Transform2D};
use scion::rendering::bidimensional::components::Square;
use scion::Scion;
use scion::legion::{system, World, Resources};
use scion::game_layer::{SimpleGameLayer, GameLayer, GameLayerController};

#[system]
fn test(){
fn test() {
log::info!("Hello all");
}

#[derive(Default)]
struct LayerA{
tmp: usize
}
struct LayerA;

impl SimpleGameLayer for LayerA{
fn update(&mut self, _world: &mut World, resource: &mut Resources) {
log::info!("HeullohA...{}", self.tmp);
self.tmp += 1;
if self.tmp >= 301 {
resource.get_mut::<GameLayerController>().unwrap().pop_layer();
resource.get_mut::<GameLayerController>().unwrap().push_layer(GameLayer::strong::<LayerB>());
}
}
}

#[derive(Default)]
struct LayerB;
impl SimpleGameLayer for LayerA {
fn on_start(&mut self, world: &mut World, resource: &mut Resources) {

impl SimpleGameLayer for LayerB{
fn update(&mut self, _world: &mut World, _resource: &mut Resources) {
log::info!("HeullohB...");
}
}

Expand Down
16 changes: 11 additions & 5 deletions src/rendering/bidimensional/components/square.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use std::ops::Range;

use wgpu::{
util::BufferInitDescriptor, BindGroupLayout, Device, RenderPipeline, SwapChainDescriptor,
};
use wgpu::{util::BufferInitDescriptor, BindGroupLayout, Device, RenderPipeline, SwapChainDescriptor, BlendFactor, BlendOperation};

use crate::rendering::bidimensional::{
gl_representations::TexturedGlVertex, scion2d::Renderable2D, transform::Position2D,
Expand Down Expand Up @@ -98,8 +96,16 @@ impl Renderable2D for Square {
entry_point: "main",
targets: &[wgpu::ColorTargetState {
format: sc_desc.format,
alpha_blend: wgpu::BlendState::REPLACE,
color_blend: wgpu::BlendState::REPLACE,
alpha_blend: wgpu::BlendState {
src_factor: BlendFactor::One,
dst_factor: BlendFactor::One,
operation: BlendOperation::Add,
},
color_blend: wgpu::BlendState {
src_factor: BlendFactor::SrcAlpha,
dst_factor: BlendFactor::OneMinusSrcAlpha,
operation: BlendOperation::Add,
},
write_mask: wgpu::ColorWrite::ALL,
}],
}),
Expand Down
16 changes: 11 additions & 5 deletions src/rendering/bidimensional/components/triangle.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use std::ops::Range;

use wgpu::{
util::BufferInitDescriptor, BindGroupLayout, Device, RenderPipeline, SwapChainDescriptor,
};
use wgpu::{util::BufferInitDescriptor, BindGroupLayout, Device, RenderPipeline, SwapChainDescriptor, BlendFactor, BlendOperation};

use crate::rendering::bidimensional::{
gl_representations::TexturedGlVertex, scion2d::Renderable2D, transform::Position2D,
Expand Down Expand Up @@ -84,8 +82,16 @@ impl Renderable2D for Triangle {
entry_point: "main",
targets: &[wgpu::ColorTargetState {
format: sc_desc.format,
alpha_blend: wgpu::BlendState::REPLACE,
color_blend: wgpu::BlendState::REPLACE,
alpha_blend: wgpu::BlendState {
src_factor: BlendFactor::One,
dst_factor: BlendFactor::One,
operation: BlendOperation::Add,
},
color_blend: wgpu::BlendState {
src_factor: BlendFactor::SrcAlpha,
dst_factor: BlendFactor::OneMinusSrcAlpha,
operation: BlendOperation::Add,
},
write_mask: wgpu::ColorWrite::ALL,
}],
}),
Expand Down
2 changes: 1 addition & 1 deletion src/rendering/bidimensional/scion2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ fn get_default_color_attachment(frame: &SwapChainTexture) -> RenderPassColorAtta
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(wgpu::Color {
r: 0.,
r: 1.,
g: 0.,
b: 0.,
a: 1.0,
Expand Down

0 comments on commit 9f6380c

Please # to comment.