Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash while compile shaders for GaussianBlur #325

Open
khorbushko opened this issue Apr 14, 2021 · 0 comments
Open

Crash while compile shaders for GaussianBlur #325

khorbushko opened this issue Apr 14, 2021 · 0 comments

Comments

@khorbushko
Copy link

When create a simple effect like

    let testImage = UIImage(named:"cat.jpg")!
    let unsharpMask = UnsharpMask()
    unsharpMask.blurRadiusInPixels = 5
    unsharpMask.intensity = 2.5
    let filteredImage = testImage.filterWithOperation(unsharpMask)

within Xcode 12.4 and swift5 I got an fatalError with shader compilation error:

Compile log: ERROR: 0:2: 'float' : declaration must include a precision qualifier for type

ERROR: 0:3: 'float' : declaration must include a precision qualifier for type

ERROR: 0:5: 'vec2[7]' : declaration must include a precision qualifier for type

ERROR: 0:9: 'vec4' : declaration must include a precision qualifier for type

ERROR: 0:10: Use of undeclared identifier 'sum'

ERROR: 0:10: Use of undeclared identifier 'blurCoordinates'

ERROR: 0:11: Use of undeclared identifier 'sum'

ERROR: 0:11: Use of undeclared identifier 'blurCoordinates'

ERROR: 0:12: Use of undeclared identifier 'sum'

ERROR: 0:12: Use of undeclared identifier 'blurCoordinates'

ERROR: 0:13: Use of undeclared identifier 'sum'

ERROR: 0:13: Use of undeclared identifier 'blurCoordinates'

ERROR: 0:14: Use of undeclared identifier 'sum'

ERROR: 0:14: Use of undeclared identifier 'blurCoordinates'

ERROR: 0:15: Use of undeclared identifier 'sum'

ERROR: 0:15: Use of undeclared identifier 'blurCoordinates'

ERROR: 0:16: Use of undeclared identifier 'sum'

ERROR: 0:16: Use of undeclared identifier 'blurCoordinates'

ERROR: 0:17: Use of undeclared identifier 'sum'

Shader deallocated --> ShaderProgram.swift: deinit: 64

ERROR: GaussianBlur compilation failed with error: ShaderCompileError(compileLog: "Fragment shader compile error:")

Fatal error: Aborting execution.: file GPUImage/ShaderProgram.swift, line 253

2021-04-14 14:09:41.961013+0300 gpuImage2tests[94267:692420] Fatal error: Aborting execution.: file GPUImage/ShaderProgram.swift, line 253

looks like shaders needs to be modified a bit by adding required precision. I added highp for some values and looks like this solve the issue, but better if @BradLarson u can check this issue.

example of modified shader:

func vertexShaderForStandardGaussianBlurOfRadius(_ radius:UInt, sigma:Double) -> String {
    guard (radius > 0) else { return OneInputVertexShader }
    
    let numberOfBlurCoordinates = radius * 2 + 1
    var shaderString = "#version 310 es \n attribute highp vec4 position;\n attribute highp vec4 inputTextureCoordinate;\n \n uniform  highp float texelWidth;\n uniform highp float texelHeight;\n \n varying highp vec2 blurCoordinates[\(numberOfBlurCoordinates)];\n \n void main()\n {\n gl_Position = position;\n \n highp vec2 singleStepOffset = vec2(texelWidth, texelHeight);\n"
    for currentBlurCoordinateIndex in 0..<numberOfBlurCoordinates {
        let offsetFromCenter = Int(currentBlurCoordinateIndex) - Int(radius)
        if (offsetFromCenter < 0) {
            shaderString += "blurCoordinates[\(currentBlurCoordinateIndex)] = inputTextureCoordinate.xy - singleStepOffset * \(Float(-offsetFromCenter));\n"
        } else if (offsetFromCenter > 0) {
            shaderString += "blurCoordinates[\(currentBlurCoordinateIndex)] = inputTextureCoordinate.xy + singleStepOffset * \(Float(offsetFromCenter));\n"
        } else {
            shaderString += "blurCoordinates[\(currentBlurCoordinateIndex)] = inputTextureCoordinate.xy;\n"
        }
    }
    
    shaderString += "}\n"
    return shaderString
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant