Search Unity

Using light probe with new Shuriken particle system

Discussion in 'Editor & General Support' started by castor76, May 16, 2012.

  1. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    With old particle system, it was possible to use light probe with particle renderer.

    But with new Shuriken particle system it seems like that option was taken out.

    I wish to know what is the reason for this and is there a way work around for this? ( not using old one )

    I wish to use Shuriken because it can emit mesh objects. And I wish to apply light probe to the meshes that particle systme emits.

    Thanks.
     
  2. bluescrn

    bluescrn

    Joined:
    Feb 25, 2013
    Posts:
    642
    I'm also looking for this... there doesn't seem to be an obvious 'use light probes' setting for particle effects (either for mesh particles or for regular billboard particles?)

    Is this not supported? or is there some way to make it work?

    I'm not even looking for per-particle lighting, per-emitter would be just fine - it's needed for a number of small effects spawned in the world at run-time - to prevent things like smoke/dust from 'glowing' if spawned in darker areas.
     
    Last edited: Apr 3, 2013
  3. bluescrn

    bluescrn

    Joined:
    Feb 25, 2013
    Posts:
    642
    Well, for now I've managed to use GetInterpolatedLightProbe() to manually sample the lightprobes myself from a script, and pass the output into a material.

    It more-or-less works, but I'm not sure that I've got the maths quite right. I attempted to implement 'ShadeSH9' from the shaders in a script, and it took a fair bit of trial-and-improvement to figure out the order of the coefficients - but it's returning sensible colours - they're just a lot brighter than expected, by a factor of 4 or so, so I'm having to scale them down by a 'magic number' for now.

    Is there any sample code showing use of GetInterpolatedLightProbe() for this sort of thing? Or is somebody now going to tell me that there's a really easy way to get lightprobes to affect particles? :)
     
  4. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    Why don't you just pass the coefficients directly to the material and work out shading from there. I also can't say about the order of coefficients but my initial guess is that they should be in order or how they are used in SH9 code from the shader? If they don't seems like it, then can you let us know what your findings are?
     
  5. bluescrn

    bluescrn

    Joined:
    Feb 25, 2013
    Posts:
    642
    As far as I can tell, the coefficients aren't in the same order as the shader parameters, and need a bit of swapping around first.

    This is what I've got so far, which I think matches up with the sample code in the docs on Lightprobes.coefficients (http://docs.unity3d.com/Documentation/ScriptReference/LightProbes-coefficients.html)

    It seems to give reasonable results so long as I scale down the final output by a magic number. But there's no obvious scaling/clamping going on in the shader implementation.

    (For lighting particles, I'm just using a fixed upward-pointing normal at the moment, so I could simplify the calculation for that case, as a lot of the terms are multiplying by a constant zero)

    Code (csharp):
    1.  
    2. LightmapSettings.lightProbes.GetInterpolatedLightProbe( transform.position, this.particleSystem.renderer, m_aSample ); 
    3.  
    4. // Linear term
    5. m_v4RGB.x = m_aSample[0];
    6. m_v4RGB.y = m_aSample[1];
    7. m_v4RGB.z = m_aSample[2];
    8. m_v4RGB.w = 1.0f;
    9.  
    10. // Constant polynomial terms
    11. m_v4RGB.x += (m_aSample[3]*vNormal.x)+(m_aSample[6]*vNormal.y)+(m_aSample[9]*vNormal.z);
    12. m_v4RGB.y += (m_aSample[4]*vNormal.x)+(m_aSample[7]*vNormal.y)+(m_aSample[10]*vNormal.z);
    13. m_v4RGB.z += (m_aSample[5]*vNormal.x)+(m_aSample[8]*vNormal.y)+(m_aSample[11]*vNormal.z);      
    14.  
    15. // 4 of the quadratic polynomials
    16. Vector4 vB = new Vector4( vNormal.x*vNormal.y, vNormal.y*vNormal.z, vNormal.z*vNormal.z, vNormal.z*vNormal.x );
    17. m_v4RGB.x += (m_aSample[12]*vB.x)+(m_aSample[15]*vB.y)+(m_aSample[18]*vB.z)+(m_aSample[21]*vB.w);
    18. m_v4RGB.y += (m_aSample[13]*vB.x)+(m_aSample[16]*vB.y)+(m_aSample[19]*vB.z)+(m_aSample[22]*vB.w);
    19. m_v4RGB.z += (m_aSample[14]*vB.x)+(m_aSample[17]*vB.y)+(m_aSample[20]*vB.z)+(m_aSample[23]*vB.w);
    20.        
    21. // Final quadratic polynomial
    22. float fC = vNormal.x*vNormal.x - vNormal.y*vNormal.y;                      
    23. m_v4RGB.x += m_aSample[24]*fC;
    24. m_v4RGB.y += m_aSample[25]*fC;
    25. m_v4RGB.z += m_aSample[26]*fC;
    26.  
    27.  
     
    Last edited: Apr 4, 2013
  6. bluescrn

    bluescrn

    Joined:
    Feb 25, 2013
    Posts:
    642
    Has anyone else attempted to make this work?

    My earlier attempt at a solution doesn't work properly, and I don't know way.

    To sample a lightprobe RGB value for a fixed up normal (0,1,0), the maths should simplify down to this:

    Code (csharp):
    1.  
    2. m_v4RGB.x = m_aSample[0] + m_aSample[6];
    3. m_v4RGB.y = m_aSample[1] + m_aSample[7];
    4. m_v4RGB.z = m_aSample[2] + m_aSample[8];
    5. m_v4RGB.x -= m_aSample[24];        
    6. m_v4RGB.y -= m_aSample[25];        
    7. m_v4RGB.z -= m_aSample[26];    
    8.  
    to match the behaviour of a shader which does this:

    Code (csharp):
    1.  
    2. lightProbes.r = unity_SHAr.y+unity_SHAr.w;
    3. lightProbes.g = unity_SHAg.y+unity_SHAg.w;
    4. lightProbes.b = unity_SHAb.y+unity_SHAb.w;
    5. lightProbes  -= unity_SHC.rgb; 
    6.  
    (Which was a simplified version of ShadeSH9, for the case where the normal is 0,1,0)

    But while the shader appears to work OK, the code using GetInterpolatedLightProbe is not working properly... results seem to vary dramatically from scene to scene.

    Has anyone else had more success with this? - am I just interpreting the coefficient order incorrectly? Or is something else done to these coefficients before passing them to the shader?...
     
    Last edited: Nov 6, 2013
  7. bluescrn

    bluescrn

    Joined:
    Feb 25, 2013
    Posts:
    642
    Hmm, I'm trying to just get the constant term to match up, and it's not working...

    I'm comparing the first 3 coefficients returned from GetInterpolatedLightProbe() to the values of ( unity_SHAr.w, unity_SHAg.w, unity_SHAb.w ) from a shader, and they're not even close to matching up.

    Has anyone used GetInterpolatedLightProbe() with any success?
     
  8. bluescrn

    bluescrn

    Joined:
    Feb 25, 2013
    Posts:
    642