Home Unity

How would I create attenuation with no shadows? (In shader forge)

I have been experimenting with shader forge for a bit, but, I cant seem to create lighting for an object that just calculates lighting attenuation and not shadows.

To be specific - When an object gets close to a light source it gets brighter (evenly across the entire surface), when it moves away it gets darker in the same manor.

I cant seem to get it right. Any ideas?

Replies

  • Farfarer
    Options
    Offline / Send Message
    You can do it, but probably not with shader forge. You'll need to hand code it.
  • almighty_gir
    Options
    Offline / Send Message
    almighty_gir ngon master
    Isn't this just handled by unities internal "Atten" parameter?
  • Farfarer
    Options
    Offline / Send Message
    Atten includes the shadow value premultiplied in. You have to pick out the code that does the attenuation from the code that does the shadows before they get multiplied together.

    The code's in AutoLight.cginc...
  • Linksta
    Options
    Offline / Send Message
    Farfarer wrote: »
    Atten includes the shadow value premultiplied in. You have to pick out the code that does the attenuation from the code that does the shadows before they get multiplied together.

    The code's in AutoLight.cginc...

    Ok, so maybe I can use the custom code node in shaderforge and dump just the AutoLight.cginc code into it?
  • Farfarer
    Options
    Offline / Send Message
    Bits of it, maybe. I write my shaders by hand so I'm not sure how ShaderForge deals with it.

    It should be obvious where the light and shadow values are gotten from, but be aware that they're nested in defines depending on the light and shadow types.
  • Linksta
    Options
    Offline / Send Message
    I think I'm in over my head here. How hard would it be to take a standard diffuse shader and modify the attenuation to brighten and darken (evenly) via distance? I appreciate you musing back and forth with me. There is a lot about shaders that I don't fully understand yet. That's why shader forge is helpful. Although it seems like I'm starting to run into limitations with it.
  • Brendan
    Options
    Offline / Send Message
    Brendan polycounter lvl 8
    Shader Forge has, I think, both a light position and object position nodes.

    Hook both of those up to a distance node.

    Divide that by a VALUE (// light range) node.

    Plug that into a Power node A slot, and plug a new VALUE (// attenuation) into the B slot.

    Multiply by Light Color

    Clamp 0-1

    Into Emission.

    If you want it to take into account the curvature of the object...change the Object Position to World Position, and multiply by (DOT: Normal, Light Direction) at some point before the clamp.
  • Linksta
    Options
    Offline / Send Message
    That was exactly what I was looking for! The silly thing is, I had something very similar but I tried to connect the object and light position into a dot product. In hind sight that makes little sense. I appreciate the help, I really do.
Sign In or Register to comment.