Search Unity

Particles' tangent basis, or how to put NormalMap on particles or even basic lighting

Discussion in 'Shaders' started by fvdsn, Jan 20, 2011.

  1. fvdsn

    fvdsn

    Joined:
    Nov 15, 2009
    Posts:
    7
    Hi there,
    I'm looking into fetching the world space tangent basis to light up some particles for an iPhone project (GLSL shader).

    I'm using camera facing particles. When I sample gl_Normal.xyz it outputs vec3(0.0, 0.0 , 1.0), whatever the angle I look at it, so it's not even in object space.

    Worse, attribute vec4 Tangent; is always 0.0

    How can I force this to output the proper vertex data? Don't tell me every single particle system in Unity is self illuminated or has baked lighting (and no rotation)... or are they? :eek:

    Thanks for your help
     
  2. Daimon

    Daimon

    Joined:
    Jul 20, 2010
    Posts:
    32
    im not sure if this helps, but do you have any light source in your scene ?
     
  3. bricevdm

    bricevdm

    Joined:
    Nov 4, 2009
    Posts:
    34
    No I don't, I wrote a custom lighting system. Using lamps is not what I'm looking for.

    (I messed up and used my colleague's account for the first post, Sorry about the confusion)
     
  4. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    You will have to write an own particle system or better want to.
    You can always calculate the normal (you can get the position of each particle and feed it to the vertex shader for example to calc the normal) but the question is if you really want to do that if you could offload the whole particle updating etc to the vertex shader and get the normal etc as a "free byproduct"
     
  5. bricevdm

    bricevdm

    Joined:
    Nov 4, 2009
    Posts:
    34
    I'm not sure I understand...
    I don't know any way to generate a normal with just a single vertex position (I doubt there is any since the normal is calculated using surrounding geometry). That still doesn't help for tangent since I need to know the derivative of the UVs, another non-local information.
    I don't know about doing it all to the vertex shader either since I can never know how much particles there is, I'll quickly run out of constants (remember I'm doing stuff for iPhone)
     
  6. Lex-DRL

    Lex-DRL

    Joined:
    Oct 10, 2011
    Posts:
    140
    Hi B.Vandemoortele,
    did you find a solution? I'm facing the same issue now.
    The normal vector is provided, so particles react to the light as expected if there is no normal mapping:
    http://my.jetscreenshot.com/24064/20140730-1zac-50kb
    http://my.jetscreenshot.com/24064/20140730-kfs0-47kb
    http://my.jetscreenshot.com/24064/20140730-bw75-63kb

    But then I apply a very simple normal map, something goes wrong:
    http://my.jetscreenshot.com/24064/20140730-xdsa-78kb

    Obviously, normal vector is correct, but tangent vector (which is also used to calculate binormal) is really wrong.
     
  7. bricevdm

    bricevdm

    Joined:
    Nov 4, 2009
    Posts:
    34
    sorry I haven't
    if you're confident the normal is correct than there might be a workaround. from the look of your screenshots it seems the tangent basis is not updated. If it was missing everything would probably look black (the operation to transform the light would multiply by 0). If you can predict the rotation of your particles (you don't use "random between..."), you could maybe store a rotation factor into the (vertex) color and use it in the shader to do a rotation there ("maybe"...just thinking).

    good luck tough :)