Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Image Processing in Compute Shaders [Open Source]

Discussion in 'Assets and Asset Store' started by bleppie2, Nov 21, 2023.

  1. bleppie2


    Mar 25, 2015
    Hi all, I just put this up on github for when you want to mess with your textures but don't want to install OpenCV or the like. It's pretty lightweight and uses all Compute Shaders. In addition to the simple ops, there's a nice constant-time Gaussian blur based on recursive convolution (great for big blurs, not as accurate for small blurs), Skeletonization, and Histogram Equalization.

    README is below. You can find it here:


    Blep.TextureOps is a Unity plugin that allows you to manipulate Textures using compute shaders. Note: This has been tested on OSX/Metal only, but should work on all platforms that support compute shaders. If there are problems, please let me know.

    Static classes provide all the functionality, for example:
    • TextureMath.Add(srcA, srcB, dst)
    • TextureIP.Threshold(src, dst, new Vector4(0.5, 0.5, 0.5, 0))
    • TextureDraw.Circle(src,, new Vector2(100, 100), 10)
    See more examples in TextureOpsExample.cs.

    The TextureCompute class provides some nice utilities for working with Textures and compute shaders so you can write your own operations.

    Installation Instructions
    Install from Git or copy to your Assets folder

    Supported Operations

    • Copy
    • Set to Constant
    • Set to Constant with a channel mask
    • Set to Constant with an alpha (image) mask
    • Add Src + Constant
    • Add SrcA + SrcB
    • AddWeighted SrcA * ConstantA + SrcB * ConstantB
    • Lerp(SrcA, SrcB, Constant)
    • Multiply Src * Constant
    • Multiply SrcA * SrcB
    • MultiplyAdd: Src * ConstantA + ConstantB
    • Clamp(Src, ConstantA, ConstantB)
    • Saturate
    • Remap from one range to another
    • Circle
    • Line
    • Border
    Image Processing
    • Grayscale
    • GrayscaleGamma: grayscale a gamma image by first converting to linear space
    • Threshold
    • ConvertRGB2HSV
    • ConvertHSV2RGB
    • Swizzle
    • Lookup using a pallete
    • Contrast adjustment
    • FlipHorizontal
    • FlipVertical
    • Rotate180
    Morphology Etc
    • Erode
    • Dilate
    • Skeletonize
    • Sobel
    • Scharr
    • BlurGaussian
    • RecursiveConvolve: constant time convolution
    • BlurGaussianRecursive: constant time gaussian for big blurs
    • GetHistogram as a ComputeBuffer
    • GetHistogram as an array
    • EqualizeHistogram
    • Reduce: used by Min, Max, Sum
    • Min
    • Max
    • Sum
    • ComposeOver
    • ComposeIn
    • ComposeOut
    • ComposeAtop
    • ComposeXor
    • ComposePlus
    Known Limitations
    • Does absolutely no parameter checking, for example making sure that the dimensions of the images in a binary operation are the same size.
    • Unless specified, Math operations do not saturate, so they should be used either with high-range-count textures (float, int) or carefully.
    Mark_01 likes this.