working on additive blending for determination of winding order. Saving here because this bug is very pretty

master
mitchellhansen 5 years ago
parent b3e092e25a
commit 5dde94cdf9

@ -7,7 +7,12 @@ layout(location = 0) in vec4 out_color;
layout(location = 0) out vec4 f_color;
void main() {
f_color = out_color;
if (int(out_color.w) % 2 == 0) {
f_color = out_color;
f_color.w = 255.0;
}
}

@ -10,6 +10,8 @@ layout(location = 0) out vec4 out_color;
void main() {
out_color = color;
gl_Position = vec4(v_position, 1.0);
}

@ -8,5 +8,13 @@ layout(location = 0) in vec4 out_color;
layout(location = 0) out vec4 f_color;
void main() {
f_color = out_color;
if (int(out_color.w) % 2 == 0) {
f_color = out_color;
f_color.w = 255.0;
}
//f_color = out_color;
}

@ -392,7 +392,7 @@ impl CanvasState {
let mut image_vertex_buffer: HashMap<Arc<CanvasImageHandle>, Vec<ImageVertex3D>> = HashMap::new();
let mut text_instances: HashMap<Arc<CanvasFontHandle>, Vec<TextVertex3D>> = HashMap::new();
let mut text_vertex_buffer: Vec<TextVertex3D> = Vec::new();
let mut text_vertex_buffer: Vec<ColorVertex3D> = Vec::new();
for value in canvas_frame.map {
match value {
@ -542,29 +542,58 @@ impl CanvasState {
}
}
self.dynamic_state = DynamicState {
line_width: None,
viewports: self.dynamic_state.viewports.clone(),
scissors: None,
compare_mask: Some(DynamicStencilValue {
face: StencilFaceFlags::StencilFrontAndBack,
value: 0xFF,
}),
write_mask: Some(DynamicStencilValue {
face: StencilFaceFlags::StencilFrontAndBack,
value: 0xFF,
}),
reference: Some(DynamicStencilValue {
face: StencilFaceFlags::StencilFrontAndBack,
value: 0xFF,
}),
};
// Text
let mut shader = self.shader_buffers.get(
self.get_shader_handle(String::from("simple_text"))
.unwrap().clone().get_handle() as usize
).unwrap();
//
// self.dynamic_state = DynamicState {
// line_width: None,
// viewports: self.dynamic_state.viewports.clone(),
// scissors: None,
// compare_mask: Some(DynamicStencilValue {
// face: StencilFaceFlags::StencilFrontAndBack,
// value: 0x00,
// }),
// write_mask: Some(DynamicStencilValue {
// face: StencilFaceFlags::StencilFrontAndBack,
// value: 0xFF,
// }),
// reference: Some(DynamicStencilValue {
// face: StencilFaceFlags::StencilFrontAndBack,
// value: 0x00,
// }),
// };
//
// if !allocated_buffers.text_vertex_buffer.is_empty() {
// command_buffer = command_buffer.draw(
// shader.get_pipeline().clone(),
// &self.dynamic_state.clone(),
// allocated_buffers.text_vertex_buffer.clone(),
// (), (),
// ).unwrap();
// }
//
// self.dynamic_state = DynamicState {
// line_width: None,
// viewports: self.dynamic_state.viewports.clone(),
// scissors: None,
// compare_mask: Some(DynamicStencilValue {
// face: StencilFaceFlags::StencilFrontAndBack,
// value: 0xFF,
// }),
// write_mask: Some(DynamicStencilValue {
// face: StencilFaceFlags::StencilFrontAndBack,
// value: 0x00,
// }),
// reference: Some(DynamicStencilValue {
// face: StencilFaceFlags::StencilFrontAndBack,
// value: 0x00,
// }),
// };
if !allocated_buffers.text_vertex_buffer.is_empty() {
command_buffer = command_buffer.draw(
@ -575,6 +604,7 @@ impl CanvasState {
).unwrap();
}
command_buffer
.end_render_pass()
.unwrap()

@ -17,6 +17,7 @@ use crate::canvas::managed::shader::generic_shader::GenericShader;
use crate::canvas::managed::shader::dynamic_vertex::RuntimeVertexDef;
use crate::canvas::managed::ShaderSpecializationConstants;
use crate::util::vertex::ColorVertex3D;
use vulkano::pipeline::blend::{LogicOp, AttachmentBlend, BlendOp, BlendFactor};
/// CanvasShader holds the pipeline and render pass for the input shader source
@ -80,19 +81,19 @@ impl CompiledShader for TextShader {
depth_write: true,
depth_bounds_test: DepthBounds::Disabled,
stencil_front: Stencil {
compare: Compare::Equal,
pass_op: StencilOp::IncrementAndWrap,
fail_op: StencilOp::DecrementAndClamp,
compare: Compare::NotEqual,
pass_op: StencilOp::Keep,
fail_op: StencilOp::IncrementAndWrap,
depth_fail_op: StencilOp::Keep,
compare_mask: None,
write_mask: None,
reference: None,
},
stencil_back: Stencil {
compare: Compare::Equal,
pass_op: StencilOp::Invert,
fail_op: StencilOp::Zero,
depth_fail_op: StencilOp::Zero,
compare: Compare::NotEqual,
pass_op: StencilOp::Keep,
fail_op: StencilOp::DecrementAndWrap,
depth_fail_op: StencilOp::Keep,
compare_mask: None,
write_mask: None,
reference: None,
@ -101,6 +102,21 @@ impl CompiledShader for TextShader {
let vertex_definition = RuntimeVertexDef::from_primitive(0);
let blend = AttachmentBlend {
enabled: true,
color_op: BlendOp::Add,
color_source: BlendFactor::SrcAlpha,
color_destination: BlendFactor::OneMinusSrcAlpha,
alpha_op: BlendOp::Add,
alpha_source: BlendFactor::SrcAlpha,
alpha_destination: BlendFactor::OneMinusSrcAlpha,
mask_red: true,
mask_green: true,
mask_blue: true,
mask_alpha: true,
};
TextShader {
graphics_pipeline:
Some(Arc::new(GraphicsPipeline::start()
@ -124,8 +140,9 @@ impl CompiledShader for TextShader {
third_constant: 0.0,
})
.depth_stencil(stencil)
.depth_stencil_simple_depth()
.blend_collective(blend)
.blend_logic_op(LogicOp::And)
// We have to indicate which subpass of which render pass this pipeline is going to be used
// in. The pipeline will only be usable from this particular subpass.
.render_pass(Subpass::from(render_pass.clone(), 0).unwrap())

@ -26,7 +26,7 @@ impl Text {
},
ColorVertex3D {
v_position: [-1.0, 1.0, normalized_depth],
color: [1.0, 1.0, 1.0, 1.0],
color: [1.0, 0.8, 1.0, 1.0],
},
ColorVertex3D {
v_position: [-0.25, 0.0, normalized_depth],
@ -34,7 +34,7 @@ impl Text {
},
ColorVertex3D {
v_position: [-0.25, 0.0, normalized_depth],
color: [1.0, 1.0, 1.0, 1.0],
color: [0.8, 1.0, 1.0, 1.0],
},
ColorVertex3D {
v_position: [-1.0, 1.0, normalized_depth],
@ -42,7 +42,7 @@ impl Text {
},
ColorVertex3D {
v_position: [0.0, 0.5, normalized_depth],
color: [1.0, 1.0, 1.0, 1.0],
color: [1.0, 1.0, 0.8, 1.0],
},
ColorVertex3D {
v_position: [0.25, 0.0, normalized_depth],
@ -50,7 +50,7 @@ impl Text {
},
ColorVertex3D {
v_position: [-1.0, 1.0, normalized_depth],
color: [1.0, 1.0, 1.0, 1.0],
color: [1.0, 0.8, 1.0, 1.0],
},
ColorVertex3D {
v_position: [0.0, 0.5, normalized_depth],
@ -119,7 +119,7 @@ impl Text {
};
Text {
verts: VertexTypes::ColorType(verts),
verts: VertexTypes::TextType(verts),
position: position,
size: size,
}

@ -56,7 +56,7 @@ pub enum VertexTypes {
ImageType(Vec<ImageVertex3D>, Arc<CanvasImageHandle>),
ColorType(Vec<ColorVertex3D>),
ThreeDType(Vec<Vertex3D>),
TextType(Vec<TextVertex3D>),
TextType(Vec<ColorVertex3D>),
}

Loading…
Cancel
Save