Search Unity

_PPLAmbient

Discussion in 'Shaders' started by PrvtHudson, Jul 2, 2009.

  1. PrvtHudson

    PrvtHudson

    Joined:
    Apr 10, 2009
    Posts:
    236
    I am tearing shaders apart to learn ShaderLab. Could someone tell me what _PPLAmbient does. I guess it is a property that incoroprates the ambient light into the pass. Is there a list of these properties somewhere?

    Code (csharp):
    1.  
    2.         Pass {
    3.             Name "BASE"
    4.             Tags {"LightMode" = "PixelOrNone"}
    5.             Blend AppSrcAdd AppDstAdd
    6.             Color [_PPLAmbient]
    7.  
    The whole shader is here.

    http://www.unifycommunity.com/wiki/index.php?title=BumpColorSpec
     
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    PPLambient is the per pixel light ambient shader.
    If you go to the resource section on the website you can download the sources of all standard included shaders which will give you the possibility to read it in detail (and learn from them naturally)
     
  3. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    _PPLAmbient is the ambient light from RenderSettings. It is presumably called PPL because when doing per-pixel lighting, you separate the ambient term into a base pass, whereas vertex lighting is done in one pass, and includes the ambient term with all the other lights.

    _PPLAmbient, along with all of Unity's other builtin exposed values, is declared in UnityCG.cginc, either in the Unity.app bundle on Mac OS, or somewhere else on Windows. In either case, it's part of the installed program.
     
  4. PrvtHudson

    PrvtHudson

    Joined:
    Apr 10, 2009
    Posts:
    236
  5. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    I was pretty sure we could use _PPLAmbient in fixed functions shaders before. It's not working now, though. Is there something we can use instead, other than turning lighting on and using (2,2,2) as the ambient component? I tried UNITY_LIGHTMODEL_AMBIENT. That wasn't it.
     
  6. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    PPL never worked in fixed function.
    As the name implies its PerPixelLighting and per pixel means pixel shader ops.

    On FFP hardware this always led to a straight jump to fallback if that use was in.


    In the case of the original shader here its no topic anyway as that pass will be skipped from start on an FFP as it is set to PixelOrNone
     
  7. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    No, I just downloaded Unity iPhone 1.7 and verified that it worked. The result is 50% of whatever you set in the Render Settings:
     

    Attached Files:

  8. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    On the contrary, _PPLAmbient was used almost exclusively in base ("LightMode" = "PixelOrNone") passes prior to Unity 3, all of which used the fixed function pipeline. Base passes were used in cases where there was no lighting (only ambient) or per-pixel lighting, where an initial pass was needed for everything that didn't depend on dynamic lights.

    Turning on lighting and using Ambient [_Color] in the Material block is the correct way to use ambient light in vertex-lit shaders. This is how it was done in Unity 2.x as well.
     
  9. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Unsure if this proofs anything as Unity iPhone 1.x has no support for per pixel at all, its always enforcing FFP and falling back to it.
    On the other hand I just tried to recall an FFP counterpart to _PPLAmbient to get the ambient color for the shaderlab setup and can't recall one, but that does not mean anything as I know that traditional ambient lighting went through the hardware light 0 in DX and OGL (and as such a vertex light)

    In case of the ambient it does not make a difference anyway cause ambient is an unpositional thing with no direction ie no "per pixel thing" that could be used for any per pixel effect on a pixel shader aside of just mixing it in as environmental light color on the lightmap for example
     
  10. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    I'm not talking about a vertex lit shader. I just wanted to know if we had access to the color.
     
  11. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    It seems to work yes.
    Though unsure if it maps over a register or a texture

    Technically the correct way doing ambient in FFP would be vertex lit as ambient is a vertex light, but Unity has various helpers and pseudo macros to drive stuff elsewhere too for usage in shaderlab and even cgprograms
     
  12. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    I'm not sure how you get the ambient light colour in fixed function if you're not using lighting. I'm curious why you'd want that, though.
     
  13. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    Is that not what's going on in my screenshot above? I'm confused about what's happening, because it works fine in the Game View, but in order for it to work in the Scene View, the light button needs to be turned on.

    Someone was asking me for help with a day-night shader, for which night is just multiplying in some blue. They brought up the idea of using the ambient light color, and I thought that it seemed a reasonable place to change a global variable. I figured I could test to see if this was any faster than using "Lighting On", but I can't test if it doesn't even work.

    Do you know if using "Lighting On", with just an Ambient or Emissive term, is slower than using a ConstantColor?
     
  14. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    Sorry, I should've said I don't know in 3.x. _PPLAmbient is clearly deprecated, and I don't know if there's a replacement in fixed function.

    You'd have to test that yourself, although I think that at the moment getting colours from lighting is something like four times faster than getting them from constants on GLES 2.0 devices.