From b269723254d50a7f1b57f6c4f4dc9a9b1af77ca1 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Tue, 4 Feb 2020 21:50:13 -0800 Subject: [PATCH] Switch to per-pixel texture lookup for paints. This is a prerequisite for supporting gradients and images. --- Cargo.lock | 1 + color/src/lib.rs | 2 +- content/Cargo.toml | 3 + content/src/dash.rs | 2 +- content/src/gradient.rs | 36 ++ content/src/lib.rs | 2 + {renderer => content}/src/sorted_vector.rs | 4 +- demo/common/src/renderer.rs | 8 +- renderer/src/gpu/renderer.rs | 419 +++++------------- renderer/src/lib.rs | 1 - renderer/src/tiles.rs | 6 +- resources/shaders/gl3/tile_alpha.fs.glsl | 10 +- resources/shaders/gl3/tile_alpha.vs.glsl | 48 ++ resources/shaders/gl3/tile_solid.fs.glsl | 7 +- resources/shaders/gl3/tile_solid.vs.glsl | 31 ++ resources/shaders/metal/tile_alpha.fs.metal | 13 +- resources/shaders/metal/tile_alpha.vs.metal | 55 +++ resources/shaders/metal/tile_solid.fs.metal | 12 +- resources/shaders/metal/tile_solid.vs.metal | 34 ++ shaders/Makefile | 10 +- shaders/tile_alpha.fs.glsl | 10 +- ...pha_vertex.inc.glsl => tile_alpha.vs.glsl} | 22 +- shaders/tile_alpha_monochrome.vs.glsl | 22 - shaders/tile_alpha_multicolor.vs.glsl | 22 - shaders/tile_monochrome.inc.glsl | 15 - shaders/tile_multicolor.inc.glsl | 18 - shaders/tile_solid.fs.glsl | 7 +- ...lid_vertex.inc.glsl => tile_solid.vs.glsl} | 15 +- shaders/tile_solid_monochrome.vs.glsl | 22 - shaders/tile_solid_multicolor.vs.glsl | 22 - 30 files changed, 389 insertions(+), 490 deletions(-) create mode 100644 content/src/gradient.rs rename {renderer => content}/src/sorted_vector.rs (95%) create mode 100644 resources/shaders/gl3/tile_alpha.vs.glsl create mode 100644 resources/shaders/gl3/tile_solid.vs.glsl create mode 100644 resources/shaders/metal/tile_alpha.vs.metal create mode 100644 resources/shaders/metal/tile_solid.vs.metal rename shaders/{tile_alpha_vertex.inc.glsl => tile_alpha.vs.glsl} (78%) delete mode 100644 shaders/tile_alpha_monochrome.vs.glsl delete mode 100644 shaders/tile_alpha_multicolor.vs.glsl delete mode 100644 shaders/tile_monochrome.inc.glsl delete mode 100644 shaders/tile_multicolor.inc.glsl rename shaders/{tile_solid_vertex.inc.glsl => tile_solid.vs.glsl} (76%) delete mode 100644 shaders/tile_solid_monochrome.vs.glsl delete mode 100644 shaders/tile_solid_multicolor.vs.glsl diff --git a/Cargo.lock b/Cargo.lock index 72a0319b..575b4604 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1523,6 +1523,7 @@ dependencies = [ "arrayvec 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "pathfinder_color 0.1.0", "pathfinder_geometry 0.4.0", "pathfinder_simd 0.4.0", "smallvec 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/color/src/lib.rs b/color/src/lib.rs index 2248e05a..f918b173 100644 --- a/color/src/lib.rs +++ b/color/src/lib.rs @@ -12,7 +12,7 @@ use pathfinder_simd::default::F32x4; use std::fmt::{self, Debug, Formatter}; // TODO(pcwalton): Maybe this should be a u32? -#[derive(Clone, Copy, PartialEq, Eq, Hash, Default)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] pub struct ColorU { pub r: u8, pub g: u8, diff --git a/content/Cargo.toml b/content/Cargo.toml index cdd7b473..77174085 100644 --- a/content/Cargo.toml +++ b/content/Cargo.toml @@ -10,6 +10,9 @@ bitflags = "1.0" log = "0.4" smallvec = "0.6" +[dependencies.pathfinder_color] +path = "../color" + [dependencies.pathfinder_geometry] path = "../geometry" diff --git a/content/src/dash.rs b/content/src/dash.rs index a77df34b..d25f70e0 100644 --- a/content/src/dash.rs +++ b/content/src/dash.rs @@ -1,4 +1,4 @@ -// pathfinder/geometry/src/dash.rs +// pathfinder/content/src/dash.rs // // Copyright © 2019 The Pathfinder Project Developers. // diff --git a/content/src/gradient.rs b/content/src/gradient.rs new file mode 100644 index 00000000..3020ed48 --- /dev/null +++ b/content/src/gradient.rs @@ -0,0 +1,36 @@ +// pathfinder/geometry/src/gradient.rs +// +// Copyright © 2020 The Pathfinder Project Developers. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use crate::sorted_vector::SortedVector; +use pathfinder_color::ColorU; +use std::cmp::PartialOrd; + +#[derive(Clone, Debug)] +pub struct Gradient { + stops: SortedVector, +} + +#[derive(Clone, Copy, PartialEq, PartialOrd, Debug)] +pub struct ColorStop { + pub offset: f32, + pub color: ColorU, +} + +impl Gradient { + #[inline] + pub fn add_color_stop(&mut self, stop: ColorStop) { + self.stops.push(stop); + } + + #[inline] + pub fn stops(&self) -> &[ColorStop] { + &self.stops.array + } +} diff --git a/content/src/lib.rs b/content/src/lib.rs index e8a1f741..fa8cc650 100644 --- a/content/src/lib.rs +++ b/content/src/lib.rs @@ -19,9 +19,11 @@ extern crate log; pub mod clip; pub mod dash; +pub mod gradient; pub mod orientation; pub mod outline; pub mod segment; +pub mod sorted_vector; pub mod stroke; pub mod transform; diff --git a/renderer/src/sorted_vector.rs b/content/src/sorted_vector.rs similarity index 95% rename from renderer/src/sorted_vector.rs rename to content/src/sorted_vector.rs index 1b77c25b..46ade1c6 100644 --- a/renderer/src/sorted_vector.rs +++ b/content/src/sorted_vector.rs @@ -1,6 +1,6 @@ -// pathfinder/renderer/src/sorted_vector.rs +// pathfinder/content/src/sorted_vector.rs // -// Copyright © 2019 The Pathfinder Project Developers. +// Copyright © 2020 The Pathfinder Project Developers. // // Licensed under the Apache License, Version 2.0 or the MIT license diff --git a/demo/common/src/renderer.rs b/demo/common/src/renderer.rs index 4e7b4d58..2228f3c4 100644 --- a/demo/common/src/renderer.rs +++ b/demo/common/src/renderer.rs @@ -21,7 +21,7 @@ use pathfinder_geometry::rect::RectI; use pathfinder_geometry::transform3d::Transform4F; use pathfinder_geometry::vector::{Vector2I, Vector4F}; use pathfinder_renderer::gpu::options::{DestFramebuffer, RendererOptions}; -use pathfinder_renderer::gpu::renderer::RenderMode; +use pathfinder_renderer::gpu::renderer::PostprocessOptions; use pathfinder_renderer::gpu_data::RenderCommand; use pathfinder_renderer::options::RenderTransform; use pathfinder_renderer::post::DEFRINGING_KERNEL_CORE_GRAPHICS; @@ -252,9 +252,9 @@ impl DemoApp where W: Window { fn render_vector_scene(&mut self) { match self.scene_metadata.monochrome_color { - None => self.renderer.set_render_mode(RenderMode::Multicolor), + None => self.renderer.set_postprocess_options(None), Some(fg_color) => { - self.renderer.set_render_mode(RenderMode::Monochrome { + self.renderer.set_postprocess_options(Some(PostprocessOptions { fg_color: fg_color.to_f32(), bg_color: self.background_color().to_f32(), gamma_correction: self.ui_model.gamma_correction_effect_enabled, @@ -264,7 +264,7 @@ impl DemoApp where W: Window { } else { None }, - }) + })) } } diff --git a/renderer/src/gpu/renderer.rs b/renderer/src/gpu/renderer.rs index 63f3aa1b..cb7dd04c 100644 --- a/renderer/src/gpu/renderer.rs +++ b/renderer/src/gpu/renderer.rs @@ -56,14 +56,10 @@ where dest_framebuffer: DestFramebuffer, options: RendererOptions, fill_program: FillProgram, - solid_multicolor_tile_program: SolidTileMulticolorProgram, - alpha_multicolor_tile_program: AlphaTileMulticolorProgram, - solid_monochrome_tile_program: SolidTileMonochromeProgram, - alpha_monochrome_tile_program: AlphaTileMonochromeProgram, - solid_multicolor_tile_vertex_array: SolidTileVertexArray, - alpha_multicolor_tile_vertex_array: AlphaTileVertexArray, - solid_monochrome_tile_vertex_array: SolidTileVertexArray, - alpha_monochrome_tile_vertex_array: AlphaTileVertexArray, + solid_tile_program: SolidTileProgram, + alpha_tile_program: AlphaTileProgram, + solid_tile_vertex_array: SolidTileVertexArray, + alpha_tile_vertex_array: AlphaTileVertexArray, area_lut_texture: D::Texture, quad_vertex_positions_buffer: D::Buffer, quad_vertex_indices_buffer: D::Buffer, @@ -97,7 +93,7 @@ where pub debug_ui_presenter: DebugUIPresenter, // Extra info - render_mode: RenderMode, + postprocess_options: Option, use_depth: bool, } @@ -112,10 +108,8 @@ where -> Renderer { let fill_program = FillProgram::new(&device, resources); - let solid_multicolor_tile_program = SolidTileMulticolorProgram::new(&device, resources); - let alpha_multicolor_tile_program = AlphaTileMulticolorProgram::new(&device, resources); - let solid_monochrome_tile_program = SolidTileMonochromeProgram::new(&device, resources); - let alpha_monochrome_tile_program = AlphaTileMonochromeProgram::new(&device, resources); + let solid_tile_program = SolidTileProgram::new(&device, resources); + let alpha_tile_program = AlphaTileProgram::new(&device, resources); let postprocess_program = PostprocessProgram::new(&device, resources); let stencil_program = StencilProgram::new(&device, resources); @@ -145,27 +139,15 @@ where &quad_vertex_positions_buffer, &quad_vertex_indices_buffer, ); - let alpha_multicolor_tile_vertex_array = AlphaTileVertexArray::new( + let alpha_tile_vertex_array = AlphaTileVertexArray::new( &device, - &alpha_multicolor_tile_program.alpha_tile_program, + &alpha_tile_program, &quad_vertex_positions_buffer, &quad_vertex_indices_buffer, ); - let solid_multicolor_tile_vertex_array = SolidTileVertexArray::new( + let solid_tile_vertex_array = SolidTileVertexArray::new( &device, - &solid_multicolor_tile_program.solid_tile_program, - &quad_vertex_positions_buffer, - &quad_vertex_indices_buffer, - ); - let alpha_monochrome_tile_vertex_array = AlphaTileVertexArray::new( - &device, - &alpha_monochrome_tile_program.alpha_tile_program, - &quad_vertex_positions_buffer, - &quad_vertex_indices_buffer, - ); - let solid_monochrome_tile_vertex_array = SolidTileVertexArray::new( - &device, - &solid_monochrome_tile_program.solid_tile_program, + &solid_tile_program, &quad_vertex_positions_buffer, &quad_vertex_indices_buffer, ); @@ -198,14 +180,10 @@ where dest_framebuffer, options, fill_program, - solid_monochrome_tile_program, - alpha_monochrome_tile_program, - solid_multicolor_tile_program, - alpha_multicolor_tile_program, - solid_monochrome_tile_vertex_array, - alpha_monochrome_tile_vertex_array, - solid_multicolor_tile_vertex_array, - alpha_multicolor_tile_vertex_array, + solid_tile_program, + alpha_tile_program, + solid_tile_vertex_array, + alpha_tile_vertex_array, area_lut_texture, quad_vertex_positions_buffer, quad_vertex_indices_buffer, @@ -233,7 +211,7 @@ where framebuffer_flags: FramebufferFlags::empty(), buffered_fills: vec![], - render_mode: RenderMode::default(), + postprocess_options: None, use_depth: false, } } @@ -276,7 +254,7 @@ where } pub fn end_scene(&mut self) { - if self.postprocessing_needed() { + if self.postprocess_options.is_some() { self.postprocess(); } @@ -343,8 +321,8 @@ where } #[inline] - pub fn set_render_mode(&mut self, mode: RenderMode) { - self.render_mode = mode; + pub fn set_postprocess_options(&mut self, new_options: Option) { + self.postprocess_options = new_options; } #[inline] @@ -368,23 +346,33 @@ where } fn upload_paint_data(&mut self, paint_data: &PaintData) { + // FIXME(pcwalton): This is a hack. We shouldn't be generating paint data at all on the + // renderer side. + let (paint_size, paint_texels): (Vector2I, &[u8]); + if self.postprocess_options.is_some() { + paint_size = Vector2I::splat(1); + paint_texels = &[255; 4]; + } else { + paint_size = paint_data.size; + paint_texels = &paint_data.texels; + }; + match self.paint_texture { - Some(ref paint_texture) if - self.device.texture_size(paint_texture) == paint_data.size => {} + Some(ref paint_texture) if self.device.texture_size(paint_texture) == paint_size => {} _ => { - let texture = self.device.create_texture(TextureFormat::RGBA8, paint_data.size); + let texture = self.device.create_texture(TextureFormat::RGBA8, paint_size); self.paint_texture = Some(texture) } } self.device.upload_to_texture(self.paint_texture.as_ref().unwrap(), - RectI::new(Vector2I::default(), paint_data.size), - TextureDataRef::U8(&paint_data.texels)); + RectI::new(Vector2I::default(), paint_size), + TextureDataRef::U8(paint_texels)); } fn upload_solid_tiles(&mut self, solid_tiles: &[SolidTileBatchPrimitive]) { self.device.allocate_buffer( - &self.solid_tile_vertex_array().vertex_buffer, + &self.solid_tile_vertex_array.vertex_buffer, BufferData::Memory(&solid_tiles), BufferTarget::Vertex, BufferUploadMode::Dynamic, @@ -393,7 +381,7 @@ where fn upload_alpha_tiles(&mut self, alpha_tiles: &[AlphaTileBatchPrimitive]) { self.device.allocate_buffer( - &self.alpha_tile_vertex_array().vertex_buffer, + &self.alpha_tile_vertex_array.vertex_buffer, BufferData::Memory(&alpha_tiles), BufferTarget::Vertex, BufferUploadMode::Dynamic, @@ -480,47 +468,32 @@ where fn draw_alpha_tiles(&mut self, count: u32) { let clear_color = self.clear_color_for_draw_operation(); - let alpha_tile_vertex_array = self.alpha_tile_vertex_array(); - let alpha_tile_program = self.alpha_tile_program(); - let mut textures = vec![self.device.framebuffer_texture(&self.mask_framebuffer)]; let mut uniforms = vec![ - (&alpha_tile_program.transform_uniform, + (&self.alpha_tile_program.transform_uniform, UniformData::Mat4(self.tile_transform().to_columns())), - (&alpha_tile_program.tile_size_uniform, + (&self.alpha_tile_program.tile_size_uniform, UniformData::Vec2(F32x2::new(TILE_WIDTH as f32, TILE_HEIGHT as f32))), - (&alpha_tile_program.stencil_texture_uniform, UniformData::TextureUnit(0)), - (&alpha_tile_program.stencil_texture_size_uniform, + (&self.alpha_tile_program.stencil_texture_uniform, UniformData::TextureUnit(0)), + (&self.alpha_tile_program.stencil_texture_size_uniform, UniformData::Vec2(F32x2::new(MASK_FRAMEBUFFER_WIDTH as f32, MASK_FRAMEBUFFER_HEIGHT as f32))), ]; - match self.render_mode { - RenderMode::Multicolor => { - let paint_texture = self.paint_texture.as_ref().unwrap(); - textures.push(paint_texture); - uniforms.push((&self.alpha_multicolor_tile_program.paint_texture_uniform, - UniformData::TextureUnit(1))); - uniforms.push((&self.alpha_multicolor_tile_program.paint_texture_size_uniform, - UniformData::Vec2(self.device - .texture_size(paint_texture) - .0 - .to_f32x2()))); - } - RenderMode::Monochrome { .. } if self.postprocessing_needed() => { - uniforms.push((&self.alpha_monochrome_tile_program.color_uniform, - UniformData::Vec4(F32x4::splat(1.0)))); - } - RenderMode::Monochrome { fg_color, .. } => { - uniforms.push((&self.alpha_monochrome_tile_program.color_uniform, - UniformData::Vec4(fg_color.0))); - } - } + let paint_texture = self.paint_texture.as_ref().unwrap(); + textures.push(paint_texture); + uniforms.push((&self.alpha_tile_program.paint_texture_uniform, + UniformData::TextureUnit(1))); + uniforms.push((&self.alpha_tile_program.paint_texture_size_uniform, + UniformData::Vec2(self.device + .texture_size(paint_texture) + .0 + .to_f32x2()))); self.device.draw_elements_instanced(6, count, &RenderState { target: &self.draw_render_target(), - program: &alpha_tile_program.program, - vertex_array: &alpha_tile_vertex_array.vertex_array, + program: &self.alpha_tile_program.program, + vertex_array: &self.alpha_tile_vertex_array.vertex_array, primitive: Primitive::Triangles, textures: &textures, uniforms: &uniforms, @@ -542,43 +515,25 @@ where fn draw_solid_tiles(&mut self, count: u32) { let clear_color = self.clear_color_for_draw_operation(); - let solid_tile_vertex_array = self.solid_tile_vertex_array(); - let solid_tile_program = self.solid_tile_program(); - let mut textures = vec![]; let mut uniforms = vec![ - (&solid_tile_program.transform_uniform, + (&self.solid_tile_program.transform_uniform, UniformData::Mat4(self.tile_transform().to_columns())), - (&solid_tile_program.tile_size_uniform, + (&self.solid_tile_program.tile_size_uniform, UniformData::Vec2(F32x2::new(TILE_WIDTH as f32, TILE_HEIGHT as f32))), ]; - match self.render_mode { - RenderMode::Multicolor => { - let paint_texture = self.paint_texture.as_ref().unwrap(); - textures.push(paint_texture); - uniforms.push((&self.solid_multicolor_tile_program.paint_texture_uniform, - UniformData::TextureUnit(0))); - uniforms.push((&self.solid_multicolor_tile_program.paint_texture_size_uniform, - UniformData::Vec2(self.device - .texture_size(paint_texture) - .0 - .to_f32x2()))); - } - RenderMode::Monochrome { .. } if self.postprocessing_needed() => { - uniforms.push((&self.solid_monochrome_tile_program.color_uniform, - UniformData::Vec4(F32x4::splat(1.0)))); - } - RenderMode::Monochrome { fg_color, .. } => { - uniforms.push((&self.solid_monochrome_tile_program.color_uniform, - UniformData::Vec4(fg_color.0))); - } - } + let paint_texture = self.paint_texture.as_ref().unwrap(); + textures.push(paint_texture); + uniforms.push((&self.solid_tile_program.paint_texture_uniform, + UniformData::TextureUnit(0))); + uniforms.push((&self.solid_tile_program.paint_texture_size_uniform, + UniformData::Vec2(self.device.texture_size(paint_texture).0.to_f32x2()))); self.device.draw_elements_instanced(6, count, &RenderState { target: &self.draw_render_target(), - program: &solid_tile_program.program, - vertex_array: &solid_tile_vertex_array.vertex_array, + program: &self.solid_tile_program.program, + vertex_array: &self.solid_tile_vertex_array.vertex_array, primitive: Primitive::Triangles, textures: &textures, uniforms: &uniforms, @@ -600,21 +555,10 @@ where clear_color = self.options.background_color; } - let (fg_color, bg_color, defringing_kernel, gamma_correction_enabled); - match self.render_mode { - RenderMode::Multicolor => return, - RenderMode::Monochrome { - fg_color: fg, - bg_color: bg, - defringing_kernel: kernel, - gamma_correction, - } => { - fg_color = fg; - bg_color = bg; - defringing_kernel = kernel; - gamma_correction_enabled = gamma_correction; - } - } + let postprocess_options = match self.postprocess_options { + None => return, + Some(ref options) => options, + }; let postprocess_source_framebuffer = self.postprocess_source_framebuffer.as_ref().unwrap(); let source_texture = self @@ -630,13 +574,15 @@ where (&self.postprocess_program.source_size_uniform, UniformData::Vec2(source_texture_size.0.to_f32x2())), (&self.postprocess_program.gamma_lut_uniform, UniformData::TextureUnit(1)), - (&self.postprocess_program.fg_color_uniform, UniformData::Vec4(fg_color.0)), - (&self.postprocess_program.bg_color_uniform, UniformData::Vec4(bg_color.0)), + (&self.postprocess_program.fg_color_uniform, + UniformData::Vec4(postprocess_options.fg_color.0)), + (&self.postprocess_program.bg_color_uniform, + UniformData::Vec4(postprocess_options.bg_color.0)), (&self.postprocess_program.gamma_correction_enabled_uniform, - UniformData::Int(gamma_correction_enabled as i32)), + UniformData::Int(postprocess_options.gamma_correction as i32)), ]; - match defringing_kernel { + match postprocess_options.defringing_kernel { Some(ref kernel) => { uniforms.push((&self.postprocess_program.kernel_uniform, UniformData::Vec4(F32x4::from_slice(&kernel.0)))); @@ -664,34 +610,6 @@ where self.framebuffer_flags.insert(FramebufferFlags::MUST_PRESERVE_DEST_FRAMEBUFFER_CONTENTS); } - fn solid_tile_program(&self) -> &SolidTileProgram { - match self.render_mode { - RenderMode::Monochrome { .. } => &self.solid_monochrome_tile_program.solid_tile_program, - RenderMode::Multicolor => &self.solid_multicolor_tile_program.solid_tile_program, - } - } - - fn alpha_tile_program(&self) -> &AlphaTileProgram { - match self.render_mode { - RenderMode::Monochrome { .. } => &self.alpha_monochrome_tile_program.alpha_tile_program, - RenderMode::Multicolor => &self.alpha_multicolor_tile_program.alpha_tile_program, - } - } - - fn solid_tile_vertex_array(&self) -> &SolidTileVertexArray { - match self.render_mode { - RenderMode::Monochrome { .. } => &self.solid_monochrome_tile_vertex_array, - RenderMode::Multicolor => &self.solid_multicolor_tile_vertex_array, - } - } - - fn alpha_tile_vertex_array(&self) -> &AlphaTileVertexArray { - match self.render_mode { - RenderMode::Monochrome { .. } => &self.alpha_monochrome_tile_vertex_array, - RenderMode::Multicolor => &self.alpha_multicolor_tile_vertex_array, - } - } - fn draw_stencil(&mut self, quad_positions: &[Vector4F]) { self.device.allocate_buffer( &self.stencil_vertex_array.vertex_buffer, @@ -774,7 +692,7 @@ where } pub fn draw_render_target(&self) -> RenderTarget { - if self.postprocessing_needed() { + if self.postprocess_options.is_some() { RenderTarget::Framebuffer(self.postprocess_source_framebuffer.as_ref().unwrap()) } else { self.dest_render_target() @@ -789,7 +707,7 @@ where } fn init_postprocessing_framebuffer(&mut self) { - if !self.postprocessing_needed() { + if !self.postprocess_options.is_some() { self.postprocess_source_framebuffer = None; return; } @@ -822,17 +740,6 @@ where */ } - fn postprocessing_needed(&self) -> bool { - match self.render_mode { - RenderMode::Monochrome { - ref defringing_kernel, - gamma_correction, - .. - } => defringing_kernel.is_some() || gamma_correction, - _ => false, - } - } - fn stencil_state(&self) -> Option { if !self.use_depth { return None; @@ -847,7 +754,7 @@ where } fn clear_color_for_draw_operation(&mut self) -> Option { - let postprocessing_needed = self.postprocessing_needed(); + let postprocessing_needed = self.postprocess_options.is_some(); let flag = if postprocessing_needed { FramebufferFlags::MUST_PRESERVE_POSTPROCESS_FRAMEBUFFER_CONTENTS } else { @@ -864,7 +771,7 @@ where } fn preserve_draw_framebuffer(&mut self) { - let flag = if self.postprocessing_needed() { + let flag = if self.postprocess_options.is_some() { FramebufferFlags::MUST_PRESERVE_POSTPROCESS_FRAMEBUFFER_CONTENTS } else { FramebufferFlags::MUST_PRESERVE_DEST_FRAMEBUFFER_CONTENTS @@ -874,13 +781,9 @@ where pub fn draw_viewport(&self) -> RectI { let main_viewport = self.main_viewport(); - match self.render_mode { - RenderMode::Monochrome { - defringing_kernel: Some(..), - .. - } => { - let scale = Vector2I::new(3, 1); - RectI::new(Vector2I::default(), main_viewport.size().scale_xy(scale)) + match self.postprocess_options { + Some(PostprocessOptions { defringing_kernel: Some(_), .. }) => { + RectI::new(Vector2I::default(), main_viewport.size().scale_xy(Vector2I::new(3, 1))) } _ => main_viewport, } @@ -1208,166 +1111,62 @@ where } } -struct SolidTileProgram -where - D: Device, -{ +struct SolidTileProgram where D: Device { program: D::Program, transform_uniform: D::Uniform, tile_size_uniform: D::Uniform, -} - -impl SolidTileProgram -where - D: Device, -{ - fn new(device: &D, program_name: &str, resources: &dyn ResourceLoader) -> SolidTileProgram { - let program = device.create_program_from_shader_names( - resources, - program_name, - program_name, - "tile_solid", - ); - let transform_uniform = device.get_uniform(&program, "Transform"); - let tile_size_uniform = device.get_uniform(&program, "TileSize"); - SolidTileProgram { program, transform_uniform, tile_size_uniform } - } -} - -struct SolidTileMulticolorProgram -where - D: Device, -{ - solid_tile_program: SolidTileProgram, paint_texture_uniform: D::Uniform, paint_texture_size_uniform: D::Uniform, } -impl SolidTileMulticolorProgram -where - D: Device, -{ - fn new(device: &D, resources: &dyn ResourceLoader) -> SolidTileMulticolorProgram { - let solid_tile_program = SolidTileProgram::new(device, "tile_solid_multicolor", resources); - let paint_texture_uniform = device.get_uniform(&solid_tile_program.program, - "PaintTexture"); - let paint_texture_size_uniform = device.get_uniform(&solid_tile_program.program, - "PaintTextureSize"); - SolidTileMulticolorProgram { - solid_tile_program, +impl SolidTileProgram where D: Device { + fn new(device: &D, resources: &dyn ResourceLoader) -> SolidTileProgram { + let program = device.create_program(resources, "tile_solid"); + let transform_uniform = device.get_uniform(&program, "Transform"); + let tile_size_uniform = device.get_uniform(&program, "TileSize"); + let paint_texture_uniform = device.get_uniform(&program, "PaintTexture"); + let paint_texture_size_uniform = device.get_uniform(&program, "PaintTextureSize"); + SolidTileProgram { + program, + transform_uniform, + tile_size_uniform, paint_texture_uniform, paint_texture_size_uniform, } } } -struct SolidTileMonochromeProgram -where - D: Device, -{ - solid_tile_program: SolidTileProgram, - color_uniform: D::Uniform, -} - -impl SolidTileMonochromeProgram -where - D: Device, -{ - fn new(device: &D, resources: &dyn ResourceLoader) -> SolidTileMonochromeProgram { - let solid_tile_program = SolidTileProgram::new(device, "tile_solid_monochrome", resources); - let color_uniform = device.get_uniform(&solid_tile_program.program, "Color"); - SolidTileMonochromeProgram { - solid_tile_program, - color_uniform, - } - } -} - -struct AlphaTileProgram -where - D: Device, -{ +struct AlphaTileProgram where D: Device { program: D::Program, transform_uniform: D::Uniform, tile_size_uniform: D::Uniform, stencil_texture_uniform: D::Uniform, stencil_texture_size_uniform: D::Uniform, + paint_texture_uniform: D::Uniform, + paint_texture_size_uniform: D::Uniform, } -impl AlphaTileProgram -where - D: Device, -{ - fn new(device: &D, program_name: &str, resources: &dyn ResourceLoader) -> AlphaTileProgram { - let program = device.create_program_from_shader_names( - resources, - program_name, - program_name, - "tile_alpha", - ); +impl AlphaTileProgram where D: Device { + fn new(device: &D, resources: &dyn ResourceLoader) -> AlphaTileProgram { + let program = device.create_program(resources, "tile_alpha"); let transform_uniform = device.get_uniform(&program, "Transform"); let tile_size_uniform = device.get_uniform(&program, "TileSize"); let stencil_texture_uniform = device.get_uniform(&program, "StencilTexture"); let stencil_texture_size_uniform = device.get_uniform(&program, "StencilTextureSize"); + let paint_texture_uniform = device.get_uniform(&program, "PaintTexture"); + let paint_texture_size_uniform = device.get_uniform(&program, "PaintTextureSize"); AlphaTileProgram { program, transform_uniform, tile_size_uniform, stencil_texture_uniform, stencil_texture_size_uniform, - } - } -} - -struct AlphaTileMulticolorProgram -where - D: Device, -{ - alpha_tile_program: AlphaTileProgram, - paint_texture_uniform: D::Uniform, - paint_texture_size_uniform: D::Uniform, -} - -impl AlphaTileMulticolorProgram -where - D: Device, -{ - fn new(device: &D, resources: &dyn ResourceLoader) -> AlphaTileMulticolorProgram { - let alpha_tile_program = AlphaTileProgram::new(device, "tile_alpha_multicolor", resources); - let paint_texture_uniform = - device.get_uniform(&alpha_tile_program.program, "PaintTexture"); - let paint_texture_size_uniform = - device.get_uniform(&alpha_tile_program.program, "PaintTextureSize"); - AlphaTileMulticolorProgram { - alpha_tile_program, paint_texture_uniform, paint_texture_size_uniform, } } } -struct AlphaTileMonochromeProgram -where - D: Device, -{ - alpha_tile_program: AlphaTileProgram, - color_uniform: D::Uniform, -} - -impl AlphaTileMonochromeProgram -where - D: Device, -{ - fn new(device: &D, resources: &dyn ResourceLoader) -> AlphaTileMonochromeProgram { - let alpha_tile_program = AlphaTileProgram::new(device, "tile_alpha_monochrome", resources); - let color_uniform = device.get_uniform(&alpha_tile_program.program, "Color"); - AlphaTileMonochromeProgram { - alpha_tile_program, - color_uniform, - } - } -} - struct PostprocessProgram where D: Device, @@ -1567,22 +1366,12 @@ where } } -#[derive(Clone, Copy)] -pub enum RenderMode { - Multicolor, - Monochrome { - fg_color: ColorF, - bg_color: ColorF, - defringing_kernel: Option, - gamma_correction: bool, - }, -} - -impl Default for RenderMode { - #[inline] - fn default() -> RenderMode { - RenderMode::Multicolor - } +#[derive(Clone, Copy, Default)] +pub struct PostprocessOptions { + pub fg_color: ColorF, + pub bg_color: ColorF, + pub defringing_kernel: Option, + pub gamma_correction: bool, } #[derive(Clone, Copy, Debug, Default)] diff --git a/renderer/src/lib.rs b/renderer/src/lib.rs index e4fef9c8..05715479 100644 --- a/renderer/src/lib.rs +++ b/renderer/src/lib.rs @@ -25,7 +25,6 @@ pub mod scene; mod allocator; mod builder; -mod sorted_vector; mod tile_map; mod tiles; mod z_buffer; diff --git a/renderer/src/tiles.rs b/renderer/src/tiles.rs index b256f884..2eacb111 100644 --- a/renderer/src/tiles.rs +++ b/renderer/src/tiles.rs @@ -11,12 +11,12 @@ use crate::builder::SceneBuilder; use crate::gpu_data::{AlphaTileBatchPrimitive, BuiltObject, TileObjectPrimitive}; use crate::paint::PaintMetadata; -use crate::sorted_vector::SortedVector; +use pathfinder_content::outline::{Contour, Outline, PointIndex}; +use pathfinder_content::segment::Segment; +use pathfinder_content::sorted_vector::SortedVector; use pathfinder_geometry::line_segment::LineSegment2F; use pathfinder_geometry::vector::{Vector2F, Vector2I}; use pathfinder_geometry::rect::{RectF, RectI}; -use pathfinder_content::outline::{Contour, Outline, PointIndex}; -use pathfinder_content::segment::Segment; use std::cmp::Ordering; use std::mem; diff --git a/resources/shaders/gl3/tile_alpha.fs.glsl b/resources/shaders/gl3/tile_alpha.fs.glsl index 0e7247d7..6f142253 100644 --- a/resources/shaders/gl3/tile_alpha.fs.glsl +++ b/resources/shaders/gl3/tile_alpha.fs.glsl @@ -15,15 +15,19 @@ precision highp float; uniform sampler2D uStencilTexture; +uniform sampler2D uPaintTexture; +uniform vec2 uPaintTextureSize; -in vec2 vTexCoord; +in vec2 vMaskTexCoord; +in vec2 vColorTexCoord; in float vBackdrop; in vec4 vColor; out vec4 oFragColor; void main(){ - float coverage = abs(texture(uStencilTexture, vTexCoord). r + vBackdrop); - oFragColor = vec4(vColor . rgb, vColor . a * coverage); + float coverage = abs(texture(uStencilTexture, vMaskTexCoord). r + vBackdrop); + vec4 color = texture(uPaintTexture, vColorTexCoord); + oFragColor = vec4(color . rgb, color . a * coverage); } diff --git a/resources/shaders/gl3/tile_alpha.vs.glsl b/resources/shaders/gl3/tile_alpha.vs.glsl new file mode 100644 index 00000000..721786fd --- /dev/null +++ b/resources/shaders/gl3/tile_alpha.vs.glsl @@ -0,0 +1,48 @@ +#version {{version}} +// Automatically generated from files in pathfinder/shaders/. Do not edit! + + + + + + + + + + + + +precision highp float; + +uniform mat4 uTransform; +uniform vec2 uTileSize; +uniform vec2 uStencilTextureSize; + +in uvec2 aTessCoord; +in uvec3 aTileOrigin; +in vec2 aColorTexCoord; +in int aBackdrop; +in int aTileIndex; + +out vec2 vMaskTexCoord; +out vec2 vColorTexCoord; +out float vBackdrop; + +vec2 computeTileOffset(uint tileIndex, float stencilTextureWidth){ + uint tilesPerRow = uint(stencilTextureWidth / uTileSize . x); + uvec2 tileOffset = uvec2(tileIndex % tilesPerRow, tileIndex / tilesPerRow); + return vec2(tileOffset)* uTileSize; +} + +void main(){ + vec2 origin = vec2(aTileOrigin . xy)+ vec2(aTileOrigin . z & 15u, aTileOrigin . z >> 4u)* 256.0; + vec2 position =(origin + vec2(aTessCoord))* uTileSize; + vec2 maskTexCoordOrigin = computeTileOffset(uint(aTileIndex), uStencilTextureSize . x); + vec2 maskTexCoord = maskTexCoordOrigin + aTessCoord * uTileSize; + + vMaskTexCoord = maskTexCoord / uStencilTextureSize; + vColorTexCoord = aColorTexCoord; + vBackdrop = float(aBackdrop); + gl_Position = uTransform * vec4(position, 0.0, 1.0); +} + diff --git a/resources/shaders/gl3/tile_solid.fs.glsl b/resources/shaders/gl3/tile_solid.fs.glsl index f8f8f7a7..214b026c 100644 --- a/resources/shaders/gl3/tile_solid.fs.glsl +++ b/resources/shaders/gl3/tile_solid.fs.glsl @@ -14,11 +14,14 @@ precision highp float; -in vec4 vColor; +uniform sampler2D uPaintTexture; +uniform vec2 uPaintTextureSize; + +in vec2 vColorTexCoord; out vec4 oFragColor; void main(){ - oFragColor = vColor; + oFragColor = texture(uPaintTexture, vColorTexCoord); } diff --git a/resources/shaders/gl3/tile_solid.vs.glsl b/resources/shaders/gl3/tile_solid.vs.glsl new file mode 100644 index 00000000..7320c851 --- /dev/null +++ b/resources/shaders/gl3/tile_solid.vs.glsl @@ -0,0 +1,31 @@ +#version {{version}} +// Automatically generated from files in pathfinder/shaders/. Do not edit! + + + + + + + + + + + + +precision highp float; + +uniform mat4 uTransform; +uniform vec2 uTileSize; + +in uvec2 aTessCoord; +in ivec2 aTileOrigin; +in vec2 aColorTexCoord; + +out vec2 vColorTexCoord; + +void main(){ + vec2 position = vec2(aTileOrigin + ivec2(aTessCoord))* uTileSize; + vColorTexCoord = aColorTexCoord; + gl_Position = uTransform * vec4(position, 0.0, 1.0); +} + diff --git a/resources/shaders/metal/tile_alpha.fs.metal b/resources/shaders/metal/tile_alpha.fs.metal index 2e72b19e..7dde311b 100644 --- a/resources/shaders/metal/tile_alpha.fs.metal +++ b/resources/shaders/metal/tile_alpha.fs.metal @@ -8,6 +8,8 @@ struct spvDescriptorSetBuffer0 { texture2d uStencilTexture [[id(0)]]; sampler uStencilTextureSmplr [[id(1)]]; + texture2d uPaintTexture [[id(2)]]; + sampler uPaintTextureSmplr [[id(3)]]; }; struct main0_out @@ -17,16 +19,17 @@ struct main0_out struct main0_in { - float2 vTexCoord [[user(locn0)]]; - float vBackdrop [[user(locn1)]]; - float4 vColor [[user(locn2)]]; + float2 vMaskTexCoord [[user(locn0)]]; + float2 vColorTexCoord [[user(locn1)]]; + float vBackdrop [[user(locn2)]]; }; fragment main0_out main0(main0_in in [[stage_in]], constant spvDescriptorSetBuffer0& spvDescriptorSet0 [[buffer(0)]]) { main0_out out = {}; - float coverage = abs(spvDescriptorSet0.uStencilTexture.sample(spvDescriptorSet0.uStencilTextureSmplr, in.vTexCoord).x + in.vBackdrop); - out.oFragColor = float4(in.vColor.xyz, in.vColor.w * coverage); + float coverage = abs(spvDescriptorSet0.uStencilTexture.sample(spvDescriptorSet0.uStencilTextureSmplr, in.vMaskTexCoord).x + in.vBackdrop); + float4 color = spvDescriptorSet0.uPaintTexture.sample(spvDescriptorSet0.uPaintTextureSmplr, in.vColorTexCoord); + out.oFragColor = float4(color.xyz, color.w * coverage); return out; } diff --git a/resources/shaders/metal/tile_alpha.vs.metal b/resources/shaders/metal/tile_alpha.vs.metal new file mode 100644 index 00000000..68e0cf1d --- /dev/null +++ b/resources/shaders/metal/tile_alpha.vs.metal @@ -0,0 +1,55 @@ +// Automatically generated from files in pathfinder/shaders/. Do not edit! +#pragma clang diagnostic ignored "-Wmissing-prototypes" + +#include +#include + +using namespace metal; + +struct spvDescriptorSetBuffer0 +{ + constant float2* uTileSize [[id(0)]]; + constant float2* uStencilTextureSize [[id(1)]]; + constant float4x4* uTransform [[id(2)]]; +}; + +struct main0_out +{ + float2 vMaskTexCoord [[user(locn0)]]; + float2 vColorTexCoord [[user(locn1)]]; + float vBackdrop [[user(locn2)]]; + float4 gl_Position [[position]]; +}; + +struct main0_in +{ + uint2 aTessCoord [[attribute(0)]]; + uint3 aTileOrigin [[attribute(1)]]; + float2 aColorTexCoord [[attribute(2)]]; + int aBackdrop [[attribute(3)]]; + int aTileIndex [[attribute(4)]]; +}; + +float2 computeTileOffset(thread const uint& tileIndex, thread const float& stencilTextureWidth, thread float2 uTileSize) +{ + uint tilesPerRow = uint(stencilTextureWidth / uTileSize.x); + uint2 tileOffset = uint2(tileIndex % tilesPerRow, tileIndex / tilesPerRow); + return float2(tileOffset) * uTileSize; +} + +vertex main0_out main0(main0_in in [[stage_in]], constant spvDescriptorSetBuffer0& spvDescriptorSet0 [[buffer(0)]]) +{ + main0_out out = {}; + float2 origin = float2(in.aTileOrigin.xy) + (float2(float(in.aTileOrigin.z & 15u), float(in.aTileOrigin.z >> 4u)) * 256.0); + float2 position = (origin + float2(in.aTessCoord)) * (*spvDescriptorSet0.uTileSize); + uint param = uint(in.aTileIndex); + float param_1 = (*spvDescriptorSet0.uStencilTextureSize).x; + float2 maskTexCoordOrigin = computeTileOffset(param, param_1, (*spvDescriptorSet0.uTileSize)); + float2 maskTexCoord = maskTexCoordOrigin + (float2(in.aTessCoord) * (*spvDescriptorSet0.uTileSize)); + out.vMaskTexCoord = maskTexCoord / (*spvDescriptorSet0.uStencilTextureSize); + out.vColorTexCoord = in.aColorTexCoord; + out.vBackdrop = float(in.aBackdrop); + out.gl_Position = (*spvDescriptorSet0.uTransform) * float4(position, 0.0, 1.0); + return out; +} + diff --git a/resources/shaders/metal/tile_solid.fs.metal b/resources/shaders/metal/tile_solid.fs.metal index ac500c97..6e961080 100644 --- a/resources/shaders/metal/tile_solid.fs.metal +++ b/resources/shaders/metal/tile_solid.fs.metal @@ -4,6 +4,12 @@ using namespace metal; +struct spvDescriptorSetBuffer0 +{ + texture2d uPaintTexture [[id(0)]]; + sampler uPaintTextureSmplr [[id(1)]]; +}; + struct main0_out { float4 oFragColor [[color(0)]]; @@ -11,13 +17,13 @@ struct main0_out struct main0_in { - float4 vColor [[user(locn0)]]; + float2 vColorTexCoord [[user(locn0)]]; }; -fragment main0_out main0(main0_in in [[stage_in]]) +fragment main0_out main0(main0_in in [[stage_in]], constant spvDescriptorSetBuffer0& spvDescriptorSet0 [[buffer(0)]]) { main0_out out = {}; - out.oFragColor = in.vColor; + out.oFragColor = spvDescriptorSet0.uPaintTexture.sample(spvDescriptorSet0.uPaintTextureSmplr, in.vColorTexCoord); return out; } diff --git a/resources/shaders/metal/tile_solid.vs.metal b/resources/shaders/metal/tile_solid.vs.metal new file mode 100644 index 00000000..b603768b --- /dev/null +++ b/resources/shaders/metal/tile_solid.vs.metal @@ -0,0 +1,34 @@ +// Automatically generated from files in pathfinder/shaders/. Do not edit! +#include +#include + +using namespace metal; + +struct spvDescriptorSetBuffer0 +{ + constant float2* uTileSize [[id(0)]]; + constant float4x4* uTransform [[id(1)]]; +}; + +struct main0_out +{ + float2 vColorTexCoord [[user(locn0)]]; + float4 gl_Position [[position]]; +}; + +struct main0_in +{ + uint2 aTessCoord [[attribute(0)]]; + int2 aTileOrigin [[attribute(1)]]; + float2 aColorTexCoord [[attribute(2)]]; +}; + +vertex main0_out main0(main0_in in [[stage_in]], constant spvDescriptorSetBuffer0& spvDescriptorSet0 [[buffer(0)]]) +{ + main0_out out = {}; + float2 position = float2(in.aTileOrigin + int2(in.aTessCoord)) * (*spvDescriptorSet0.uTileSize); + out.vColorTexCoord = in.aColorTexCoord; + out.gl_Position = (*spvDescriptorSet0.uTransform) * float4(position, 0.0, 1.0); + return out; +} + diff --git a/shaders/Makefile b/shaders/Makefile index 327144c8..b5e8ad4c 100644 --- a/shaders/Makefile +++ b/shaders/Makefile @@ -18,20 +18,14 @@ SHADERS=\ stencil.fs.glsl \ stencil.vs.glsl \ tile_alpha.fs.glsl \ - tile_alpha_monochrome.vs.glsl \ - tile_alpha_multicolor.vs.glsl \ + tile_alpha.vs.glsl \ tile_solid.fs.glsl \ - tile_solid_monochrome.vs.glsl \ - tile_solid_multicolor.vs.glsl \ + tile_solid.vs.glsl \ $(EMPTY) INCLUDES=\ post_convolve.inc.glsl \ - tile_alpha_vertex.inc.glsl \ - tile_multicolor.inc.glsl \ post_gamma_correct.inc.glsl \ - tile_monochrome.inc.glsl \ - tile_solid_vertex.inc.glsl \ $(EMPTY) OUT=\ diff --git a/shaders/tile_alpha.fs.glsl b/shaders/tile_alpha.fs.glsl index b7dc5df9..fc2a3f31 100644 --- a/shaders/tile_alpha.fs.glsl +++ b/shaders/tile_alpha.fs.glsl @@ -13,14 +13,18 @@ precision highp float; uniform sampler2D uStencilTexture; +uniform sampler2D uPaintTexture; +uniform vec2 uPaintTextureSize; -in vec2 vTexCoord; +in vec2 vMaskTexCoord; +in vec2 vColorTexCoord; in float vBackdrop; in vec4 vColor; out vec4 oFragColor; void main() { - float coverage = abs(texture(uStencilTexture, vTexCoord).r + vBackdrop); - oFragColor = vec4(vColor.rgb, vColor.a * coverage); + float coverage = abs(texture(uStencilTexture, vMaskTexCoord).r + vBackdrop); + vec4 color = texture(uPaintTexture, vColorTexCoord); + oFragColor = vec4(color.rgb, color.a * coverage); } diff --git a/shaders/tile_alpha_vertex.inc.glsl b/shaders/tile_alpha.vs.glsl similarity index 78% rename from shaders/tile_alpha_vertex.inc.glsl rename to shaders/tile_alpha.vs.glsl index dee7eb36..a81f1f2e 100644 --- a/shaders/tile_alpha_vertex.inc.glsl +++ b/shaders/tile_alpha.vs.glsl @@ -1,6 +1,8 @@ -// pathfinder/shaders/tile_alpha_vertex.inc.glsl +#version 330 + +// pathfinder/shaders/tile_alpha.vs.glsl // -// Copyright © 2019 The Pathfinder Project Developers. +// Copyright © 2020 The Pathfinder Project Developers. // // Licensed under the Apache License, Version 2.0 or the MIT license @@ -8,20 +10,21 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +precision highp float; + uniform mat4 uTransform; uniform vec2 uTileSize; uniform vec2 uStencilTextureSize; in uvec2 aTessCoord; in uvec3 aTileOrigin; +in vec2 aColorTexCoord; in int aBackdrop; in int aTileIndex; -out vec2 vTexCoord; +out vec2 vMaskTexCoord; +out vec2 vColorTexCoord; out float vBackdrop; -out vec4 vColor; - -vec4 getColor(); vec2 computeTileOffset(uint tileIndex, float stencilTextureWidth) { uint tilesPerRow = uint(stencilTextureWidth / uTileSize.x); @@ -29,15 +32,14 @@ vec2 computeTileOffset(uint tileIndex, float stencilTextureWidth) { return vec2(tileOffset) * uTileSize; } -void computeVaryings() { +void main() { vec2 origin = vec2(aTileOrigin.xy) + vec2(aTileOrigin.z & 15u, aTileOrigin.z >> 4u) * 256.0; vec2 position = (origin + vec2(aTessCoord)) * uTileSize; vec2 maskTexCoordOrigin = computeTileOffset(uint(aTileIndex), uStencilTextureSize.x); vec2 maskTexCoord = maskTexCoordOrigin + aTessCoord * uTileSize; - vTexCoord = maskTexCoord / uStencilTextureSize; + vMaskTexCoord = maskTexCoord / uStencilTextureSize; + vColorTexCoord = aColorTexCoord; vBackdrop = float(aBackdrop); - vColor = getColor(); gl_Position = uTransform * vec4(position, 0.0, 1.0); } - diff --git a/shaders/tile_alpha_monochrome.vs.glsl b/shaders/tile_alpha_monochrome.vs.glsl deleted file mode 100644 index 856b4f1f..00000000 --- a/shaders/tile_alpha_monochrome.vs.glsl +++ /dev/null @@ -1,22 +0,0 @@ -#version 330 - -// pathfinder/shaders/tile_alpha_monochrome.vs.glsl -// -// Copyright © 2019 The Pathfinder Project Developers. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#extension GL_GOOGLE_include_directive : enable - -precision highp float; - -#include "tile_alpha_vertex.inc.glsl" -#include "tile_monochrome.inc.glsl" - -void main() { - computeVaryings(); -} diff --git a/shaders/tile_alpha_multicolor.vs.glsl b/shaders/tile_alpha_multicolor.vs.glsl deleted file mode 100644 index 823016dd..00000000 --- a/shaders/tile_alpha_multicolor.vs.glsl +++ /dev/null @@ -1,22 +0,0 @@ -#version 330 - -// pathfinder/shaders/tile_alpha_multicolor.vs.glsl -// -// Copyright © 2019 The Pathfinder Project Developers. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#extension GL_GOOGLE_include_directive : enable - -precision highp float; - -#include "tile_alpha_vertex.inc.glsl" -#include "tile_multicolor.inc.glsl" - -void main() { - computeVaryings(); -} diff --git a/shaders/tile_monochrome.inc.glsl b/shaders/tile_monochrome.inc.glsl deleted file mode 100644 index 3e27f749..00000000 --- a/shaders/tile_monochrome.inc.glsl +++ /dev/null @@ -1,15 +0,0 @@ -// pathfinder/shaders/tile_monochrome.inc.glsl -// -// Copyright © 2019 The Pathfinder Project Developers. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -uniform vec4 uColor; - -vec4 getColor() { - return uColor; -} diff --git a/shaders/tile_multicolor.inc.glsl b/shaders/tile_multicolor.inc.glsl deleted file mode 100644 index 4520625b..00000000 --- a/shaders/tile_multicolor.inc.glsl +++ /dev/null @@ -1,18 +0,0 @@ -// pathfinder/shaders/tile_multicolor.inc.glsl -// -// Copyright © 2019 The Pathfinder Project Developers. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -uniform sampler2D uPaintTexture; -uniform vec2 uPaintTextureSize; - -in vec2 aColorTexCoord; - -vec4 getColor() { - return texture(uPaintTexture, aColorTexCoord); -} diff --git a/shaders/tile_solid.fs.glsl b/shaders/tile_solid.fs.glsl index eed63042..1c75b97f 100644 --- a/shaders/tile_solid.fs.glsl +++ b/shaders/tile_solid.fs.glsl @@ -12,10 +12,13 @@ precision highp float; -in vec4 vColor; +uniform sampler2D uPaintTexture; +uniform vec2 uPaintTextureSize; + +in vec2 vColorTexCoord; out vec4 oFragColor; void main() { - oFragColor = vColor; + oFragColor = texture(uPaintTexture, vColorTexCoord); } diff --git a/shaders/tile_solid_vertex.inc.glsl b/shaders/tile_solid.vs.glsl similarity index 76% rename from shaders/tile_solid_vertex.inc.glsl rename to shaders/tile_solid.vs.glsl index da7d19f2..4707afe2 100644 --- a/shaders/tile_solid_vertex.inc.glsl +++ b/shaders/tile_solid.vs.glsl @@ -1,4 +1,6 @@ -// pathfinder/shaders/tile_solid_vertex.inc.glsl +#version 330 + +// pathfinder/shaders/tile_solid.vs.glsl // // Copyright © 2019 The Pathfinder Project Developers. // @@ -8,18 +10,19 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +precision highp float; + uniform mat4 uTransform; uniform vec2 uTileSize; in uvec2 aTessCoord; in ivec2 aTileOrigin; +in vec2 aColorTexCoord; -out vec4 vColor; +out vec2 vColorTexCoord; -vec4 getColor(); - -void computeVaryings() { +void main() { vec2 position = vec2(aTileOrigin + ivec2(aTessCoord)) * uTileSize; - vColor = getColor(); + vColorTexCoord = aColorTexCoord; gl_Position = uTransform * vec4(position, 0.0, 1.0); } diff --git a/shaders/tile_solid_monochrome.vs.glsl b/shaders/tile_solid_monochrome.vs.glsl deleted file mode 100644 index cf6f61e7..00000000 --- a/shaders/tile_solid_monochrome.vs.glsl +++ /dev/null @@ -1,22 +0,0 @@ -#version 330 - -// pathfinder/shaders/tile_solid_monochrome.vs.glsl -// -// Copyright © 2019 The Pathfinder Project Developers. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#extension GL_GOOGLE_include_directive : enable - -precision highp float; - -#include "tile_solid_vertex.inc.glsl" -#include "tile_monochrome.inc.glsl" - -void main() { - computeVaryings(); -} diff --git a/shaders/tile_solid_multicolor.vs.glsl b/shaders/tile_solid_multicolor.vs.glsl deleted file mode 100644 index 34ee0f20..00000000 --- a/shaders/tile_solid_multicolor.vs.glsl +++ /dev/null @@ -1,22 +0,0 @@ -#version 330 - -// pathfinder/shaders/tile_solid_multicolor.vs.glsl -// -// Copyright © 2019 The Pathfinder Project Developers. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#extension GL_GOOGLE_include_directive : enable - -precision highp float; - -#include "tile_solid_vertex.inc.glsl" -#include "tile_multicolor.inc.glsl" - -void main() { - computeVaryings(); -}