diff --git a/gl/src/lib.rs b/gl/src/lib.rs index baec4e26..ae0d2140 100644 --- a/gl/src/lib.rs +++ b/gl/src/lib.rs @@ -225,18 +225,12 @@ impl Device for GLDevice { texture } - fn create_shader_from_source(&self, - resources: &dyn ResourceLoader, - name: &str, - source: &[u8], - kind: ShaderKind, - includes: &[&str]) - -> GLShader { + fn create_shader_from_source(&self, name: &str, source: &[u8], kind: ShaderKind) -> GLShader { // FIXME(pcwalton): Do this once and cache it. let glsl_version_spec = self.version.to_glsl_version_spec(); let mut output = vec![]; - self.preprocess(&mut output, resources, source, includes, glsl_version_spec); + self.preprocess(&mut output, source, glsl_version_spec); let source = output; let gl_shader_kind = match kind { @@ -650,12 +644,7 @@ impl Device for GLDevice { } impl GLDevice { - fn preprocess(&self, - output: &mut Vec, - resources: &dyn ResourceLoader, - source: &[u8], - includes: &[&str], - version: &str) { + fn preprocess(&self, output: &mut Vec, source: &[u8], version: &str) { let mut index = 0; while index < source.len() { if source[index..].starts_with(b"{{") { @@ -666,12 +655,6 @@ impl GLDevice { let ident = String::from_utf8_lossy(&source[(index + 2)..end_index]); if ident == "version" { output.extend_from_slice(version.as_bytes()); - } else if ident.starts_with("include_") { - let include_name = &ident["include_".len()..]; - if includes.iter().any(|include| *include == include_name) { - let include_source = self.load_shader_include(resources, include_name); - self.preprocess(output, resources, &include_source, includes, version); - } } else { panic!("unknown template variable: `{}`", ident); } diff --git a/gpu/src/lib.rs b/gpu/src/lib.rs index fdbab686..cfe4b4ee 100644 --- a/gpu/src/lib.rs +++ b/gpu/src/lib.rs @@ -21,15 +21,6 @@ use std::time::Duration; pub mod resources; -static INCLUDES: [&str; 6] = [ - "tile_alpha_vertex", - "tile_monochrome", - "tile_multicolor", - "tile_solid_vertex", - "post_convolve", - "post_gamma_correct", -]; - pub trait Device { type Buffer; type Framebuffer; @@ -43,14 +34,8 @@ pub trait Device { fn create_texture(&self, format: TextureFormat, size: Vector2I) -> Self::Texture; fn create_texture_from_data(&self, size: Vector2I, data: &[u8]) -> Self::Texture; - fn create_shader_from_source( - &self, - resources: &dyn ResourceLoader, - name: &str, - source: &[u8], - kind: ShaderKind, - includes: &[&str], - ) -> Self::Shader; + fn create_shader_from_source(&self, name: &str, source: &[u8], kind: ShaderKind) + -> Self::Shader; fn create_vertex_array(&self) -> Self::VertexArray; fn create_program_from_shaders( &self, @@ -117,8 +102,8 @@ pub trait Device { ShaderKind::Vertex => 'v', ShaderKind::Fragment => 'f', }; - let source = resources.slurp(&format!("shaders/{}.{}s.glsl", name, suffix)).unwrap(); - self.create_shader_from_source(resources, name, &source, kind, &INCLUDES) + let source = resources.slurp(&format!("shaders/gl3/{}.{}s.glsl", name, suffix)).unwrap(); + self.create_shader_from_source(name, &source, kind) } fn create_program_from_shader_names( @@ -137,10 +122,6 @@ pub trait Device { fn create_program(&self, resources: &dyn ResourceLoader, name: &str) -> Self::Program { self.create_program_from_shader_names(resources, name, name, name) } - - fn load_shader_include(&self, resources: &dyn ResourceLoader, include_name: &str) -> Vec { - resources.slurp(&format!("shaders/{}.inc.glsl", include_name)).unwrap() - } } #[derive(Clone, Copy, Debug)] diff --git a/resources/shaders/README.md b/resources/shaders/README.md new file mode 100644 index 00000000..24bff80f --- /dev/null +++ b/resources/shaders/README.md @@ -0,0 +1,7 @@ +This directory contains postprocessed versions of the shaders in the top-level +`shaders/` directory, for convenience. Don't modify the shaders here; instead +modify the corresponding shaders in `shaders/` and rerun `make` in that +directory. + +You will need `glslangValidator` and `spirv-cross` installed to execute the +Makefile. On macOS, you can get these with `brew install glslang spirv-cross`. diff --git a/resources/shaders/gl3/debug_solid.fs.glsl b/resources/shaders/gl3/debug_solid.fs.glsl new file mode 100644 index 00000000..eeaaf489 --- /dev/null +++ b/resources/shaders/gl3/debug_solid.fs.glsl @@ -0,0 +1,22 @@ +#version {{version}} + + + + + + + + + + + +precision highp float; + +uniform vec4 uColor; + +out vec4 oFragColor; + +void main(){ + oFragColor = vec4(uColor . rgb, 1.0)* uColor . a; +} + diff --git a/resources/shaders/gl3/debug_solid.vs.glsl b/resources/shaders/gl3/debug_solid.vs.glsl new file mode 100644 index 00000000..3c38f3f7 --- /dev/null +++ b/resources/shaders/gl3/debug_solid.vs.glsl @@ -0,0 +1,23 @@ +#version {{version}} + + + + + + + + + + + +precision highp float; + +uniform vec2 uFramebufferSize; + +in vec2 aPosition; + +void main(){ + vec2 position = aPosition / uFramebufferSize * 2.0 - 1.0; + gl_Position = vec4(position . x, - position . y, 0.0, 1.0); +} + diff --git a/resources/shaders/gl3/debug_texture.fs.glsl b/resources/shaders/gl3/debug_texture.fs.glsl new file mode 100644 index 00000000..9601adf2 --- /dev/null +++ b/resources/shaders/gl3/debug_texture.fs.glsl @@ -0,0 +1,26 @@ +#version {{version}} + + + + + + + + + + + +precision highp float; + +uniform sampler2D uTexture; +uniform vec4 uColor; + +in vec2 vTexCoord; + +out vec4 oFragColor; + +void main(){ + float alpha = texture(uTexture, vTexCoord). r * uColor . a; + oFragColor = alpha * vec4(uColor . rgb, 1.0); +} + diff --git a/resources/shaders/gl3/debug_texture.vs.glsl b/resources/shaders/gl3/debug_texture.vs.glsl new file mode 100644 index 00000000..b3b546d8 --- /dev/null +++ b/resources/shaders/gl3/debug_texture.vs.glsl @@ -0,0 +1,28 @@ +#version {{version}} + + + + + + + + + + + +precision highp float; + +uniform vec2 uFramebufferSize; +uniform vec2 uTextureSize; + +in vec2 aPosition; +in vec2 aTexCoord; + +out vec2 vTexCoord; + +void main(){ + vTexCoord = aTexCoord / uTextureSize; + vec2 position = aPosition / uFramebufferSize * 2.0 - 1.0; + gl_Position = vec4(position . x, - position . y, 0.0, 1.0); +} + diff --git a/resources/shaders/gl3/demo_ground.fs.glsl b/resources/shaders/gl3/demo_ground.fs.glsl new file mode 100644 index 00000000..3bf84270 --- /dev/null +++ b/resources/shaders/gl3/demo_ground.fs.glsl @@ -0,0 +1,26 @@ +#version {{version}} + + + + + + + + + + + +precision highp float; + +uniform vec4 uGroundColor; +uniform vec4 uGridlineColor; + +in vec2 vTexCoord; + +out vec4 oFragColor; + +void main(){ + vec2 texCoordPx = fract(vTexCoord)/ fwidth(vTexCoord); + oFragColor = any(lessThanEqual(texCoordPx, vec2(1.0)))? uGridlineColor : uGroundColor; +} + diff --git a/resources/shaders/gl3/demo_ground.vs.glsl b/resources/shaders/gl3/demo_ground.vs.glsl new file mode 100644 index 00000000..418eb50a --- /dev/null +++ b/resources/shaders/gl3/demo_ground.vs.glsl @@ -0,0 +1,26 @@ +#version {{version}} + + + + + + + + + + + +precision highp float; + +uniform mat4 uTransform; +uniform int uGridlineCount; + +in vec2 aPosition; + +out vec2 vTexCoord; + +void main(){ + vTexCoord = aPosition * float(uGridlineCount); + gl_Position = uTransform * vec4(aPosition . x, 0.0, aPosition . y, 1.0); +} + diff --git a/resources/shaders/gl3/fill.fs.glsl b/resources/shaders/gl3/fill.fs.glsl new file mode 100644 index 00000000..aeebe141 --- /dev/null +++ b/resources/shaders/gl3/fill.fs.glsl @@ -0,0 +1,42 @@ +#version {{version}} + + + + + + + + + + + +precision highp float; + +uniform sampler2D uAreaLUT; + +in vec2 vFrom; +in vec2 vTo; + +out vec4 oFragColor; + +void main(){ + + vec2 from = vFrom, to = vTo; + + + vec2 left = from . x < to . x ? from : to, right = from . x < to . x ? to : from; + + + vec2 window = clamp(vec2(from . x, to . x), - 0.5, 0.5); + float offset = mix(window . x, window . y, 0.5)- left . x; + float t = offset /(right . x - left . x); + + + float y = mix(left . y, right . y, t); + float d =(right . y - left . y)/(right . x - left . x); + + + float dX = window . x - window . y; + oFragColor = vec4(texture(uAreaLUT, vec2(y + 8.0, abs(d * dX))/ 16.0). r * dX); +} + diff --git a/resources/shaders/gl3/fill.vs.glsl b/resources/shaders/gl3/fill.vs.glsl new file mode 100644 index 00000000..fac4560a --- /dev/null +++ b/resources/shaders/gl3/fill.vs.glsl @@ -0,0 +1,55 @@ +#version {{version}} + + + + + + + + + + + +precision highp float; + +uniform vec2 uFramebufferSize; +uniform vec2 uTileSize; + +in vec2 aTessCoord; +in uint aFromPx; +in uint aToPx; +in vec2 aFromSubpx; +in vec2 aToSubpx; +in uint aTileIndex; + +out vec2 vFrom; +out vec2 vTo; + +vec2 computeTileOffset(uint tileIndex, float stencilTextureWidth){ + uint tilesPerRow = uint(stencilTextureWidth / uTileSize . x); + uvec2 tileOffset = uvec2(aTileIndex % tilesPerRow, aTileIndex / tilesPerRow); + return vec2(tileOffset)* uTileSize; +} + +void main(){ + vec2 tileOrigin = computeTileOffset(aTileIndex, uFramebufferSize . x); + + vec2 from = vec2(aFromPx & 15u, aFromPx >> 4u)+ aFromSubpx; + vec2 to = vec2(aToPx & 15u, aToPx >> 4u)+ aToSubpx; + + vec2 position; + if(aTessCoord . x < 0.5) + position . x = floor(min(from . x, to . x)); + else + position . x = ceil(max(from . x, to . x)); + if(aTessCoord . y < 0.5) + position . y = floor(min(from . y, to . y)); + else + position . y = uTileSize . y; + + vFrom = from - position; + vTo = to - position; + + gl_Position = vec4((tileOrigin + position)/ uFramebufferSize * 2.0 - 1.0, 0.0, 1.0); +} + diff --git a/resources/shaders/gl3/post.fs.glsl b/resources/shaders/gl3/post.fs.glsl new file mode 100644 index 00000000..0a74556b --- /dev/null +++ b/resources/shaders/gl3/post.fs.glsl @@ -0,0 +1,125 @@ +#version {{version}} + + + + + + + + + + + + + + +#extension GL_GOOGLE_include_directive : enable + +precision highp float; + +uniform sampler2D uSource; +uniform vec2 uSourceSize; +uniform vec4 uFGColor; +uniform vec4 uBGColor; +uniform int uGammaCorrectionEnabled; + +in vec2 vTexCoord; + +out vec4 oFragColor; + + + + + + + + + + + + + + +uniform sampler2D uGammaLUT; + +float gammaCorrectChannel(float bgColor, float fgColor){ + return texture(uGammaLUT, vec2(fgColor, 1.0 - bgColor)). r; +} + + +vec3 gammaCorrect(vec3 bgColor, vec3 fgColor){ + return vec3(gammaCorrectChannel(bgColor . r, fgColor . r), + gammaCorrectChannel(bgColor . g, fgColor . g), + gammaCorrectChannel(bgColor . b, fgColor . b)); +} + + + + + + + + + + + + + +uniform vec4 uKernel; + + + +float sample1Tap(float offset); + + +void sample9Tap(out vec4 outAlphaLeft, + out float outAlphaCenter, + out vec4 outAlphaRight, + float onePixel){ + outAlphaLeft = vec4(uKernel . x > 0.0 ? sample1Tap(- 4.0 * onePixel): 0.0, + sample1Tap(- 3.0 * onePixel), + sample1Tap(- 2.0 * onePixel), + sample1Tap(- 1.0 * onePixel)); + outAlphaCenter = sample1Tap(0.0); + outAlphaRight = vec4(sample1Tap(1.0 * onePixel), + sample1Tap(2.0 * onePixel), + sample1Tap(3.0 * onePixel), + uKernel . x > 0.0 ? sample1Tap(4.0 * onePixel): 0.0); +} + + +float convolve7Tap(vec4 alpha0, vec3 alpha1){ + return dot(alpha0, uKernel)+ dot(alpha1, uKernel . zyx); +} + + + +float sample1Tap(float offset){ + return texture(uSource, vec2(vTexCoord . x + offset, vTexCoord . y)). r; +} + +void main(){ + + vec3 alpha; + if(uKernel . w == 0.0){ + alpha = texture(uSource, vTexCoord). rrr; + } else { + vec4 alphaLeft, alphaRight; + float alphaCenter; + sample9Tap(alphaLeft, alphaCenter, alphaRight, 1.0 / uSourceSize . x); + + float r = convolve7Tap(alphaLeft, vec3(alphaCenter, alphaRight . xy)); + float g = convolve7Tap(vec4(alphaLeft . yzw, alphaCenter), alphaRight . xyz); + float b = convolve7Tap(vec4(alphaLeft . zw, alphaCenter, alphaRight . x), alphaRight . yzw); + + alpha = vec3(r, g, b); + } + + + if(uGammaCorrectionEnabled != 0) + alpha = gammaCorrect(uBGColor . rgb, alpha); + + + oFragColor = vec4(mix(uBGColor . rgb, uFGColor . rgb, alpha), 1.0); +} + diff --git a/resources/shaders/gl3/post.vs.glsl b/resources/shaders/gl3/post.vs.glsl new file mode 100644 index 00000000..29e75ade --- /dev/null +++ b/resources/shaders/gl3/post.vs.glsl @@ -0,0 +1,23 @@ +#version {{version}} + + + + + + + + + + + +precision highp float; + +in vec2 aPosition; + +out vec2 vTexCoord; + +void main(){ + vTexCoord = aPosition; + gl_Position = vec4(aPosition * 2.0 - 1.0, 0.0, 1.0); +} + diff --git a/resources/shaders/gl3/reproject.fs.glsl b/resources/shaders/gl3/reproject.fs.glsl new file mode 100644 index 00000000..427b632c --- /dev/null +++ b/resources/shaders/gl3/reproject.fs.glsl @@ -0,0 +1,27 @@ +#version {{version}} + + + + + + + + + + + +precision highp float; + +uniform mat4 uOldTransform; +uniform sampler2D uTexture; + +in vec2 vTexCoord; + +out vec4 oFragColor; + +void main(){ + vec4 normTexCoord = uOldTransform * vec4(vTexCoord, 0.0, 1.0); + vec2 texCoord =((normTexCoord . xy / normTexCoord . w)+ 1.0)* 0.5; + oFragColor = texture(uTexture, texCoord); +} + diff --git a/resources/shaders/gl3/reproject.vs.glsl b/resources/shaders/gl3/reproject.vs.glsl new file mode 100644 index 00000000..d1c70544 --- /dev/null +++ b/resources/shaders/gl3/reproject.vs.glsl @@ -0,0 +1,25 @@ +#version {{version}} + + + + + + + + + + + +precision highp float; + +uniform mat4 uNewTransform; + +in vec2 aPosition; + +out vec2 vTexCoord; + +void main(){ + vTexCoord = aPosition; + gl_Position = uNewTransform * vec4(aPosition, 0.0, 1.0); +} + diff --git a/resources/shaders/gl3/stencil.fs.glsl b/resources/shaders/gl3/stencil.fs.glsl new file mode 100644 index 00000000..e2e093ab --- /dev/null +++ b/resources/shaders/gl3/stencil.fs.glsl @@ -0,0 +1,21 @@ +#version {{version}} + + + + + + + + + + + +precision highp float; + +out vec4 oFragColor; + +void main(){ + + oFragColor = vec4(1.0, 0.0, 0.0, 1.0); +} + diff --git a/resources/shaders/gl3/stencil.vs.glsl b/resources/shaders/gl3/stencil.vs.glsl new file mode 100644 index 00000000..2fee81a2 --- /dev/null +++ b/resources/shaders/gl3/stencil.vs.glsl @@ -0,0 +1,20 @@ +#version {{version}} + + + + + + + + + + + +precision highp float; + +in vec3 aPosition; + +void main(){ + gl_Position = vec4(aPosition, 1.0); +} + diff --git a/resources/shaders/gl3/tile_alpha.fs.glsl b/resources/shaders/gl3/tile_alpha.fs.glsl new file mode 100644 index 00000000..3af9cf4d --- /dev/null +++ b/resources/shaders/gl3/tile_alpha.fs.glsl @@ -0,0 +1,27 @@ +#version {{version}} + + + + + + + + + + + +precision highp float; + +uniform sampler2D uStencilTexture; + +in vec2 vTexCoord; +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); +} + diff --git a/resources/shaders/gl3/tile_alpha_monochrome.vs.glsl b/resources/shaders/gl3/tile_alpha_monochrome.vs.glsl new file mode 100644 index 00000000..d99d7dd7 --- /dev/null +++ b/resources/shaders/gl3/tile_alpha_monochrome.vs.glsl @@ -0,0 +1,85 @@ +#version {{version}} + + + + + + + + + + + +#extension GL_GOOGLE_include_directive : enable + +precision highp float; + + + + + + + + + + + + +uniform vec2 uFramebufferSize; +uniform vec2 uTileSize; +uniform vec2 uStencilTextureSize; +uniform vec2 uViewBoxOrigin; + +in vec2 aTessCoord; +in uvec3 aTileOrigin; +in int aBackdrop; +in uint aTileIndex; + +out vec2 vTexCoord; +out float vBackdrop; +out vec4 vColor; + +vec4 getColor(); + +vec2 computeTileOffset(uint tileIndex, float stencilTextureWidth){ + uint tilesPerRow = uint(stencilTextureWidth / uTileSize . x); + uvec2 tileOffset = uvec2(tileIndex % tilesPerRow, tileIndex / tilesPerRow); + return vec2(tileOffset)* uTileSize; +} + +void computeVaryings(){ + vec2 origin = vec2(aTileOrigin . xy)+ vec2(aTileOrigin . z & 15u, aTileOrigin . z >> 4u)* 256.0; + vec2 pixelPosition =(origin + aTessCoord)* uTileSize + uViewBoxOrigin; + vec2 position =(pixelPosition / uFramebufferSize * 2.0 - 1.0)* vec2(1.0, - 1.0); + vec2 maskTexCoordOrigin = computeTileOffset(aTileIndex, uStencilTextureSize . x); + vec2 maskTexCoord = maskTexCoordOrigin + aTessCoord * uTileSize; + + vTexCoord = maskTexCoord / uStencilTextureSize; + vBackdrop = float(aBackdrop); + vColor = getColor(); + gl_Position = vec4(position, 0.0, 1.0); +} + + + + + + + + + + + + + +uniform vec4 uColor; + +vec4 getColor(){ + return uColor; +} + + +void main(){ + computeVaryings(); +} + diff --git a/resources/shaders/gl3/tile_alpha_multicolor.vs.glsl b/resources/shaders/gl3/tile_alpha_multicolor.vs.glsl new file mode 100644 index 00000000..be655748 --- /dev/null +++ b/resources/shaders/gl3/tile_alpha_multicolor.vs.glsl @@ -0,0 +1,88 @@ +#version {{version}} + + + + + + + + + + + +#extension GL_GOOGLE_include_directive : enable + +precision highp float; + + + + + + + + + + + + +uniform vec2 uFramebufferSize; +uniform vec2 uTileSize; +uniform vec2 uStencilTextureSize; +uniform vec2 uViewBoxOrigin; + +in vec2 aTessCoord; +in uvec3 aTileOrigin; +in int aBackdrop; +in uint aTileIndex; + +out vec2 vTexCoord; +out float vBackdrop; +out vec4 vColor; + +vec4 getColor(); + +vec2 computeTileOffset(uint tileIndex, float stencilTextureWidth){ + uint tilesPerRow = uint(stencilTextureWidth / uTileSize . x); + uvec2 tileOffset = uvec2(tileIndex % tilesPerRow, tileIndex / tilesPerRow); + return vec2(tileOffset)* uTileSize; +} + +void computeVaryings(){ + vec2 origin = vec2(aTileOrigin . xy)+ vec2(aTileOrigin . z & 15u, aTileOrigin . z >> 4u)* 256.0; + vec2 pixelPosition =(origin + aTessCoord)* uTileSize + uViewBoxOrigin; + vec2 position =(pixelPosition / uFramebufferSize * 2.0 - 1.0)* vec2(1.0, - 1.0); + vec2 maskTexCoordOrigin = computeTileOffset(aTileIndex, uStencilTextureSize . x); + vec2 maskTexCoord = maskTexCoordOrigin + aTessCoord * uTileSize; + + vTexCoord = maskTexCoord / uStencilTextureSize; + vBackdrop = float(aBackdrop); + vColor = getColor(); + gl_Position = vec4(position, 0.0, 1.0); +} + + + + + + + + + + + + + +uniform sampler2D uPaintTexture; +uniform vec2 uPaintTextureSize; + +in vec2 aColorTexCoord; + +vec4 getColor(){ + return texture(uPaintTexture, aColorTexCoord); +} + + +void main(){ + computeVaryings(); +} + diff --git a/resources/shaders/gl3/tile_solid.fs.glsl b/resources/shaders/gl3/tile_solid.fs.glsl new file mode 100644 index 00000000..2079d945 --- /dev/null +++ b/resources/shaders/gl3/tile_solid.fs.glsl @@ -0,0 +1,22 @@ +#version {{version}} + + + + + + + + + + + +precision highp float; + +in vec4 vColor; + +out vec4 oFragColor; + +void main(){ + oFragColor = vColor; +} + diff --git a/resources/shaders/gl3/tile_solid_monochrome.vs.glsl b/resources/shaders/gl3/tile_solid_monochrome.vs.glsl new file mode 100644 index 00000000..d7544c26 --- /dev/null +++ b/resources/shaders/gl3/tile_solid_monochrome.vs.glsl @@ -0,0 +1,69 @@ +#version {{version}} + + + + + + + + + + + +#extension GL_GOOGLE_include_directive : enable + +precision highp float; + + + + + + + + + + + + +uniform vec2 uFramebufferSize; +uniform vec2 uTileSize; +uniform vec2 uViewBoxOrigin; + +in vec2 aTessCoord; +in vec2 aTileOrigin; + +out vec4 vColor; + +vec4 getColor(); + +void computeVaryings(){ + vec2 pixelPosition =(aTileOrigin + aTessCoord)* uTileSize + uViewBoxOrigin; + vec2 position =(pixelPosition / uFramebufferSize * 2.0 - 1.0)* vec2(1.0, - 1.0); + + vColor = getColor(); + + gl_Position = vec4(position, 0.0, 1.0); +} + + + + + + + + + + + + +uniform vec4 uColor; + +vec4 getColor(){ + return uColor; +} + + +void main(){ + computeVaryings(); +} + diff --git a/resources/shaders/gl3/tile_solid_multicolor.vs.glsl b/resources/shaders/gl3/tile_solid_multicolor.vs.glsl new file mode 100644 index 00000000..0e23e0a4 --- /dev/null +++ b/resources/shaders/gl3/tile_solid_multicolor.vs.glsl @@ -0,0 +1,72 @@ +#version {{version}} + + + + + + + + + + + +#extension GL_GOOGLE_include_directive : enable + +precision highp float; + + + + + + + + + + + + +uniform vec2 uFramebufferSize; +uniform vec2 uTileSize; +uniform vec2 uViewBoxOrigin; + +in vec2 aTessCoord; +in vec2 aTileOrigin; + +out vec4 vColor; + +vec4 getColor(); + +void computeVaryings(){ + vec2 pixelPosition =(aTileOrigin + aTessCoord)* uTileSize + uViewBoxOrigin; + vec2 position =(pixelPosition / uFramebufferSize * 2.0 - 1.0)* vec2(1.0, - 1.0); + + vColor = getColor(); + + gl_Position = vec4(position, 0.0, 1.0); +} + + + + + + + + + + + + +uniform sampler2D uPaintTexture; +uniform vec2 uPaintTextureSize; + +in vec2 aColorTexCoord; + +vec4 getColor(){ + return texture(uPaintTexture, aColorTexCoord); +} + + +void main(){ + computeVaryings(); +} + diff --git a/resources/shaders/metal/debug_solid.fs.metal b/resources/shaders/metal/debug_solid.fs.metal new file mode 100644 index 00000000..6fc13e2f --- /dev/null +++ b/resources/shaders/metal/debug_solid.fs.metal @@ -0,0 +1,17 @@ +#include +#include + +using namespace metal; + +struct main0_out +{ + float4 oFragColor [[color(0)]]; +}; + +fragment main0_out main0(float4 uColor [[buffer(0)]]) +{ + main0_out out = {}; + out.oFragColor = float4(uColor.xyz, 1.0) * uColor.w; + return out; +} + diff --git a/resources/shaders/metal/debug_solid.vs.metal b/resources/shaders/metal/debug_solid.vs.metal new file mode 100644 index 00000000..bcad2a03 --- /dev/null +++ b/resources/shaders/metal/debug_solid.vs.metal @@ -0,0 +1,23 @@ +#include +#include + +using namespace metal; + +struct main0_out +{ + float4 gl_Position [[position]]; +}; + +struct main0_in +{ + float2 aPosition [[attribute(0)]]; +}; + +vertex main0_out main0(main0_in in [[stage_in]], float2 uFramebufferSize [[buffer(0)]], uint gl_VertexID [[vertex_id]], uint gl_InstanceID [[instance_id]]) +{ + main0_out out = {}; + float2 position = ((in.aPosition / uFramebufferSize) * 2.0) - float2(1.0); + out.gl_Position = float4(position.x, -position.y, 0.0, 1.0); + return out; +} + diff --git a/resources/shaders/metal/debug_texture.fs.metal b/resources/shaders/metal/debug_texture.fs.metal new file mode 100644 index 00000000..67bc2370 --- /dev/null +++ b/resources/shaders/metal/debug_texture.fs.metal @@ -0,0 +1,23 @@ +#include +#include + +using namespace metal; + +struct main0_out +{ + float4 oFragColor [[color(0)]]; +}; + +struct main0_in +{ + float2 vTexCoord [[user(locn0)]]; +}; + +fragment main0_out main0(main0_in in [[stage_in]], float4 uColor [[buffer(0)]], texture2d uTexture [[texture(0)]], sampler uTextureSmplr [[sampler(0)]]) +{ + main0_out out = {}; + float alpha = uTexture.sample(uTextureSmplr, in.vTexCoord).x * uColor.w; + out.oFragColor = float4(uColor.xyz, 1.0) * alpha; + return out; +} + diff --git a/resources/shaders/metal/debug_texture.vs.metal b/resources/shaders/metal/debug_texture.vs.metal new file mode 100644 index 00000000..25eb20b8 --- /dev/null +++ b/resources/shaders/metal/debug_texture.vs.metal @@ -0,0 +1,26 @@ +#include +#include + +using namespace metal; + +struct main0_out +{ + float2 vTexCoord [[user(locn0)]]; + float4 gl_Position [[position]]; +}; + +struct main0_in +{ + float2 aPosition [[attribute(0)]]; + float2 aTexCoord [[attribute(1)]]; +}; + +vertex main0_out main0(main0_in in [[stage_in]], float2 uTextureSize [[buffer(0)]], float2 uFramebufferSize [[buffer(1)]], uint gl_VertexID [[vertex_id]], uint gl_InstanceID [[instance_id]]) +{ + main0_out out = {}; + out.vTexCoord = in.aTexCoord / uTextureSize; + float2 position = ((in.aPosition / uFramebufferSize) * 2.0) - float2(1.0); + out.gl_Position = float4(position.x, -position.y, 0.0, 1.0); + return out; +} + diff --git a/resources/shaders/metal/demo_ground.fs.metal b/resources/shaders/metal/demo_ground.fs.metal new file mode 100644 index 00000000..919b2f37 --- /dev/null +++ b/resources/shaders/metal/demo_ground.fs.metal @@ -0,0 +1,24 @@ +#include +#include + +using namespace metal; + +struct main0_out +{ + float4 oFragColor [[color(0)]]; +}; + +struct main0_in +{ + float2 vTexCoord [[user(locn0)]]; +}; + +fragment main0_out main0(main0_in in [[stage_in]], float4 uGridlineColor [[buffer(0)]], float4 uGroundColor [[buffer(1)]]) +{ + main0_out out = {}; + float2 texCoordPx = fract(in.vTexCoord) / fwidth(in.vTexCoord); + bool4 _33 = bool4(any(texCoordPx <= float2(1.0))); + out.oFragColor = float4(_33.x ? uGridlineColor.x : uGroundColor.x, _33.y ? uGridlineColor.y : uGroundColor.y, _33.z ? uGridlineColor.z : uGroundColor.z, _33.w ? uGridlineColor.w : uGroundColor.w); + return out; +} + diff --git a/resources/shaders/metal/demo_ground.vs.metal b/resources/shaders/metal/demo_ground.vs.metal new file mode 100644 index 00000000..049083ea --- /dev/null +++ b/resources/shaders/metal/demo_ground.vs.metal @@ -0,0 +1,24 @@ +#include +#include + +using namespace metal; + +struct main0_out +{ + float2 vTexCoord [[user(locn0)]]; + float4 gl_Position [[position]]; +}; + +struct main0_in +{ + float2 aPosition [[attribute(0)]]; +}; + +vertex main0_out main0(main0_in in [[stage_in]], int uGridlineCount [[buffer(0)]], float4x4 uTransform [[buffer(1)]], uint gl_VertexID [[vertex_id]], uint gl_InstanceID [[instance_id]]) +{ + main0_out out = {}; + out.vTexCoord = in.aPosition * float(uGridlineCount); + out.gl_Position = uTransform * float4(in.aPosition.x, 0.0, in.aPosition.y, 1.0); + return out; +} + diff --git a/resources/shaders/metal/fill.fs.metal b/resources/shaders/metal/fill.fs.metal new file mode 100644 index 00000000..d002bba6 --- /dev/null +++ b/resources/shaders/metal/fill.fs.metal @@ -0,0 +1,35 @@ +#include +#include + +using namespace metal; + +struct main0_out +{ + float4 oFragColor [[color(0)]]; +}; + +struct main0_in +{ + float2 vFrom [[user(locn0)]]; + float2 vTo [[user(locn1)]]; +}; + +fragment main0_out main0(main0_in in [[stage_in]], texture2d uAreaLUT [[texture(0)]], sampler uAreaLUTSmplr [[sampler(0)]]) +{ + main0_out out = {}; + float2 from = in.vFrom; + float2 to = in.vTo; + bool2 _29 = bool2(from.x < to.x); + float2 left = float2(_29.x ? from.x : to.x, _29.y ? from.y : to.y); + bool2 _39 = bool2(from.x < to.x); + float2 right = float2(_39.x ? to.x : from.x, _39.y ? to.y : from.y); + float2 window = fast::clamp(float2(from.x, to.x), float2(-0.5), float2(0.5)); + float offset = mix(window.x, window.y, 0.5) - left.x; + float t = offset / (right.x - left.x); + float y = mix(left.y, right.y, t); + float d = (right.y - left.y) / (right.x - left.x); + float dX = window.x - window.y; + out.oFragColor = float4(uAreaLUT.sample(uAreaLUTSmplr, (float2(y + 8.0, abs(d * dX)) / float2(16.0))).x * dX); + return out; +} + diff --git a/resources/shaders/metal/fill.vs.metal b/resources/shaders/metal/fill.vs.metal new file mode 100644 index 00000000..1c545156 --- /dev/null +++ b/resources/shaders/metal/fill.vs.metal @@ -0,0 +1,62 @@ +#pragma clang diagnostic ignored "-Wmissing-prototypes" + +#include +#include + +using namespace metal; + +struct main0_out +{ + float2 vFrom [[user(locn0)]]; + float2 vTo [[user(locn1)]]; + float4 gl_Position [[position]]; +}; + +struct main0_in +{ + float2 aTessCoord [[attribute(0)]]; + uint aFromPx [[attribute(1)]]; + uint aToPx [[attribute(2)]]; + float2 aFromSubpx [[attribute(3)]]; + float2 aToSubpx [[attribute(4)]]; + uint aTileIndex [[attribute(5)]]; +}; + +float2 computeTileOffset(thread const uint& tileIndex, thread const float& stencilTextureWidth, thread float2 uTileSize, thread uint& aTileIndex) +{ + uint tilesPerRow = uint(stencilTextureWidth / uTileSize.x); + uint2 tileOffset = uint2(aTileIndex % tilesPerRow, aTileIndex / tilesPerRow); + return float2(tileOffset) * uTileSize; +} + +vertex main0_out main0(main0_in in [[stage_in]], float2 uTileSize [[buffer(0)]], float2 uFramebufferSize [[buffer(1)]], uint gl_VertexID [[vertex_id]], uint gl_InstanceID [[instance_id]]) +{ + main0_out out = {}; + uint param = in.aTileIndex; + float param_1 = uFramebufferSize.x; + float2 tileOrigin = computeTileOffset(param, param_1, uTileSize, in.aTileIndex); + float2 from = float2(float(in.aFromPx & 15u), float(in.aFromPx >> 4u)) + in.aFromSubpx; + float2 to = float2(float(in.aToPx & 15u), float(in.aToPx >> 4u)) + in.aToSubpx; + float2 position; + if (in.aTessCoord.x < 0.5) + { + position.x = floor(fast::min(from.x, to.x)); + } + else + { + position.x = ceil(fast::max(from.x, to.x)); + } + if (in.aTessCoord.y < 0.5) + { + position.y = floor(fast::min(from.y, to.y)); + } + else + { + position.y = uTileSize.y; + } + out.vFrom = from - position; + out.vTo = to - position; + out.gl_Position = float4((((tileOrigin + position) / uFramebufferSize) * 2.0) - float2(1.0), 0.0, 1.0); + return out; +} + diff --git a/resources/shaders/metal/post.fs.metal b/resources/shaders/metal/post.fs.metal new file mode 100644 index 00000000..66ca87f8 --- /dev/null +++ b/resources/shaders/metal/post.fs.metal @@ -0,0 +1,119 @@ +#pragma clang diagnostic ignored "-Wmissing-prototypes" + +#include +#include + +using namespace metal; + +struct main0_out +{ + float4 oFragColor [[color(0)]]; +}; + +struct main0_in +{ + float2 vTexCoord [[user(locn0)]]; +}; + +float sample1Tap(thread const float& offset, thread texture2d uSource, thread const sampler uSourceSmplr, thread float2& vTexCoord) +{ + return uSource.sample(uSourceSmplr, float2(vTexCoord.x + offset, vTexCoord.y)).x; +} + +void sample9Tap(thread float4& outAlphaLeft, thread float& outAlphaCenter, thread float4& outAlphaRight, thread const float& onePixel, thread float4 uKernel, thread texture2d uSource, thread const sampler uSourceSmplr, thread float2& vTexCoord) +{ + float _89; + if (uKernel.x > 0.0) + { + float param = (-4.0) * onePixel; + _89 = sample1Tap(param, uSource, uSourceSmplr, vTexCoord); + } + else + { + _89 = 0.0; + } + float param_1 = (-3.0) * onePixel; + float param_2 = (-2.0) * onePixel; + float param_3 = (-1.0) * onePixel; + outAlphaLeft = float4(_89, sample1Tap(param_1, uSource, uSourceSmplr, vTexCoord), sample1Tap(param_2, uSource, uSourceSmplr, vTexCoord), sample1Tap(param_3, uSource, uSourceSmplr, vTexCoord)); + float param_4 = 0.0; + outAlphaCenter = sample1Tap(param_4, uSource, uSourceSmplr, vTexCoord); + float param_5 = 1.0 * onePixel; + float _120 = sample1Tap(param_5, uSource, uSourceSmplr, vTexCoord); + float param_6 = 2.0 * onePixel; + float _125 = sample1Tap(param_6, uSource, uSourceSmplr, vTexCoord); + float param_7 = 3.0 * onePixel; + float _130 = sample1Tap(param_7, uSource, uSourceSmplr, vTexCoord); + float _134; + if (uKernel.x > 0.0) + { + float param_8 = 4.0 * onePixel; + _134 = sample1Tap(param_8, uSource, uSourceSmplr, vTexCoord); + } + else + { + _134 = 0.0; + } + outAlphaRight = float4(_120, _125, _130, _134); +} + +float convolve7Tap(thread const float4& alpha0, thread const float3& alpha1, thread float4 uKernel) +{ + return dot(alpha0, uKernel) + dot(alpha1, uKernel.zyx); +} + +float gammaCorrectChannel(thread const float& bgColor, thread const float& fgColor, thread texture2d uGammaLUT, thread const sampler uGammaLUTSmplr) +{ + return uGammaLUT.sample(uGammaLUTSmplr, float2(fgColor, 1.0 - bgColor)).x; +} + +float3 gammaCorrect(thread const float3& bgColor, thread const float3& fgColor, thread texture2d uGammaLUT, thread const sampler uGammaLUTSmplr) +{ + float param = bgColor.x; + float param_1 = fgColor.x; + float param_2 = bgColor.y; + float param_3 = fgColor.y; + float param_4 = bgColor.z; + float param_5 = fgColor.z; + return float3(gammaCorrectChannel(param, param_1, uGammaLUT, uGammaLUTSmplr), gammaCorrectChannel(param_2, param_3, uGammaLUT, uGammaLUTSmplr), gammaCorrectChannel(param_4, param_5, uGammaLUT, uGammaLUTSmplr)); +} + +fragment main0_out main0(main0_in in [[stage_in]], int uGammaCorrectionEnabled [[buffer(2)]], float4 uKernel [[buffer(0)]], float2 uSourceSize [[buffer(1)]], float4 uBGColor [[buffer(3)]], float4 uFGColor [[buffer(4)]], texture2d uGammaLUT [[texture(0)]], texture2d uSource [[texture(0)]], sampler uGammaLUTSmplr [[sampler(0)]], sampler uSourceSmplr [[sampler(0)]]) +{ + main0_out out = {}; + float3 alpha; + if (uKernel.w == 0.0) + { + alpha = uSource.sample(uSourceSmplr, in.vTexCoord).xxx; + } + else + { + float param_3 = 1.0 / uSourceSize.x; + float4 param; + float param_1; + float4 param_2; + sample9Tap(param, param_1, param_2, param_3, uKernel, uSource, uSourceSmplr, in.vTexCoord); + float4 alphaLeft = param; + float alphaCenter = param_1; + float4 alphaRight = param_2; + float4 param_4 = alphaLeft; + float3 param_5 = float3(alphaCenter, alphaRight.xy); + float r = convolve7Tap(param_4, param_5, uKernel); + float4 param_6 = float4(alphaLeft.yzw, alphaCenter); + float3 param_7 = alphaRight.xyz; + float g = convolve7Tap(param_6, param_7, uKernel); + float4 param_8 = float4(alphaLeft.zw, alphaCenter, alphaRight.x); + float3 param_9 = alphaRight.yzw; + float b = convolve7Tap(param_8, param_9, uKernel); + alpha = float3(r, g, b); + } + if (uGammaCorrectionEnabled != 0) + { + float3 param_10 = uBGColor.xyz; + float3 param_11 = alpha; + alpha = gammaCorrect(param_10, param_11, uGammaLUT, uGammaLUTSmplr); + } + out.oFragColor = float4(mix(uBGColor.xyz, uFGColor.xyz, alpha), 1.0); + return out; +} + diff --git a/resources/shaders/metal/post.vs.metal b/resources/shaders/metal/post.vs.metal new file mode 100644 index 00000000..a960ca1b --- /dev/null +++ b/resources/shaders/metal/post.vs.metal @@ -0,0 +1,24 @@ +#include +#include + +using namespace metal; + +struct main0_out +{ + float2 vTexCoord [[user(locn0)]]; + float4 gl_Position [[position]]; +}; + +struct main0_in +{ + float2 aPosition [[attribute(0)]]; +}; + +vertex main0_out main0(main0_in in [[stage_in]], uint gl_VertexID [[vertex_id]], uint gl_InstanceID [[instance_id]]) +{ + main0_out out = {}; + out.vTexCoord = in.aPosition; + out.gl_Position = float4((in.aPosition * 2.0) - float2(1.0), 0.0, 1.0); + return out; +} + diff --git a/resources/shaders/metal/reproject.fs.metal b/resources/shaders/metal/reproject.fs.metal new file mode 100644 index 00000000..3e2a2039 --- /dev/null +++ b/resources/shaders/metal/reproject.fs.metal @@ -0,0 +1,24 @@ +#include +#include + +using namespace metal; + +struct main0_out +{ + float4 oFragColor [[color(0)]]; +}; + +struct main0_in +{ + float2 vTexCoord [[user(locn0)]]; +}; + +fragment main0_out main0(main0_in in [[stage_in]], float4x4 uOldTransform [[buffer(0)]], texture2d uTexture [[texture(0)]], sampler uTextureSmplr [[sampler(0)]]) +{ + main0_out out = {}; + float4 normTexCoord = uOldTransform * float4(in.vTexCoord, 0.0, 1.0); + float2 texCoord = ((normTexCoord.xy / float2(normTexCoord.w)) + float2(1.0)) * 0.5; + out.oFragColor = uTexture.sample(uTextureSmplr, texCoord); + return out; +} + diff --git a/resources/shaders/metal/reproject.vs.metal b/resources/shaders/metal/reproject.vs.metal new file mode 100644 index 00000000..d125c376 --- /dev/null +++ b/resources/shaders/metal/reproject.vs.metal @@ -0,0 +1,24 @@ +#include +#include + +using namespace metal; + +struct main0_out +{ + float2 vTexCoord [[user(locn0)]]; + float4 gl_Position [[position]]; +}; + +struct main0_in +{ + float2 aPosition [[attribute(0)]]; +}; + +vertex main0_out main0(main0_in in [[stage_in]], float4x4 uNewTransform [[buffer(0)]], uint gl_VertexID [[vertex_id]], uint gl_InstanceID [[instance_id]]) +{ + main0_out out = {}; + out.vTexCoord = in.aPosition; + out.gl_Position = uNewTransform * float4(in.aPosition, 0.0, 1.0); + return out; +} + diff --git a/resources/shaders/metal/stencil.fs.metal b/resources/shaders/metal/stencil.fs.metal new file mode 100644 index 00000000..426311ef --- /dev/null +++ b/resources/shaders/metal/stencil.fs.metal @@ -0,0 +1,17 @@ +#include +#include + +using namespace metal; + +struct main0_out +{ + float4 oFragColor [[color(0)]]; +}; + +fragment main0_out main0() +{ + main0_out out = {}; + out.oFragColor = float4(1.0, 0.0, 0.0, 1.0); + return out; +} + diff --git a/resources/shaders/metal/stencil.vs.metal b/resources/shaders/metal/stencil.vs.metal new file mode 100644 index 00000000..2dc23a5d --- /dev/null +++ b/resources/shaders/metal/stencil.vs.metal @@ -0,0 +1,22 @@ +#include +#include + +using namespace metal; + +struct main0_out +{ + float4 gl_Position [[position]]; +}; + +struct main0_in +{ + float3 aPosition [[attribute(0)]]; +}; + +vertex main0_out main0(main0_in in [[stage_in]], uint gl_VertexID [[vertex_id]], uint gl_InstanceID [[instance_id]]) +{ + main0_out out = {}; + out.gl_Position = float4(in.aPosition, 1.0); + return out; +} + diff --git a/resources/shaders/metal/tile_alpha.fs.metal b/resources/shaders/metal/tile_alpha.fs.metal new file mode 100644 index 00000000..30afe4cd --- /dev/null +++ b/resources/shaders/metal/tile_alpha.fs.metal @@ -0,0 +1,25 @@ +#include +#include + +using namespace metal; + +struct main0_out +{ + float4 oFragColor [[color(0)]]; +}; + +struct main0_in +{ + float2 vTexCoord [[user(locn0)]]; + float vBackdrop [[user(locn1)]]; + float4 vColor [[user(locn2)]]; +}; + +fragment main0_out main0(main0_in in [[stage_in]], texture2d uStencilTexture [[texture(0)]], sampler uStencilTextureSmplr [[sampler(0)]]) +{ + main0_out out = {}; + float coverage = abs(uStencilTexture.sample(uStencilTextureSmplr, in.vTexCoord).x + in.vBackdrop); + out.oFragColor = float4(in.vColor.xyz, in.vColor.w * coverage); + return out; +} + diff --git a/resources/shaders/metal/tile_alpha_monochrome.vs.metal b/resources/shaders/metal/tile_alpha_monochrome.vs.metal new file mode 100644 index 00000000..e92a3af0 --- /dev/null +++ b/resources/shaders/metal/tile_alpha_monochrome.vs.metal @@ -0,0 +1,57 @@ +#pragma clang diagnostic ignored "-Wmissing-prototypes" + +#include +#include + +using namespace metal; + +struct main0_out +{ + float2 vTexCoord [[user(locn0)]]; + float vBackdrop [[user(locn1)]]; + float4 vColor [[user(locn2)]]; + float4 gl_Position [[position]]; +}; + +struct main0_in +{ + float2 aTessCoord [[attribute(0)]]; + uint3 aTileOrigin [[attribute(1)]]; + int aBackdrop [[attribute(2)]]; + uint aTileIndex [[attribute(3)]]; +}; + +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; +} + +float4 getColor(thread float4 uColor) +{ + return uColor; +} + +void computeVaryings(thread float2 uTileSize, thread uint3& aTileOrigin, thread float2& aTessCoord, thread float2 uViewBoxOrigin, thread float2 uFramebufferSize, thread uint& aTileIndex, thread float2 uStencilTextureSize, thread float2& vTexCoord, thread float& vBackdrop, thread int& aBackdrop, thread float4& vColor, thread float4& gl_Position, thread float4 uColor) +{ + float2 origin = float2(aTileOrigin.xy) + (float2(float(aTileOrigin.z & 15u), float(aTileOrigin.z >> 4u)) * 256.0); + float2 pixelPosition = ((origin + aTessCoord) * uTileSize) + uViewBoxOrigin; + float2 position = (((pixelPosition / uFramebufferSize) * 2.0) - float2(1.0)) * float2(1.0, -1.0); + uint param = aTileIndex; + float param_1 = uStencilTextureSize.x; + float2 maskTexCoordOrigin = computeTileOffset(param, param_1, uTileSize); + float2 maskTexCoord = maskTexCoordOrigin + (aTessCoord * uTileSize); + vTexCoord = maskTexCoord / uStencilTextureSize; + vBackdrop = float(aBackdrop); + vColor = getColor(uColor); + gl_Position = float4(position, 0.0, 1.0); +} + +vertex main0_out main0(main0_in in [[stage_in]], float2 uTileSize [[buffer(0)]], float2 uViewBoxOrigin [[buffer(1)]], float2 uFramebufferSize [[buffer(2)]], float2 uStencilTextureSize [[buffer(3)]], float4 uColor [[buffer(4)]], uint gl_VertexID [[vertex_id]], uint gl_InstanceID [[instance_id]]) +{ + main0_out out = {}; + computeVaryings(uTileSize, in.aTileOrigin, in.aTessCoord, uViewBoxOrigin, uFramebufferSize, in.aTileIndex, uStencilTextureSize, out.vTexCoord, out.vBackdrop, in.aBackdrop, out.vColor, out.gl_Position, uColor); + return out; +} + diff --git a/resources/shaders/metal/tile_alpha_multicolor.vs.metal b/resources/shaders/metal/tile_alpha_multicolor.vs.metal new file mode 100644 index 00000000..525d7fe3 --- /dev/null +++ b/resources/shaders/metal/tile_alpha_multicolor.vs.metal @@ -0,0 +1,58 @@ +#pragma clang diagnostic ignored "-Wmissing-prototypes" + +#include +#include + +using namespace metal; + +struct main0_out +{ + float2 vTexCoord [[user(locn0)]]; + float vBackdrop [[user(locn1)]]; + float4 vColor [[user(locn2)]]; + float4 gl_Position [[position]]; +}; + +struct main0_in +{ + float2 aTessCoord [[attribute(0)]]; + uint3 aTileOrigin [[attribute(1)]]; + int aBackdrop [[attribute(2)]]; + uint aTileIndex [[attribute(3)]]; + float2 aColorTexCoord [[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; +} + +float4 getColor(thread texture2d uPaintTexture, thread const sampler uPaintTextureSmplr, thread float2& aColorTexCoord) +{ + return uPaintTexture.sample(uPaintTextureSmplr, aColorTexCoord, level(0.0)); +} + +void computeVaryings(thread float2 uTileSize, thread uint3& aTileOrigin, thread float2& aTessCoord, thread float2 uViewBoxOrigin, thread float2 uFramebufferSize, thread uint& aTileIndex, thread float2 uStencilTextureSize, thread float2& vTexCoord, thread float& vBackdrop, thread int& aBackdrop, thread float4& vColor, thread float4& gl_Position, thread texture2d uPaintTexture, thread const sampler uPaintTextureSmplr, thread float2& aColorTexCoord) +{ + float2 origin = float2(aTileOrigin.xy) + (float2(float(aTileOrigin.z & 15u), float(aTileOrigin.z >> 4u)) * 256.0); + float2 pixelPosition = ((origin + aTessCoord) * uTileSize) + uViewBoxOrigin; + float2 position = (((pixelPosition / uFramebufferSize) * 2.0) - float2(1.0)) * float2(1.0, -1.0); + uint param = aTileIndex; + float param_1 = uStencilTextureSize.x; + float2 maskTexCoordOrigin = computeTileOffset(param, param_1, uTileSize); + float2 maskTexCoord = maskTexCoordOrigin + (aTessCoord * uTileSize); + vTexCoord = maskTexCoord / uStencilTextureSize; + vBackdrop = float(aBackdrop); + vColor = getColor(uPaintTexture, uPaintTextureSmplr, aColorTexCoord); + gl_Position = float4(position, 0.0, 1.0); +} + +vertex main0_out main0(main0_in in [[stage_in]], float2 uTileSize [[buffer(0)]], float2 uViewBoxOrigin [[buffer(1)]], float2 uFramebufferSize [[buffer(2)]], float2 uStencilTextureSize [[buffer(3)]], texture2d uPaintTexture [[texture(0)]], sampler uPaintTextureSmplr [[sampler(0)]], uint gl_VertexID [[vertex_id]], uint gl_InstanceID [[instance_id]]) +{ + main0_out out = {}; + computeVaryings(uTileSize, in.aTileOrigin, in.aTessCoord, uViewBoxOrigin, uFramebufferSize, in.aTileIndex, uStencilTextureSize, out.vTexCoord, out.vBackdrop, in.aBackdrop, out.vColor, out.gl_Position, uPaintTexture, uPaintTextureSmplr, in.aColorTexCoord); + return out; +} + diff --git a/resources/shaders/metal/tile_solid.fs.metal b/resources/shaders/metal/tile_solid.fs.metal new file mode 100644 index 00000000..fed4023d --- /dev/null +++ b/resources/shaders/metal/tile_solid.fs.metal @@ -0,0 +1,22 @@ +#include +#include + +using namespace metal; + +struct main0_out +{ + float4 oFragColor [[color(0)]]; +}; + +struct main0_in +{ + float4 vColor [[user(locn0)]]; +}; + +fragment main0_out main0(main0_in in [[stage_in]]) +{ + main0_out out = {}; + out.oFragColor = in.vColor; + return out; +} + diff --git a/resources/shaders/metal/tile_solid_monochrome.vs.metal b/resources/shaders/metal/tile_solid_monochrome.vs.metal new file mode 100644 index 00000000..83410055 --- /dev/null +++ b/resources/shaders/metal/tile_solid_monochrome.vs.metal @@ -0,0 +1,39 @@ +#pragma clang diagnostic ignored "-Wmissing-prototypes" + +#include +#include + +using namespace metal; + +struct main0_out +{ + float4 vColor [[user(locn0)]]; + float4 gl_Position [[position]]; +}; + +struct main0_in +{ + float2 aTessCoord [[attribute(0)]]; + float2 aTileOrigin [[attribute(1)]]; +}; + +float4 getColor(thread float4 uColor) +{ + return uColor; +} + +void computeVaryings(thread float2& aTileOrigin, thread float2& aTessCoord, thread float2 uTileSize, thread float2 uViewBoxOrigin, thread float2 uFramebufferSize, thread float4& vColor, thread float4& gl_Position, thread float4 uColor) +{ + float2 pixelPosition = ((aTileOrigin + aTessCoord) * uTileSize) + uViewBoxOrigin; + float2 position = (((pixelPosition / uFramebufferSize) * 2.0) - float2(1.0)) * float2(1.0, -1.0); + vColor = getColor(uColor); + gl_Position = float4(position, 0.0, 1.0); +} + +vertex main0_out main0(main0_in in [[stage_in]], float2 uTileSize [[buffer(0)]], float2 uViewBoxOrigin [[buffer(1)]], float2 uFramebufferSize [[buffer(2)]], float4 uColor [[buffer(3)]], uint gl_VertexID [[vertex_id]], uint gl_InstanceID [[instance_id]]) +{ + main0_out out = {}; + computeVaryings(in.aTileOrigin, in.aTessCoord, uTileSize, uViewBoxOrigin, uFramebufferSize, out.vColor, out.gl_Position, uColor); + return out; +} + diff --git a/resources/shaders/metal/tile_solid_multicolor.vs.metal b/resources/shaders/metal/tile_solid_multicolor.vs.metal new file mode 100644 index 00000000..3f5d0c45 --- /dev/null +++ b/resources/shaders/metal/tile_solid_multicolor.vs.metal @@ -0,0 +1,40 @@ +#pragma clang diagnostic ignored "-Wmissing-prototypes" + +#include +#include + +using namespace metal; + +struct main0_out +{ + float4 vColor [[user(locn0)]]; + float4 gl_Position [[position]]; +}; + +struct main0_in +{ + float2 aTessCoord [[attribute(0)]]; + float2 aTileOrigin [[attribute(1)]]; + float2 aColorTexCoord [[attribute(2)]]; +}; + +float4 getColor(thread texture2d uPaintTexture, thread const sampler uPaintTextureSmplr, thread float2& aColorTexCoord) +{ + return uPaintTexture.sample(uPaintTextureSmplr, aColorTexCoord, level(0.0)); +} + +void computeVaryings(thread float2& aTileOrigin, thread float2& aTessCoord, thread float2 uTileSize, thread float2 uViewBoxOrigin, thread float2 uFramebufferSize, thread float4& vColor, thread float4& gl_Position, thread texture2d uPaintTexture, thread const sampler uPaintTextureSmplr, thread float2& aColorTexCoord) +{ + float2 pixelPosition = ((aTileOrigin + aTessCoord) * uTileSize) + uViewBoxOrigin; + float2 position = (((pixelPosition / uFramebufferSize) * 2.0) - float2(1.0)) * float2(1.0, -1.0); + vColor = getColor(uPaintTexture, uPaintTextureSmplr, aColorTexCoord); + gl_Position = float4(position, 0.0, 1.0); +} + +vertex main0_out main0(main0_in in [[stage_in]], float2 uTileSize [[buffer(0)]], float2 uViewBoxOrigin [[buffer(1)]], float2 uFramebufferSize [[buffer(2)]], texture2d uPaintTexture [[texture(0)]], sampler uPaintTextureSmplr [[sampler(0)]], uint gl_VertexID [[vertex_id]], uint gl_InstanceID [[instance_id]]) +{ + main0_out out = {}; + computeVaryings(in.aTileOrigin, in.aTessCoord, uTileSize, uViewBoxOrigin, uFramebufferSize, out.vColor, out.gl_Position, uPaintTexture, uPaintTextureSmplr, in.aColorTexCoord); + return out; +} + diff --git a/resources/shaders/spirv/debug_solid.fs.spv b/resources/shaders/spirv/debug_solid.fs.spv new file mode 100644 index 00000000..ae1e7b85 Binary files /dev/null and b/resources/shaders/spirv/debug_solid.fs.spv differ diff --git a/resources/shaders/spirv/debug_solid.vs.spv b/resources/shaders/spirv/debug_solid.vs.spv new file mode 100644 index 00000000..0c94d0df Binary files /dev/null and b/resources/shaders/spirv/debug_solid.vs.spv differ diff --git a/resources/shaders/spirv/debug_texture.fs.spv b/resources/shaders/spirv/debug_texture.fs.spv new file mode 100644 index 00000000..1be8ae23 Binary files /dev/null and b/resources/shaders/spirv/debug_texture.fs.spv differ diff --git a/resources/shaders/spirv/debug_texture.vs.spv b/resources/shaders/spirv/debug_texture.vs.spv new file mode 100644 index 00000000..22f838c7 Binary files /dev/null and b/resources/shaders/spirv/debug_texture.vs.spv differ diff --git a/resources/shaders/spirv/demo_ground.fs.spv b/resources/shaders/spirv/demo_ground.fs.spv new file mode 100644 index 00000000..8dc291cf Binary files /dev/null and b/resources/shaders/spirv/demo_ground.fs.spv differ diff --git a/resources/shaders/spirv/demo_ground.vs.spv b/resources/shaders/spirv/demo_ground.vs.spv new file mode 100644 index 00000000..0a0926a6 Binary files /dev/null and b/resources/shaders/spirv/demo_ground.vs.spv differ diff --git a/resources/shaders/spirv/fill.fs.spv b/resources/shaders/spirv/fill.fs.spv new file mode 100644 index 00000000..4cb3b288 Binary files /dev/null and b/resources/shaders/spirv/fill.fs.spv differ diff --git a/resources/shaders/spirv/fill.vs.spv b/resources/shaders/spirv/fill.vs.spv new file mode 100644 index 00000000..1ae09e95 Binary files /dev/null and b/resources/shaders/spirv/fill.vs.spv differ diff --git a/resources/shaders/spirv/post.fs.spv b/resources/shaders/spirv/post.fs.spv new file mode 100644 index 00000000..b6d2fec3 Binary files /dev/null and b/resources/shaders/spirv/post.fs.spv differ diff --git a/resources/shaders/spirv/post.vs.spv b/resources/shaders/spirv/post.vs.spv new file mode 100644 index 00000000..6d35fb90 Binary files /dev/null and b/resources/shaders/spirv/post.vs.spv differ diff --git a/resources/shaders/spirv/reproject.fs.spv b/resources/shaders/spirv/reproject.fs.spv new file mode 100644 index 00000000..34b4930a Binary files /dev/null and b/resources/shaders/spirv/reproject.fs.spv differ diff --git a/resources/shaders/spirv/reproject.vs.spv b/resources/shaders/spirv/reproject.vs.spv new file mode 100644 index 00000000..9b39096e Binary files /dev/null and b/resources/shaders/spirv/reproject.vs.spv differ diff --git a/resources/shaders/spirv/stencil.fs.spv b/resources/shaders/spirv/stencil.fs.spv new file mode 100644 index 00000000..4c89a941 Binary files /dev/null and b/resources/shaders/spirv/stencil.fs.spv differ diff --git a/resources/shaders/spirv/stencil.vs.spv b/resources/shaders/spirv/stencil.vs.spv new file mode 100644 index 00000000..e24f65ab Binary files /dev/null and b/resources/shaders/spirv/stencil.vs.spv differ diff --git a/resources/shaders/spirv/tile_alpha.fs.spv b/resources/shaders/spirv/tile_alpha.fs.spv new file mode 100644 index 00000000..006cb101 Binary files /dev/null and b/resources/shaders/spirv/tile_alpha.fs.spv differ diff --git a/resources/shaders/spirv/tile_alpha_monochrome.vs.spv b/resources/shaders/spirv/tile_alpha_monochrome.vs.spv new file mode 100644 index 00000000..782bc4f9 Binary files /dev/null and b/resources/shaders/spirv/tile_alpha_monochrome.vs.spv differ diff --git a/resources/shaders/spirv/tile_alpha_multicolor.vs.spv b/resources/shaders/spirv/tile_alpha_multicolor.vs.spv new file mode 100644 index 00000000..99363c6b Binary files /dev/null and b/resources/shaders/spirv/tile_alpha_multicolor.vs.spv differ diff --git a/resources/shaders/spirv/tile_solid.fs.spv b/resources/shaders/spirv/tile_solid.fs.spv new file mode 100644 index 00000000..cce99735 Binary files /dev/null and b/resources/shaders/spirv/tile_solid.fs.spv differ diff --git a/resources/shaders/spirv/tile_solid_monochrome.vs.spv b/resources/shaders/spirv/tile_solid_monochrome.vs.spv new file mode 100644 index 00000000..14cf6c14 Binary files /dev/null and b/resources/shaders/spirv/tile_solid_monochrome.vs.spv differ diff --git a/resources/shaders/spirv/tile_solid_multicolor.vs.spv b/resources/shaders/spirv/tile_solid_multicolor.vs.spv new file mode 100644 index 00000000..9e6cdceb Binary files /dev/null and b/resources/shaders/spirv/tile_solid_multicolor.vs.spv differ diff --git a/shaders/Makefile b/shaders/Makefile new file mode 100644 index 00000000..42e78baa --- /dev/null +++ b/shaders/Makefile @@ -0,0 +1,69 @@ +TARGET_DIR?=../resources/shaders + +EMPTY= + +SHADERS=\ + debug_solid.fs.glsl \ + debug_solid.vs.glsl \ + debug_texture.fs.glsl \ + debug_texture.vs.glsl \ + demo_ground.fs.glsl \ + demo_ground.vs.glsl \ + fill.fs.glsl \ + fill.vs.glsl \ + post.fs.glsl \ + post.vs.glsl \ + reproject.fs.glsl \ + reproject.vs.glsl \ + stencil.fs.glsl \ + stencil.vs.glsl \ + tile_alpha.fs.glsl \ + tile_alpha_monochrome.vs.glsl \ + tile_alpha_multicolor.vs.glsl \ + tile_solid.fs.glsl \ + tile_solid_monochrome.vs.glsl \ + tile_solid_multicolor.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=\ + $(SHADERS:%=$(TARGET_DIR)/gl3/%) \ + $(SHADERS:%.glsl=$(TARGET_DIR)/metal/%.metal) \ + $(EMPTY) + +GLSL_VERSION=330 +GLSLANGFLAGS=--auto-map-locations -I. + +SPIRVCROSSFLAGS=--msl + +SED_ARGS=-e "s/\#version 330/\#version \{\{version\}\}/" -e "s/\#line.*$$//" + +all: $(OUT) + +.PHONY: clean + +clean: + rm -f $(OUT) + +$(TARGET_DIR)/spirv/%.fs.spv: %.fs.glsl $(INCLUDES) + mkdir -p $(TARGET_DIR)/spirv && glslangValidator $(GLSLANGFLAGS) -G$(GLSL_VERSION) -S frag -o $@ $< + +$(TARGET_DIR)/gl3/%.fs.glsl: %.fs.glsl $(INCLUDES) + mkdir -p $(TARGET_DIR)/gl3 && glslangValidator $(GLSLANGFLAGS) -S frag -E $< | sed $(SED_ARGS) > $@ + +$(TARGET_DIR)/spirv/%.vs.spv: %.vs.glsl $(INCLUDES) + mkdir -p $(TARGET_DIR)/spirv && glslangValidator $(GLSLANGFLAGS) -G$(GLSL_VERSION) -S vert -o $@ $< + +$(TARGET_DIR)/gl3/%.vs.glsl: %.vs.glsl $(INCLUDES) + mkdir -p $(TARGET_DIR)/gl3 && glslangValidator $(GLSLANGFLAGS) -S vert -E $< | sed $(SED_ARGS) > $@ + +$(TARGET_DIR)/metal/%.metal: $(TARGET_DIR)/spirv/%.spv + mkdir -p $(TARGET_DIR)/metal && spirv-cross $(SPIRVCROSSFLAGS) --output $@ $< diff --git a/resources/shaders/debug_solid.fs.glsl b/shaders/debug_solid.fs.glsl similarity index 88% rename from resources/shaders/debug_solid.fs.glsl rename to shaders/debug_solid.fs.glsl index a50236a7..e8c09515 100644 --- a/resources/shaders/debug_solid.fs.glsl +++ b/shaders/debug_solid.fs.glsl @@ -1,6 +1,6 @@ -#version {{version}} +#version 330 -// pathfinder/demo/shaders/debug_solid.fs.glsl +// pathfinder/shaders/debug_solid.fs.glsl // // Copyright © 2019 The Pathfinder Project Developers. // diff --git a/resources/shaders/debug_solid.vs.glsl b/shaders/debug_solid.vs.glsl similarity index 89% rename from resources/shaders/debug_solid.vs.glsl rename to shaders/debug_solid.vs.glsl index 47b1f0bb..10b92ad8 100644 --- a/resources/shaders/debug_solid.vs.glsl +++ b/shaders/debug_solid.vs.glsl @@ -1,6 +1,6 @@ -#version {{version}} +#version 330 -// pathfinder/demo/shaders/debug_solid.vs.glsl +// pathfinder/shaders/debug_solid.vs.glsl // // Copyright © 2019 The Pathfinder Project Developers. // diff --git a/resources/shaders/debug_texture.fs.glsl b/shaders/debug_texture.fs.glsl similarity index 88% rename from resources/shaders/debug_texture.fs.glsl rename to shaders/debug_texture.fs.glsl index 2065c2a6..b157011f 100644 --- a/resources/shaders/debug_texture.fs.glsl +++ b/shaders/debug_texture.fs.glsl @@ -1,6 +1,6 @@ -#version {{version}} +#version 330 -// pathfinder/resources/shaders/debug_texture.fs.glsl +// pathfinder/shaders/debug_texture.fs.glsl // // Copyright © 2019 The Pathfinder Project Developers. // diff --git a/resources/shaders/debug_texture.vs.glsl b/shaders/debug_texture.vs.glsl similarity index 90% rename from resources/shaders/debug_texture.vs.glsl rename to shaders/debug_texture.vs.glsl index beed30cf..734916f1 100644 --- a/resources/shaders/debug_texture.vs.glsl +++ b/shaders/debug_texture.vs.glsl @@ -1,6 +1,6 @@ -#version {{version}} +#version 330 -// pathfinder/demo/shaders/debug_texture.vs.glsl +// pathfinder/shaders/debug_texture.vs.glsl // // Copyright © 2019 The Pathfinder Project Developers. // diff --git a/resources/shaders/demo_ground.fs.glsl b/shaders/demo_ground.fs.glsl similarity index 89% rename from resources/shaders/demo_ground.fs.glsl rename to shaders/demo_ground.fs.glsl index a34a29d5..983511d5 100644 --- a/resources/shaders/demo_ground.fs.glsl +++ b/shaders/demo_ground.fs.glsl @@ -1,6 +1,6 @@ -#version {{version}} +#version 330 -// pathfinder/demo/resources/shaders/demo_ground.fs.glsl +// pathfinder/resources/shaders/demo_ground.fs.glsl // // Copyright © 2019 The Pathfinder Project Developers. // diff --git a/resources/shaders/demo_ground.vs.glsl b/shaders/demo_ground.vs.glsl similarity index 88% rename from resources/shaders/demo_ground.vs.glsl rename to shaders/demo_ground.vs.glsl index 15287408..b145ce04 100644 --- a/resources/shaders/demo_ground.vs.glsl +++ b/shaders/demo_ground.vs.glsl @@ -1,6 +1,6 @@ -#version {{version}} +#version 330 -// pathfinder/demo/resources/shaders/demo_ground.vs.glsl +// pathfinder/resources/shaders/demo_ground.vs.glsl // // Copyright © 2019 The Pathfinder Project Developers. // diff --git a/resources/shaders/fill.fs.glsl b/shaders/fill.fs.glsl similarity index 91% rename from resources/shaders/fill.fs.glsl rename to shaders/fill.fs.glsl index 1874a60c..25872515 100644 --- a/resources/shaders/fill.fs.glsl +++ b/shaders/fill.fs.glsl @@ -1,8 +1,8 @@ -#version {{version}} +#version 330 -// pathfinder/demo2/stencil.fs.glsl +// pathfinder/shaders/stencil.fs.glsl // -// Copyright © 2018 The Pathfinder Project Developers. +// Copyright © 2019 The Pathfinder Project Developers. // // Licensed under the Apache License, Version 2.0 or the MIT license diff --git a/resources/shaders/fill.vs.glsl b/shaders/fill.vs.glsl similarity index 96% rename from resources/shaders/fill.vs.glsl rename to shaders/fill.vs.glsl index c8a2aacb..f5abbf7e 100644 --- a/resources/shaders/fill.vs.glsl +++ b/shaders/fill.vs.glsl @@ -1,6 +1,6 @@ -#version {{version}} +#version 330 -// pathfinder/demo/fill.vs.glsl +// pathfinder/resources/fill.vs.glsl // // Copyright © 2019 The Pathfinder Project Developers. // diff --git a/resources/shaders/post.fs.glsl b/shaders/post.fs.glsl similarity index 90% rename from resources/shaders/post.fs.glsl rename to shaders/post.fs.glsl index cb7326a6..62d40494 100644 --- a/resources/shaders/post.fs.glsl +++ b/shaders/post.fs.glsl @@ -1,6 +1,6 @@ -#version {{version}} +#version 330 -// pathfinder/resources/shaders/post.fs.glsl +// pathfinder/shaders/post.fs.glsl // // Copyright © 2019 The Pathfinder Project Developers. // @@ -13,6 +13,8 @@ // TODO(pcwalton): This could be significantly optimized by operating on a // sparse per-tile basis. +#extension GL_GOOGLE_include_directive : enable + precision highp float; uniform sampler2D uSource; @@ -25,8 +27,8 @@ in vec2 vTexCoord; out vec4 oFragColor; -{{include_post_gamma_correct}} -{{include_post_convolve}} +#include "post_gamma_correct.inc.glsl" +#include "post_convolve.inc.glsl" // Convolve horizontally in this pass. float sample1Tap(float offset) { diff --git a/resources/shaders/post.vs.glsl b/shaders/post.vs.glsl similarity index 88% rename from resources/shaders/post.vs.glsl rename to shaders/post.vs.glsl index 44b692ae..2ee824a7 100644 --- a/resources/shaders/post.vs.glsl +++ b/shaders/post.vs.glsl @@ -1,6 +1,6 @@ -#version {{version}} +#version 330 -// pathfinder/resources/shaders/post.vs.glsl +// pathfinder/shaders/post.vs.glsl // // Copyright © 2019 The Pathfinder Project Developers. // diff --git a/resources/shaders/post_convolve.inc.glsl b/shaders/post_convolve.inc.glsl similarity index 96% rename from resources/shaders/post_convolve.inc.glsl rename to shaders/post_convolve.inc.glsl index 8eab750b..1bf3e2ce 100644 --- a/resources/shaders/post_convolve.inc.glsl +++ b/shaders/post_convolve.inc.glsl @@ -1,4 +1,4 @@ -// pathfinder/resources/shaders/post_convolve.inc.glsl +// pathfinder/shaders/post_convolve.inc.glsl // // Copyright © 2019 The Pathfinder Project Developers. // diff --git a/resources/shaders/post_gamma_correct.inc.glsl b/shaders/post_gamma_correct.inc.glsl similarity index 93% rename from resources/shaders/post_gamma_correct.inc.glsl rename to shaders/post_gamma_correct.inc.glsl index 85c3d803..11f47d2a 100644 --- a/resources/shaders/post_gamma_correct.inc.glsl +++ b/shaders/post_gamma_correct.inc.glsl @@ -1,4 +1,4 @@ -// pathfinder/resources/shaders/post_gamma_correct.inc.glsl +// pathfinder/shaders/post_gamma_correct.inc.glsl // // Copyright © 2019 The Pathfinder Project Developers. // diff --git a/resources/shaders/reproject.fs.glsl b/shaders/reproject.fs.glsl similarity index 90% rename from resources/shaders/reproject.fs.glsl rename to shaders/reproject.fs.glsl index a1849a98..6b499664 100644 --- a/resources/shaders/reproject.fs.glsl +++ b/shaders/reproject.fs.glsl @@ -1,6 +1,6 @@ -#version {{version}} +#version 330 -// pathfinder/resources/shaders/reproject.fs.glsl +// pathfinder/shaders/reproject.fs.glsl // // Copyright © 2019 The Pathfinder Project Developers. // diff --git a/resources/shaders/reproject.vs.glsl b/shaders/reproject.vs.glsl similarity index 88% rename from resources/shaders/reproject.vs.glsl rename to shaders/reproject.vs.glsl index d297058d..91d9f9a9 100644 --- a/resources/shaders/reproject.vs.glsl +++ b/shaders/reproject.vs.glsl @@ -1,6 +1,6 @@ -#version {{version}} +#version 330 -// pathfinder/resources/shaders/reproject.vs.glsl +// pathfinder/shaders/reproject.vs.glsl // // Copyright © 2019 The Pathfinder Project Developers. // diff --git a/resources/shaders/stencil.fs.glsl b/shaders/stencil.fs.glsl similarity index 88% rename from resources/shaders/stencil.fs.glsl rename to shaders/stencil.fs.glsl index 8781cbaa..67a83918 100644 --- a/resources/shaders/stencil.fs.glsl +++ b/shaders/stencil.fs.glsl @@ -1,6 +1,6 @@ -#version {{version}} +#version 330 -// pathfinder/resources/shaders/stencil.fs.glsl +// pathfinder/shaders/stencil.fs.glsl // // Copyright © 2018 The Pathfinder Project Developers. // diff --git a/resources/shaders/stencil.vs.glsl b/shaders/stencil.vs.glsl similarity index 76% rename from resources/shaders/stencil.vs.glsl rename to shaders/stencil.vs.glsl index 1fcdc3b3..77346aa9 100644 --- a/resources/shaders/stencil.vs.glsl +++ b/shaders/stencil.vs.glsl @@ -1,8 +1,8 @@ -#version {{version}} +#version 330 -// pathfinder/resources/shaders/stencil.vs.glsl +// pathfinder/shaders/stencil.vs.glsl // -// Copyright © 2018 The Pathfinder Project Developers. +// Copyright © 2019 The Pathfinder Project Developers. // // Licensed under the Apache License, Version 2.0 or the MIT license diff --git a/resources/shaders/tile_alpha.fs.glsl b/shaders/tile_alpha.fs.glsl similarity index 89% rename from resources/shaders/tile_alpha.fs.glsl rename to shaders/tile_alpha.fs.glsl index 0a24afd6..b7dc5df9 100644 --- a/resources/shaders/tile_alpha.fs.glsl +++ b/shaders/tile_alpha.fs.glsl @@ -1,6 +1,6 @@ -#version {{version}} +#version 330 -// pathfinder/demo/resources/shaders/mask_tile.fs.glsl +// pathfinder/shaders/tile_alpha.fs.glsl // // Copyright © 2018 The Pathfinder Project Developers. // diff --git a/resources/shaders/tile_alpha_monochrome.vs.glsl b/shaders/tile_alpha_monochrome.vs.glsl similarity index 69% rename from resources/shaders/tile_alpha_monochrome.vs.glsl rename to shaders/tile_alpha_monochrome.vs.glsl index ac6cf195..856b4f1f 100644 --- a/resources/shaders/tile_alpha_monochrome.vs.glsl +++ b/shaders/tile_alpha_monochrome.vs.glsl @@ -1,6 +1,6 @@ -#version {{version}} +#version 330 -// pathfinder/resources/shaders/tile_alpha_monochrome.vs.glsl +// pathfinder/shaders/tile_alpha_monochrome.vs.glsl // // Copyright © 2019 The Pathfinder Project Developers. // @@ -10,10 +10,12 @@ // 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}} -{{include_tile_monochrome}} +#include "tile_alpha_vertex.inc.glsl" +#include "tile_monochrome.inc.glsl" void main() { computeVaryings(); diff --git a/resources/shaders/tile_alpha_multicolor.vs.glsl b/shaders/tile_alpha_multicolor.vs.glsl similarity index 69% rename from resources/shaders/tile_alpha_multicolor.vs.glsl rename to shaders/tile_alpha_multicolor.vs.glsl index b74c57fb..823016dd 100644 --- a/resources/shaders/tile_alpha_multicolor.vs.glsl +++ b/shaders/tile_alpha_multicolor.vs.glsl @@ -1,6 +1,6 @@ -#version {{version}} +#version 330 -// pathfinder/resources/shaders/tile_alpha_multicolor.vs.glsl +// pathfinder/shaders/tile_alpha_multicolor.vs.glsl // // Copyright © 2019 The Pathfinder Project Developers. // @@ -10,10 +10,12 @@ // 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}} -{{include_tile_multicolor}} +#include "tile_alpha_vertex.inc.glsl" +#include "tile_multicolor.inc.glsl" void main() { computeVaryings(); diff --git a/resources/shaders/tile_alpha_vertex.inc.glsl b/shaders/tile_alpha_vertex.inc.glsl similarity index 96% rename from resources/shaders/tile_alpha_vertex.inc.glsl rename to shaders/tile_alpha_vertex.inc.glsl index 426b2731..6993a13d 100644 --- a/resources/shaders/tile_alpha_vertex.inc.glsl +++ b/shaders/tile_alpha_vertex.inc.glsl @@ -1,4 +1,4 @@ -// pathfinder/resources/shaders/tile_alpha_vertex.inc.glsl +// pathfinder/shaders/tile_alpha_vertex.inc.glsl // // Copyright © 2019 The Pathfinder Project Developers. // diff --git a/resources/shaders/tile_monochrome.inc.glsl b/shaders/tile_monochrome.inc.glsl similarity index 88% rename from resources/shaders/tile_monochrome.inc.glsl rename to shaders/tile_monochrome.inc.glsl index 7b10b25b..3e27f749 100644 --- a/resources/shaders/tile_monochrome.inc.glsl +++ b/shaders/tile_monochrome.inc.glsl @@ -1,4 +1,4 @@ -// pathfinder/resources/shaders/tile_monochrome.inc.glsl +// pathfinder/shaders/tile_monochrome.inc.glsl // // Copyright © 2019 The Pathfinder Project Developers. // diff --git a/resources/shaders/tile_multicolor.inc.glsl b/shaders/tile_multicolor.inc.glsl similarity index 90% rename from resources/shaders/tile_multicolor.inc.glsl rename to shaders/tile_multicolor.inc.glsl index a374bbee..4520625b 100644 --- a/resources/shaders/tile_multicolor.inc.glsl +++ b/shaders/tile_multicolor.inc.glsl @@ -1,4 +1,4 @@ -// pathfinder/resources/shaders/tile_multicolor.inc.glsl +// pathfinder/shaders/tile_multicolor.inc.glsl // // Copyright © 2019 The Pathfinder Project Developers. // diff --git a/resources/shaders/tile_solid.fs.glsl b/shaders/tile_solid.fs.glsl similarity index 78% rename from resources/shaders/tile_solid.fs.glsl rename to shaders/tile_solid.fs.glsl index 129c6813..eed63042 100644 --- a/resources/shaders/tile_solid.fs.glsl +++ b/shaders/tile_solid.fs.glsl @@ -1,8 +1,8 @@ -#version {{version}} +#version 330 -// pathfinder/demo2/opaque.fs.glsl +// pathfinder/shaders/tile_solid.fs.glsl // -// Copyright © 2018 The Pathfinder Project Developers. +// Copyright © 2019 The Pathfinder Project Developers. // // Licensed under the Apache License, Version 2.0 or the MIT license diff --git a/resources/shaders/tile_solid_monochrome.vs.glsl b/shaders/tile_solid_monochrome.vs.glsl similarity index 69% rename from resources/shaders/tile_solid_monochrome.vs.glsl rename to shaders/tile_solid_monochrome.vs.glsl index 408488d7..cf6f61e7 100644 --- a/resources/shaders/tile_solid_monochrome.vs.glsl +++ b/shaders/tile_solid_monochrome.vs.glsl @@ -1,6 +1,6 @@ -#version {{version}} +#version 330 -// pathfinder/resources/shaders/tile_solid_monochrome.vs.glsl +// pathfinder/shaders/tile_solid_monochrome.vs.glsl // // Copyright © 2019 The Pathfinder Project Developers. // @@ -10,10 +10,12 @@ // 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}} -{{include_tile_monochrome}} +#include "tile_solid_vertex.inc.glsl" +#include "tile_monochrome.inc.glsl" void main() { computeVaryings(); diff --git a/resources/shaders/tile_solid_multicolor.vs.glsl b/shaders/tile_solid_multicolor.vs.glsl similarity index 69% rename from resources/shaders/tile_solid_multicolor.vs.glsl rename to shaders/tile_solid_multicolor.vs.glsl index ae3b86bd..34ee0f20 100644 --- a/resources/shaders/tile_solid_multicolor.vs.glsl +++ b/shaders/tile_solid_multicolor.vs.glsl @@ -1,6 +1,6 @@ -#version {{version}} +#version 330 -// pathfinder/resources/shaders/tile_solid_multicolor.vs.glsl +// pathfinder/shaders/tile_solid_multicolor.vs.glsl // // Copyright © 2019 The Pathfinder Project Developers. // @@ -10,10 +10,12 @@ // 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}} -{{include_tile_multicolor}} +#include "tile_solid_vertex.inc.glsl" +#include "tile_multicolor.inc.glsl" void main() { computeVaryings(); diff --git a/resources/shaders/tile_solid_vertex.inc.glsl b/shaders/tile_solid_vertex.inc.glsl similarity index 93% rename from resources/shaders/tile_solid_vertex.inc.glsl rename to shaders/tile_solid_vertex.inc.glsl index a7932c94..73f30cd0 100644 --- a/resources/shaders/tile_solid_vertex.inc.glsl +++ b/shaders/tile_solid_vertex.inc.glsl @@ -1,4 +1,4 @@ -// pathfinder/resources/shaders/tile_solid_vertex.inc.glsl +// pathfinder/shaders/tile_solid_vertex.inc.glsl // // Copyright © 2019 The Pathfinder Project Developers. //