Search Unity

Custom Lighting

Discussion in 'Shaders' started by boxhallowed, Jan 7, 2018.

  1. boxhallowed

    boxhallowed

    Joined:
    Mar 31, 2015
    Posts:
    513
    I've taken some of the udemy courses on shader programming, and I'm starting to understand some of the more intermediate topics, but I'm not sure where to start with a custom lighting system. I'm looking to replicate something along the lines of quake 1.

    I want to start by completely bypassing the Unity lighting system. Right now, if you set the ambient light to black and remove all light sources, everything is obviously black.

    Should I use emissivity and the dot function to do a basic bypass, or is there a different place I should start? Should I be using albedo somehow and writing the color directly to the screen?

    Additionally, assuming I want a simple light source, how do I get a shader to read the world position of another object?

    Thanks for your help!
     
  2. boxhallowed

    boxhallowed

    Joined:
    Mar 31, 2015
    Posts:
    513
    Basically, I have this, and I have a simple "brightness" slider. Assuming I want to fake a directional light for now, what would I plug into the DOT function to make this work? Is DOT right for this? I obviously don't want to use screenspace because it just "lights" the object as I got around it. I want it to be consistent with a direction I specify.

    upload_2018-1-6_22-0-32.png
     
  3. boxhallowed

    boxhallowed

    Joined:
    Mar 31, 2015
    Posts:
    513
    If I plug in the view direction, I get what I want with the camera, but I would rather be able to specify a custom direction instead. Eventually, I would want to be able to get the position of "point lights" as well, a custom object.

    upload_2018-1-6_22-22-39.png
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,342
    You're jumping into the deep end here with some fairly large holes in your knowledge.

    A simple Lambert diffuse is indeed a dot product between the surface normal and light direction, but it seems like you should do some more reading on how that really works.

    You don't. Shaders only get the information you feed it. Unity feeds a lot of information to shaders automatically, including light positions add the like when it's relevant. If you're trying to completely replace Unity's lighting system with custom object components for lights, then you need to track and manually pass that data to the shaders yourself. I would suggest not doing that unless you're much more familiar with shaders and rendering systems in general.

    It also looks like you're using Amplify Shader Editor, I'm not sure that's going to be the easiest way to tackle a custom lighting system either as that's not what it's really designed for. You use ASE to make custom Surface Shaders and fairly straightforward vertex fragment shaders. A fully custom lighting system is either going to need multiple passes or arrays, neither of which you can do in ASE that I'm aware of. If you only want a single unshadowed point light or directional light it can be enough, but beyond that I'm not sure it's plausible.
     
    AcidArrow likes this.
  5. boxhallowed

    boxhallowed

    Joined:
    Mar 31, 2015
    Posts:
    513
    A singled unshadowed light would be fine, as I'm only trying to replicate Quake 1. With ASE you can modify the shader source as well. Unfortunately, it's just not possible with any amount of work to make Unity's lighting system work with a fully procedural game. See my thread here: https://forum.unity.com/threads/light-bleed.511212/

    Since we're a small team and I'm the only programmer, I guess I will just have to dive off the deep end to figure it out. Even if the solution is a bit primitive.
     
  6. boxhallowed

    boxhallowed

    Joined:
    Mar 31, 2015
    Posts:
    513
    What if I used an unlit shader, then generated a 2D heatmap for basic lighting, and cheated the shadows through C#?
     
  7. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    I think KISS applies here, you're actually adding work not removing it. Quake classic should be by large entirely doable as a look with zero modifications to Unity, just by tinkering with the settings and using point filtering.

    Basically, why do you want to bypass Unity's lighting system?
     
  8. boxhallowed

    boxhallowed

    Joined:
    Mar 31, 2015
    Posts:
    513
    See my thread here, please read what I've tried to get it working with my game:
    https://forum.unity.com/threads/light-bleed.511212/
     
  9. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,342
    A directional light has by definition no position, only a direction. That direction is in the form of a float3 normalized vector. The easiest way to define that is by having a vector property that you use the first three components of and normalize in the shader and then just set it on the material.
     
  10. boxhallowed

    boxhallowed

    Joined:
    Mar 31, 2015
    Posts:
    513
    I'll give that a try, thank you. Whatever I get done I'll share.