Search Unity

Unity 5 and adding geometry trough Geometry Shaders

Discussion in 'Shaders' started by CrystalKupo, Jun 21, 2015.

  1. CrystalKupo

    CrystalKupo

    Joined:
    Jun 21, 2015
    Posts:
    3
    In older versions of Unity I remember Geometry Shaders weren't a thing and I'd like to know if it's already possible to add geometry with custom Unity 5 shaders.

    I'm coming from a HLSL background were I could add geometry in geometry shaders using
    TriangleStream::Append(...), is something like that possible in Unity too? (I have to add a lot of vertices each frame so I'd rather do it on the GPU than on the CPU)
     
  2. Plutoman

    Plutoman

    Joined:
    May 24, 2013
    Posts:
    257
    Yeah, I just implemented this yesterday actually. Geometry shaders work just fine!
     
  3. Zero_Xue

    Zero_Xue

    Joined:
    Apr 18, 2012
    Posts:
    116
    Any chance you have a custom geometry shader to share???
     
  4. CrystalKupo

    CrystalKupo

    Joined:
    Jun 21, 2015
    Posts:
    3
    Cool! But I don't suppose I could just paste in HLSL shader, you have any pointers to references or an example shader that creates new geometry?
     
  5. Plutoman

    Plutoman

    Joined:
    May 24, 2013
    Posts:
    257
    I started from this;
    http://forum.unity3d.com/threads/billboard-geometry-shader.169415/

    Worked great.

    I'm using it to implement this right now - http://forum.unity3d.com/threads/rendering-field-of-grass-grid-autosport-tech.327046/ - as the fins that are expanded into geometry.

    On the HLSL note, you actually can just paste in HLSL code generally. MSDN documents are just plain awful though. I'd have to look up how to do it for something besides a point input if you needed something besides that. If you have an HLSL background though, you might know more about it than I do. Unity works in HLSL and converts automatically to GLSL when necessary, unless you specifically design a GLSL program. For example: in some of my other shaders I use Sample and SampleLevel instead of the built in tex2D calls, to bypass the sampler limits and allow more than 16 textures in a single pass.

    I don't think everything is supported.. but most things I've worked with are (at least with some fiddling).
     
  6. Zero_Xue

    Zero_Xue

    Joined:
    Apr 18, 2012
    Posts:
    116
    i would really appreicate it if you were to share the shader, i nver even looked into how to make shaders, since its only recently became a problem when my freind (who does all the models) learnt some new tricks on blender, tricks i havent been able to do in Unity... and as close as i can get them well looks crap heres an example.....

    apperenly he just adds geometry something unity apperenly lacks
     
  7. Plutoman

    Plutoman

    Joined:
    May 24, 2013
    Posts:
    257
    I think you might be misunderstanding the concepts? A geometry is a shader that dynamically generates new vertexes based on an algorithm. It's all based on the use case. If you want just general case, more detail, then tessellation might be what you're looking for.

    Geometry shaders are very specific use-cases, though, it's not something you just apply to a model and it looks better, for ex.
     
  8. Zero_Xue

    Zero_Xue

    Joined:
    Apr 18, 2012
    Posts:
    116
    god knows, i dont have a clue about modeling, i just deal with scripts, i dont know the first thing about shaders, but cheers neway, time to look into tessellation then am guessing =)
     
  9. Plutoman

    Plutoman

    Joined:
    May 24, 2013
    Posts:
    257