Search Unity

Unity Shaderlab : update pixel A with a result from a different pixel B.

Discussion in 'Shaders' started by bugsbun, Sep 5, 2017.

  1. bugsbun

    bugsbun

    Joined:
    Jun 26, 2017
    Posts:
    27
    So I wanted to do the above. From what I have read is that this can be achieved with point splatting. Instead of drawing a full-screen quad and updating everything in a fragment shader, I can run a vertex shader with a vertex for every pixel. Now I can do the computation as before, and can make the result (a point drawn) go to an arbitrary position B.

    But how can I do this in Unity shader. How can I run the vertex shader with vertex for every pixel ?Can sombebody give me or point to a simple example?
     
  2. olkeencole

    olkeencole

    Joined:
    Oct 2, 2009
    Posts:
    17
    Where have you read about this? And what are your intended goals?
     
  3. bugsbun

    bugsbun

    Joined:
    Jun 26, 2017
    Posts:
    27
    My goal is to update pixel A with result from a different pixel B in my shader . As far as I know this cannot be done in a fragment part , but this can be done in vertex shader
     
  4. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,620
    That doesn't tell us what you're trying to achieve, though. Metaphorically, you're asking how to swing a hammer, and @olkeencole is trying to figure out if a hammer is the right tool for the job.

    What is the problem you're trying to solve that you think this is a good solution for?

    Referring to your PM, I know relatively little about shaders so I can't really help you here.
     
  5. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    9,052
    It depends on what a is and what b is. You can use texcoords for position, for example I just wrote a dropshadow shader which pixels were offset (and recolored) by a given xy, but that is simple. It is going to depend on your logic and what you are trying to achieve. Need more information to offer a useful suggestion.
     
  6. bugsbun

    bugsbun

    Joined:
    Jun 26, 2017
    Posts:
    27
    I am updating pixel B with some calculated value that is present at pixel A only, other pixels can also contribute to pixel B but their contribution will be different based on condition and calculation. I want to do something similar that can be achieved with imageLoad/Store in GLSL where you can update a image (that can be the image viewed from the camera) in realtime at an arbitary location. This I want to do in shaderlab.

    Edit: Also keeping in mind that pixel A is also being updated in realtime
     
    Last edited: Sep 6, 2017
  7. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    You should tell us the end goal because you don't have anywhere near the experience to decide if you're doing it right or if it's even possible. If you did, you wouldn't be saying things like this.

    I can't visualise what your actual request is.
     
    zombiegorilla likes this.
  8. bugsbun

    bugsbun

    Joined:
    Jun 26, 2017
    Posts:
    27
    I want to copy the reflectance value of point A to point B, and each point in the scene has a different reflectance value. You can take any model of BRDF for your choice, Cook-Torrence(physically based) or Phong or any other .
     
  9. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    9,052
    Yea, still not clear. Is it really just one pixel, or several? Point in space or elsewhere in the pass? Based on the info so far, it doesn't sound like some you would do in shader. More likely you'll do by manipulation of the texture, bu that is a guess. Please provide an example.
     
  10. bugsbun

    bugsbun

    Joined:
    Jun 26, 2017
    Posts:
    27
    The whole scene is to be updated
    Several Pixel can effect 1 pixel: "Many on one" or "one on one" relationship
    I want to update points in 3D , But I would not mind first projecting them in screen space and doing this in a texture
    Yes I tried to do it in C# using textures, but it is very slow.

    The thing I want to do is similar to imageLoad/Store. This functionality in GLSL allows us to updayte an image at arbitary location, writing textures instead of reading it , using atomicadd, but but but I have not done GLSL before and Unity also doesnot support it.
     
  11. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    This means a million things. So it doesn't mean anything to us.
    This is meaningless. Pixels cannot ever effect other pixels. Pixels are typically going to be part of a texture. Textures can't do anything by themselves.
    So you are basically talking about path tracing? Just trying to be warm here.
    But you are saying you are asking for things that you do not understand. Therefore I am out. Good luck though.
     
  12. bugsbun

    bugsbun

    Joined:
    Jun 26, 2017
    Posts:
    27
    All the pixels in the scene arebeing updated
    By this: "Several Pixel can effect 1 pixel: "Many on one" or "one on one" relationship" I meant that I want my program to do that
    I am not stupid enough to do that
    Yes you always ask for things that you dont understand. GLSL technique is the second option but I cannot do it in Unity .
    So no way of going there, that was just a reference. What can be done is already asked in the question but I am asking a path to get started .Thanks anyways
     
  13. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    9,052
    You still haven't described what you are trying to do. You just keep restating a process, without details. Are you making a map, an fx, modification to a characters hat? It's impossible offer any practical advice without understanding the problem.

    Manipulation of pixels is usually abstract, not at game code. And shaders are meant to do very fast math, not really much logic. The also have virtually no awareness of anything else in the game. Anything else, like transform positions, you will have to pass in. (Or previously rendered data). Unless it is very simple (in shader terms) information, you'll still have to do the logic on the c# side. If that is slow, a shader isn't going to be faster, probably slower and more prone to break.

    So, unless you can better describe your actual goal and set up, I can't help.
     
  14. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,620
    What is the end goal you're trying to achieve? Are you making a mirror? A flowing river? Twinkling stars? Dynamic terrain generator filters on the GPU?

    Carrying on with my previous metaphor with the hammer, we're asking "What are you trying to build?" and you keep answering "I'm swinging a hammer." We don't know if you're making a car or a cupboard, and have no idea what advice might actually be useful.