Search Unity

Changing point light falloff for standard shader?

Discussion in 'Shaders' started by Zomby138, Mar 19, 2015.

  1. Zomby138

    Zomby138

    Joined:
    Nov 3, 2009
    Posts:
    659
    Hello. I really hate the way the light falloff / attenuation looks for point and spot lights, particularly in linear lighting mode. I'd light to make a falloff curve that's more realistic.

    I've been looking through the CGIncludes folder, trying to find the right part of the source code to edit. The closest thing I've been able to find is in UnityDeferredLibrary.cginc, there's a bit that's like

    float3 tolight = wpos - _LightPos.xyz;
    half3 lightDir = -normalize (tolight);

    float att = dot(tolight, tolight) * _LightPos.w;
    float atten = tex2D (_LightTextureB0, att.rr).UNITY_ATTEN_CHANNEL;

    Which to me looks like the right thing. But changing this makes no difference at all. Is this part of the code even used by the standard shader? Or is this part of the legacy shaders or something?

    The other part I've found that looks interesting is the BRDF1_Unity_PBS function in UnityStandardBRDF.cginc. Messing around with this function seems to effect the material preview sphere, but not the actual scene view etc. Also, unfortunately I can't see anything about distance in there.

    Can anyone point me in the right direction? @Aras maybe?
     
  2. Cherno

    Cherno

    Joined:
    Apr 7, 2013
    Posts:
    515
  3. Zomby138

    Zomby138

    Joined:
    Nov 3, 2009
    Posts:
    659
    Looks like there's a lot of good information there, thanks! The bit about needing to restart the editor sounds like something I was missing in particular.

    I'll try it out next time I'm at home.
     
  4. Zomby138

    Zomby138

    Joined:
    Nov 3, 2009
    Posts:
    659
    Well that didn't work :\ I copied Internal-DeferredShading.shader and UnityDeferredLibrary.cginc into Assets\Resources as suggested by this page http://docs.unity3d.com/Manual/RenderTech-DeferredShading.html

    They definitely get built, if I mess up the code it gives me errors, but they make absolutely no difference to what I see in the scene view, game view, or final build.

    I've restarted the editor many times too.

    Am I doing something wrong or is this kinda broken in 5.0 at the moment? Has anyone managed to get this to work at all in 5.0?
     
  5. kebrus

    kebrus

    Joined:
    Oct 10, 2011
    Posts:
    415
    Did you tried the texture lookup version? I don't know if unity 5 changed anything, but considering the code you provided earlier I'm guessing it's still using a texture to find out the falloff so changing the code to support a custom texture should indeed work.
     
  6. Zomby138

    Zomby138

    Joined:
    Nov 3, 2009
    Posts:
    659
    Unfortunately my problem is more fundamental than that. Unity isn't even using the code in my Assets/Resources folder. It's compiling it, but then it clearly uses its built in stuff anyway.

    :(
     
  7. kebrus

    kebrus

    Joined:
    Oct 10, 2011
    Posts:
    415
    I had that problem before, actually had to override the standard shader to use different includes pointing to mine because for some reason i never discovered it wasn't picking up the ones in the resources folder that were supposed to be overriding the default ones. It's a pain actually, i had to change a bunch of includes all over the place, but after that it worked.
     
  8. Zomby138

    Zomby138

    Joined:
    Nov 3, 2009
    Posts:
    659
    Hmm. So putting the files in the Resources folder is meant to work but doesn't. So it's an actual bug?

    It would be really nice if a member of the Unity team could chime in here. @Aras @KEngelstoft ?
     
  9. UnityGuillaume

    UnityGuillaume

    Unity Technologies

    Joined:
    Mar 16, 2015
    Posts:
    123
    Hum have you tried to put the shader in "Edit>Project settings>graphics" then you have a "Built-in shader setting" and change the option for Deferred to "custom Shader" and give it your custom shader.
     
    tinyant likes this.
  10. Zomby138

    Zomby138

    Joined:
    Nov 3, 2009
    Posts:
    659