Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Geometry data between passes/receive shadow information in vertex shader

Discussion in 'Shaders' started by weremagames, Dec 4, 2016.

  1. weremagames

    weremagames

    Joined:
    Dec 4, 2016
    Posts:
    9
    I have few questions about shaders:
    -Is it possible to generate vertices in geometry shader in one pass and send them to vertex shader in another pass?
    -Is it possible to send vertices from geometry shader to surface shader?
    -Is it possible to receive data about shadows in vertex shader? Somehow check if vertex is lit or shadowed. Maybe in a pass after surface shader
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,209
    No*. Shaders run vertex shader > geometry shader > fragment shader and can pass data on each step to the next, but there's no direct way to pass information from one pass to another, especially not from the vertex or geometry shader of one pass to another.

    No. Unity does not have support for using geometry shaders with surface shaders. You can however add geometry shaders to the generated shader code from a surface shader.

    All stages of a shader pass that deals with shadows have access to the shadows, but the built in functions and macros may not work. If you're using a surface shader it can also complicate things some. However a pass either gets shadow data or it doesn't, again other passes can't 'pass' data to others.

    * Some people abuse the grab pass, which internally is making a copy of the entire screen contents, to pass the color output from one shader pass to another. But this should be avoided when possible. There's also techniques for rendering to a render texture the data you want from one shader so another can use it, this is in fact what compute shaders do, but generally people aren't using geometry shaders for this kind of thing, but I suspect this is beyond what you're trying to do. Additionally there are some techniques for saving the output of a vertex or geometry shader to a mesh that's stored on the GPU and reusing it for another shader, this is how Unity's GPU skinning works, but there's no way I know of to use that directly.