Skip to content

Commit

Permalink
Reworked some of the visibility on items.
Browse files Browse the repository at this point in the history
  • Loading branch information
BradLarson committed Feb 20, 2017
1 parent ce8d257 commit 23e2089
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 13 deletions.
8 changes: 4 additions & 4 deletions framework/Source/Framebuffer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class Framebuffer {
let texture:GLuint
let framebuffer:GLuint?
let stencilBuffer:GLuint?
let size:GLSize
public let size:GLSize
let internalFormat:Int32
let format:Int32
let type:Int32
Expand Down Expand Up @@ -140,11 +140,11 @@ public class Framebuffer {
}
}

func texturePropertiesForOutputRotation(_ rotation:Rotation) -> InputTextureProperties {
public func texturePropertiesForOutputRotation(_ rotation:Rotation) -> InputTextureProperties {
return InputTextureProperties(textureCoordinates:rotation.textureCoordinates(), texture:texture)
}

func texturePropertiesForTargetOrientation(_ targetOrientation:ImageOrientation) -> InputTextureProperties {
public func texturePropertiesForTargetOrientation(_ targetOrientation:ImageOrientation) -> InputTextureProperties {
return texturePropertiesForOutputRotation(self.orientation.rotationNeededForOrientation(targetOrientation))
}

Expand All @@ -167,7 +167,7 @@ public class Framebuffer {
framebufferRetainCount = 0
}

func unlock() {
public func unlock() {
framebufferRetainCount -= 1
if (framebufferRetainCount < 1) {
if ((framebufferRetainCount < 0) && (cache != nil)) {
Expand Down
8 changes: 4 additions & 4 deletions framework/Source/OpenGLRendering.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

import Foundation

struct InputTextureProperties {
let textureCoordinates:[GLfloat]
let texture:GLuint
public struct InputTextureProperties {
public let textureCoordinates:[GLfloat]
public let texture:GLuint
}

public struct GLSize {
Expand Down Expand Up @@ -48,7 +48,7 @@ public let standardImageVertices:[GLfloat] = [-1.0, -1.0, 1.0, -1.0, -1.0, 1.0,
public let verticallyInvertedImageVertices:[GLfloat] = [-1.0, 1.0, 1.0, 1.0, -1.0, -1.0, 1.0, -1.0]

// "position" and "inputTextureCoordinate", "inputTextureCoordinate2" attribute naming follows the convention of the old GPUImage
func renderQuadWithShader(_ shader:ShaderProgram, uniformSettings:ShaderUniformSettings? = nil, vertices:[GLfloat], inputTextures:[InputTextureProperties]) {
public func renderQuadWithShader(_ shader:ShaderProgram, uniformSettings:ShaderUniformSettings? = nil, vertices:[GLfloat], inputTextures:[InputTextureProperties]) {
sharedImageProcessingContext.makeCurrentContext()
shader.use()
uniformSettings?.restoreShaderSettings(shader)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public let SubtractBlendFragmentShader = "varying highp vec2 textureCoordinate;\
public let SwirlFragmentShader = "varying highp vec2 textureCoordinate;\n \n uniform sampler2D inputImageTexture;\n \n uniform highp vec2 center;\n uniform highp float radius;\n uniform highp float angle;\n \n void main()\n {\n highp vec2 textureCoordinateToUse = textureCoordinate;\n highp float dist = distance(center, textureCoordinate);\n if (dist < radius)\n {\n textureCoordinateToUse -= center;\n highp float percent = (radius - dist) / radius;\n highp float theta = percent * percent * angle * 8.0;\n highp float s = sin(theta);\n highp float c = cos(theta);\n textureCoordinateToUse = vec2(dot(textureCoordinateToUse, vec2(c, -s)), dot(textureCoordinateToUse, vec2(s, c)));\n textureCoordinateToUse += center;\n }\n \n gl_FragColor = texture2D(inputImageTexture, textureCoordinateToUse );\n \n }\n "
public let ThreeInputVertexShader = "attribute vec4 position;\n attribute vec4 inputTextureCoordinate;\n attribute vec4 inputTextureCoordinate2;\n attribute vec4 inputTextureCoordinate3;\n \n varying vec2 textureCoordinate;\n varying vec2 textureCoordinate2;\n varying vec2 textureCoordinate3;\n \n void main()\n {\n gl_Position = position;\n textureCoordinate = inputTextureCoordinate.xy;\n textureCoordinate2 = inputTextureCoordinate2.xy;\n textureCoordinate3 = inputTextureCoordinate3.xy;\n }\n "
public let ThresholdEdgeDetectionFragmentShader = "precision highp float;\n \n varying vec2 textureCoordinate;\n varying vec2 leftTextureCoordinate;\n varying vec2 rightTextureCoordinate;\n \n varying vec2 topTextureCoordinate;\n varying vec2 topLeftTextureCoordinate;\n varying vec2 topRightTextureCoordinate;\n \n varying vec2 bottomTextureCoordinate;\n varying vec2 bottomLeftTextureCoordinate;\n varying vec2 bottomRightTextureCoordinate;\n \n uniform sampler2D inputImageTexture;\n uniform float threshold;\n \n uniform float edgeStrength;\n \n void main()\n {\n float bottomLeftIntensity = texture2D(inputImageTexture, bottomLeftTextureCoordinate).r;\n float topRightIntensity = texture2D(inputImageTexture, topRightTextureCoordinate).r;\n float topLeftIntensity = texture2D(inputImageTexture, topLeftTextureCoordinate).r;\n float bottomRightIntensity = texture2D(inputImageTexture, bottomRightTextureCoordinate).r;\n float leftIntensity = texture2D(inputImageTexture, leftTextureCoordinate).r;\n float rightIntensity = texture2D(inputImageTexture, rightTextureCoordinate).r;\n float bottomIntensity = texture2D(inputImageTexture, bottomTextureCoordinate).r;\n float topIntensity = texture2D(inputImageTexture, topTextureCoordinate).r;\n float h = -topLeftIntensity - 2.0 * topIntensity - topRightIntensity + bottomLeftIntensity + 2.0 * bottomIntensity + bottomRightIntensity;\n h = max(0.0, h);\n float v = -bottomLeftIntensity - 2.0 * leftIntensity - topLeftIntensity + bottomRightIntensity + 2.0 * rightIntensity + topRightIntensity;\n v = max(0.0, v);\n \n float mag = length(vec2(h, v)) * edgeStrength;\n mag = step(threshold, mag);\n \n gl_FragColor = vec4(vec3(mag), 1.0);\n }\n "
public let ThresholdSketchFragmentShader = "precision highp float;\n \n varying vec2 textureCoordinate;\n varying vec2 leftTextureCoordinate;\n varying vec2 rightTextureCoordinate;\n \n varying vec2 topTextureCoordinate;\n varying vec2 topLeftTextureCoordinate;\n varying vec2 topRightTextureCoordinate;\n \n varying vec2 bottomTextureCoordinate;\n varying vec2 bottomLeftTextureCoordinate;\n varying vec2 bottomRightTextureCoordinate;\n \n uniform sampler2D inputImageTexture;\n uniform float threshold;\n \n uniform float edgeStrength;\n \n void main()\n {\n float bottomLeftIntensity = texture2D(inputImageTexture, bottomLeftTextureCoordinate).r;\n float topRightIntensity = texture2D(inputImageTexture, topRightTextureCoordinate).r;\n float topLeftIntensity = texture2D(inputImageTexture, topLeftTextureCoordinate).r;\n float bottomRightIntensity = texture2D(inputImageTexture, bottomRightTextureCoordinate).r;\n float leftIntensity = texture2D(inputImageTexture, leftTextureCoordinate).r;\n float rightIntensity = texture2D(inputImageTexture, rightTextureCoordinate).r;\n float bottomIntensity = texture2D(inputImageTexture, bottomTextureCoordinate).r;\n float topIntensity = texture2D(inputImageTexture, topTextureCoordinate).r;\n float h = -topLeftIntensity - 2.0 * topIntensity - topRightIntensity + bottomLeftIntensity + 2.0 * bottomIntensity + bottomRightIntensity;\n h = max(0.0, h);\n float v = -bottomLeftIntensity - 2.0 * leftIntensity - topLeftIntensity + bottomRightIntensity + 2.0 * rightIntensity + topRightIntensity;\n v = max(0.0, v);\n \n float mag = length(vec2(h, v)) * edgeStrength;\n mag = 1.0 - step(threshold, mag);\n \n gl_FragColor = vec4(vec3(mag), 1.0);\n }\n "
public let ThresholdSketchFragmentShader = "precision highp float;\n \n varying vec2 textureCoordinate;\n varying vec2 leftTextureCoordinate;\n varying vec2 rightTextureCoordinate;\n \n varying vec2 topTextureCoordinate;\n varying vec2 topLeftTextureCoordinate;\n varying vec2 topRightTextureCoordinate;\n \n varying vec2 bottomTextureCoordinate;\n varying vec2 bottomLeftTextureCoordinate;\n varying vec2 bottomRightTextureCoordinate;\n \n uniform sampler2D inputImageTexture;\n uniform float threshold;\n \n uniform float edgeStrength;\n \n void main()\n {\n float bottomLeftIntensity = texture2D(inputImageTexture, bottomLeftTextureCoordinate).r;\n float topRightIntensity = texture2D(inputImageTexture, topRightTextureCoordinate).r;\n float topLeftIntensity = texture2D(inputImageTexture, topLeftTextureCoordinate).r;\n float bottomRightIntensity = texture2D(inputImageTexture, bottomRightTextureCoordinate).r;\n float leftIntensity = texture2D(inputImageTexture, leftTextureCoordinate).r;\n float rightIntensity = texture2D(inputImageTexture, rightTextureCoordinate).r;\n float bottomIntensity = texture2D(inputImageTexture, bottomTextureCoordinate).r;\n float topIntensity = texture2D(inputImageTexture, topTextureCoordinate).r;\n float h = -topLeftIntensity - 2.0 * topIntensity - topRightIntensity + bottomLeftIntensity + 2.0 * bottomIntensity + bottomRightIntensity;\n float v = -bottomLeftIntensity - 2.0 * leftIntensity - topLeftIntensity + bottomRightIntensity + 2.0 * rightIntensity + topRightIntensity;\n \n float mag = length(vec2(h, v)) * edgeStrength;\n mag = 1.0 - step(threshold, mag);\n \n gl_FragColor = vec4(vec3(mag), 1.0);\n }\n "
public let ThresholdedNonMaximumSuppressionFragmentShader = " uniform sampler2D inputImageTexture;\n \n varying highp vec2 textureCoordinate;\n varying highp vec2 leftTextureCoordinate;\n varying highp vec2 rightTextureCoordinate;\n \n varying highp vec2 topTextureCoordinate;\n varying highp vec2 topLeftTextureCoordinate;\n varying highp vec2 topRightTextureCoordinate;\n \n varying highp vec2 bottomTextureCoordinate;\n varying highp vec2 bottomLeftTextureCoordinate;\n varying highp vec2 bottomRightTextureCoordinate;\n \n uniform lowp float threshold;\n \n void main()\n {\n lowp float bottomColor = texture2D(inputImageTexture, bottomTextureCoordinate).r;\n lowp float bottomLeftColor = texture2D(inputImageTexture, bottomLeftTextureCoordinate).r;\n lowp float bottomRightColor = texture2D(inputImageTexture, bottomRightTextureCoordinate).r;\n lowp vec4 centerColor = texture2D(inputImageTexture, textureCoordinate);\n lowp float leftColor = texture2D(inputImageTexture, leftTextureCoordinate).r;\n lowp float rightColor = texture2D(inputImageTexture, rightTextureCoordinate).r;\n lowp float topColor = texture2D(inputImageTexture, topTextureCoordinate).r;\n lowp float topRightColor = texture2D(inputImageTexture, topRightTextureCoordinate).r;\n lowp float topLeftColor = texture2D(inputImageTexture, topLeftTextureCoordinate).r;\n \n // Use a tiebreaker for pixels to the left and immediately above this one\n lowp float multiplier = 1.0 - step(centerColor.r, topColor);\n multiplier = multiplier * (1.0 - step(centerColor.r, topLeftColor));\n multiplier = multiplier * (1.0 - step(centerColor.r, leftColor));\n multiplier = multiplier * (1.0 - step(centerColor.r, bottomLeftColor));\n \n lowp float maxValue = max(centerColor.r, bottomColor);\n maxValue = max(maxValue, bottomRightColor);\n maxValue = max(maxValue, rightColor);\n maxValue = max(maxValue, topRightColor);\n \n lowp float finalValue = centerColor.r * step(maxValue, centerColor.r) * multiplier;\n finalValue = step(threshold, finalValue);\n \n gl_FragColor = vec4(finalValue, finalValue, finalValue, 1.0);\n //\n // gl_FragColor = vec4((centerColor.rgb * step(maxValue, step(threshold, centerColor.r)) * multiplier), 1.0);\n }\n "
public let TiltShiftFragmentShader = "varying highp vec2 textureCoordinate;\n varying highp vec2 textureCoordinate2;\n \n uniform sampler2D inputImageTexture;\n uniform sampler2D inputImageTexture2; \n \n uniform highp float topFocusLevel;\n uniform highp float bottomFocusLevel;\n uniform highp float focusFallOffRate;\n \n void main()\n {\n lowp vec4 sharpImageColor = texture2D(inputImageTexture, textureCoordinate);\n lowp vec4 blurredImageColor = texture2D(inputImageTexture2, textureCoordinate2);\n \n lowp float blurIntensity = 1.0 - smoothstep(topFocusLevel - focusFallOffRate, topFocusLevel, textureCoordinate2.y);\n blurIntensity += smoothstep(bottomFocusLevel, bottomFocusLevel + focusFallOffRate, textureCoordinate2.y);\n \n gl_FragColor = mix(sharpImageColor, blurredImageColor, blurIntensity);\n }\n "
public let ToonFragmentShader = "precision highp float;\n \n varying vec2 textureCoordinate;\n varying vec2 leftTextureCoordinate;\n varying vec2 rightTextureCoordinate;\n \n varying vec2 topTextureCoordinate;\n varying vec2 topLeftTextureCoordinate;\n varying vec2 topRightTextureCoordinate;\n \n varying vec2 bottomTextureCoordinate;\n varying vec2 bottomLeftTextureCoordinate;\n varying vec2 bottomRightTextureCoordinate;\n \n uniform sampler2D inputImageTexture;\n \n uniform highp float intensity;\n uniform highp float threshold;\n uniform highp float quantizationLevels;\n \n const highp vec3 W = vec3(0.2125, 0.7154, 0.0721);\n \n void main()\n {\n vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);\n \n float bottomLeftIntensity = texture2D(inputImageTexture, bottomLeftTextureCoordinate).r;\n float topRightIntensity = texture2D(inputImageTexture, topRightTextureCoordinate).r;\n float topLeftIntensity = texture2D(inputImageTexture, topLeftTextureCoordinate).r;\n float bottomRightIntensity = texture2D(inputImageTexture, bottomRightTextureCoordinate).r;\n float leftIntensity = texture2D(inputImageTexture, leftTextureCoordinate).r;\n float rightIntensity = texture2D(inputImageTexture, rightTextureCoordinate).r;\n float bottomIntensity = texture2D(inputImageTexture, bottomTextureCoordinate).r;\n float topIntensity = texture2D(inputImageTexture, topTextureCoordinate).r;\n float h = -topLeftIntensity - 2.0 * topIntensity - topRightIntensity + bottomLeftIntensity + 2.0 * bottomIntensity + bottomRightIntensity;\n float v = -bottomLeftIntensity - 2.0 * leftIntensity - topLeftIntensity + bottomRightIntensity + 2.0 * rightIntensity + topRightIntensity;\n \n float mag = length(vec2(h, v));\n \n vec3 posterizedImageColor = floor((textureColor.rgb * quantizationLevels) + 0.5) / quantizationLevels;\n \n float thresholdTest = 1.0 - step(threshold, mag);\n \n gl_FragColor = vec4(posterizedImageColor * thresholdTest, textureColor.a);\n }\n "
Expand Down
2 changes: 0 additions & 2 deletions framework/Source/Operations/Shaders/ThresholdSketch_GLES.fsh
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ void main()
float bottomIntensity = texture2D(inputImageTexture, bottomTextureCoordinate).r;
float topIntensity = texture2D(inputImageTexture, topTextureCoordinate).r;
float h = -topLeftIntensity - 2.0 * topIntensity - topRightIntensity + bottomLeftIntensity + 2.0 * bottomIntensity + bottomRightIntensity;
h = max(0.0, h);
float v = -bottomLeftIntensity - 2.0 * leftIntensity - topLeftIntensity + bottomRightIntensity + 2.0 * rightIntensity + topRightIntensity;
v = max(0.0, v);

float mag = length(vec2(h, v)) * edgeStrength;
mag = 1.0 - step(threshold, mag);
Expand Down
2 changes: 1 addition & 1 deletion framework/Source/Operations/ThresholdSketch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ public class ThresholdSketchFilter: TextureSamplingOperation {
({edgeStrength = 1.0})()
({threshold = 0.25})()
}
}
}
2 changes: 1 addition & 1 deletion framework/Source/Pipeline.swift
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public class ImageRelay: ImageProcessingOperation {
public let maximumInputs:UInt = 1
public var preventRelay:Bool = false

init() {
public init() {
}

public func transmitPreviousImage(to target:ImageConsumer, atIndex:UInt) {
Expand Down
3 changes: 3 additions & 0 deletions framework/Source/ShaderUniformSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

public struct ShaderUniformSettings {
private var uniformValues = [String:Any]()

public init() {
}

public subscript(index:String) -> Float? {
get { return uniformValues[index] as? Float}
Expand Down

0 comments on commit 23e2089

Please sign in to comment.