Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Fragment shader writing 3x per pixel (to compute buffer)

Discussion in 'Shaders' started by BitJunkie, Aug 15, 2019.

  1. BitJunkie

    BitJunkie

    Joined:
    Jun 8, 2017
    Posts:
    5
    If I count the number of writes per pixel using InterlockedAdd on a RWStructuredBuffer, I can plainly see that the fragment shader is running 3x for every pixel of the mesh, per frame. 6x and more if backface culling is turned off or there are overlaps. Is this intended behavior? How does it avoid drawing translucent pixels too dense if it's drawing multiple times?

    It's important to me to save info once per pixel per polygon layer. I need to record all the depth values of the mesh for building a 3D volume, even if the mesh overlaps a few times.

    (The mesh is procedurally made and rendered with with DrawProcedural to one camera. The scene is VR enabled, but this camera's set to 'target eye: None' so it only runs once.)