Blend!
This commit is contained in:
parent
dff5745652
commit
cd96691c35
|
|
@ -3,11 +3,12 @@ use std::{collections::HashSet, time::Instant};
|
||||||
use glam::{mat4, vec2, vec3, vec4, Mat4, Quat, Vec2, Vec3};
|
use glam::{mat4, vec2, vec3, vec4, Mat4, Quat, Vec2, Vec3};
|
||||||
use glium::{
|
use glium::{
|
||||||
backend::{glutin::SimpleWindowBuilder, Facade},
|
backend::{glutin::SimpleWindowBuilder, Facade},
|
||||||
|
glutin::config::ConfigTemplateBuilder,
|
||||||
implement_vertex,
|
implement_vertex,
|
||||||
index::PrimitiveType,
|
index::PrimitiveType,
|
||||||
uniform,
|
uniform,
|
||||||
winit::event::{Event, WindowEvent},
|
winit::event::{Event, WindowEvent},
|
||||||
Program, Surface, VertexBuffer,
|
DrawParameters, Program, Surface, VertexBuffer,
|
||||||
};
|
};
|
||||||
use winit::{
|
use winit::{
|
||||||
event::ElementState,
|
event::ElementState,
|
||||||
|
|
@ -99,7 +100,9 @@ fn prepare_scene(display: &impl Facade) -> Vec<Wireframe> {
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let event_loop = EventLoop::builder().build().unwrap();
|
let event_loop = EventLoop::builder().build().unwrap();
|
||||||
|
let cfg = ConfigTemplateBuilder::new().with_multisampling(8);
|
||||||
let (window, display) = SimpleWindowBuilder::new()
|
let (window, display) = SimpleWindowBuilder::new()
|
||||||
|
.with_config_template_builder(cfg)
|
||||||
.with_title("Refraction: Wireframe")
|
.with_title("Refraction: Wireframe")
|
||||||
.build(&event_loop);
|
.build(&event_loop);
|
||||||
|
|
||||||
|
|
@ -178,7 +181,7 @@ fn main() {
|
||||||
* Mat4::from_translation(-cam_pos);
|
* Mat4::from_translation(-cam_pos);
|
||||||
|
|
||||||
let mut target = display.draw();
|
let mut target = display.draw();
|
||||||
target.clear_color(0.0, 0.0, 0.2, 1.0);
|
target.clear_color(0.0, 0.0, 0.0, 0.0);
|
||||||
|
|
||||||
let mvp = proj * view;
|
let mvp = proj * view;
|
||||||
let uniforms = uniform! {
|
let uniforms = uniform! {
|
||||||
|
|
@ -194,6 +197,22 @@ fn main() {
|
||||||
&Default::default(),
|
&Default::default(),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
let params = DrawParameters {
|
||||||
|
blend: glium::Blend {
|
||||||
|
color: glium::BlendingFunction::Addition {
|
||||||
|
source: glium::LinearBlendingFactor::One,
|
||||||
|
destination: glium::LinearBlendingFactor::OneMinusSourceAlpha,
|
||||||
|
},
|
||||||
|
alpha: glium::BlendingFunction::Addition {
|
||||||
|
source: glium::LinearBlendingFactor::One,
|
||||||
|
destination: glium::LinearBlendingFactor::OneMinusSourceAlpha,
|
||||||
|
},
|
||||||
|
constant_value: (0., 0., 0., 0.),
|
||||||
|
},
|
||||||
|
line_width: Some(3.),
|
||||||
|
smooth: Some(glium::Smooth::Nicest),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
for mesh in &scene {
|
for mesh in &scene {
|
||||||
let uniforms = uniform! {
|
let uniforms = uniform! {
|
||||||
mvp: mvp.to_cols_array_2d(),
|
mvp: mvp.to_cols_array_2d(),
|
||||||
|
|
@ -201,13 +220,7 @@ fn main() {
|
||||||
};
|
};
|
||||||
let indices = glium::index::NoIndices(mesh.mode);
|
let indices = glium::index::NoIndices(mesh.mode);
|
||||||
target
|
target
|
||||||
.draw(
|
.draw(&mesh.data, &indices, &program, &uniforms, ¶ms)
|
||||||
&mesh.data,
|
|
||||||
&indices,
|
|
||||||
&program,
|
|
||||||
&uniforms,
|
|
||||||
&Default::default(),
|
|
||||||
)
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
target.finish().unwrap();
|
target.finish().unwrap();
|
||||||
|
|
|
||||||
|
|
@ -5,5 +5,6 @@ in vec3 vertex_color;
|
||||||
out vec4 color;
|
out vec4 color;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
color = vec4(vertex_color, 1.0);
|
float opacity = pow(0.5 - 0.5 * gl_FragCoord.z, 0.25);
|
||||||
|
color = opacity * vec4(vertex_color, 1.0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user