Search Unity

Can we use shaders without materials?

Discussion in 'Shaders' started by TheCelt, Sep 8, 2019.

  1. TheCelt

    TheCelt

    Joined:
    Feb 27, 2013
    Posts:
    742
    Hi

    I want to generate textures in a shader but not have have the shader associated to game objects / materials. Basically i just want to use it for image processing (in my case the Fourier transform).

    Is this possible ? Or does only compute shaders provide this functionality?
     
  2. mouurusai

    mouurusai

    Joined:
    Dec 2, 2011
    Posts:
    350
  3. TheCelt

    TheCelt

    Joined:
    Feb 27, 2013
    Posts:
    742
    Thanks though i am a bit confused how a shader might apply to it. Since i won't have a mesh.. how does it use a vertex shader in that context?

    Also if i want to process each pixel and no sub pixel calculations, how do you stop the fragment shader running between each pixel in the image ? I am basically trying to represent an image dimensions equal to my vertices so in between vertices would not make sense for my algorithm.
     
  4. mouurusai

    mouurusai

    Joined:
    Dec 2, 2011
    Posts:
    350
    Do you read article from link?
    <<how does it use a vertex shader in that context>>
    Custom render texture generate Vertex data by itself.
    <<Also if i want to process each pixel and no sub pixel calculations>>
    Just use texture coords(maybe you need add half texel offset to it)

    https://unitycoder.com/blog/2018/05/26/fire-effect-using-customrendertexture/
    https://github.com/keijiro/RDSystem
    https://github.com/hecomi/UnityWaterSurface

    If you need write computation results not in current fragment texel position then traditional shader is no go, you should use compute shader instead.
     
    Last edited: Sep 8, 2019
  5. TheCelt

    TheCelt

    Joined:
    Feb 27, 2013
    Posts:
    742

    Ah yeah i misread the vertex part my bad.

    When you say just use texture coords.. won't that mean i will run the calculation more than once for a given pixel on a render texture ? Say the fragment shader runs for a sub pixel coordinate, i would need to calculate it down to the nearest pixel coordinate each time. So i would be processing the same pixel more than once right ? Is there no way to get around that? Or do i misunderstand what you meant?
     
  6. mouurusai

    mouurusai

    Joined:
    Dec 2, 2011
    Posts:
    350
    If output render target size equals to input texture size(for Custom render texture it's always true) then texel size equals to fragment size and no subpixel reads.
     
    Last edited: Sep 8, 2019