Search Unity

Easiest way to apply convolution to texture2D?

Discussion in 'General Graphics' started by MafiaZebra, Jun 22, 2022.

  1. MafiaZebra

    MafiaZebra

    Joined:
    Feb 9, 2021
    Posts:
    4
    Hello, I'm newish to unity and want to allow the player to upload an image and then edit it. I'm trying to figure out how to apply convolutions to the texture2D for the image for certain effects but I'm not seeing anywhere how this is doable without shaders. Does anyone here know if it's possible to use a unity library to apply convolutions to an image in an efficient way? Thanks
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,492
  3. GoGoGadget

    GoGoGadget

    Joined:
    Sep 23, 2013
    Posts:
    864
    What kind of 'convolutions'? That's a very broad question.
     
  4. MafiaZebra

    MafiaZebra

    Joined:
    Feb 9, 2021
    Posts:
    4
    Hello thanks for responding. I mean applying a kernel to an image. I'm specifically trying to create a 3x3 matrix that represents a Sobel filter which I can then convolve with the texture2D represented as a matrix.
     
  5. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,073
    The most obvious way might be Texture2D.SetPixel/GetPixel/ or GetPixelData SetPixelData
     
  6. MafiaZebra

    MafiaZebra

    Joined:
    Feb 9, 2021
    Posts:
    4
    That's what I've been using so far to access the pixels but I'd have to code up a function to apply the convolution to the matrix if those are the only tools available. I figured there might be a way to do common matrix operations without turning everything into compute shaders but I was unable to find a commonly used way online.