Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Adjusting lighting for pixel/vertex shading

Discussion in 'Editor & General Support' started by Bampf, Dec 20, 2006.

  1. Bampf

    Bampf

    Joined:
    Oct 21, 2005
    Posts:
    369
    My game used to look good at medium quality settings, but then I tried it on Fantastic and the scene washed out. I then forced the light to use the pixel shader so I could see this inside the editor, and adjusted the lighting. But now the low quality settings are very flat- I'm either operating at the very edge of the spotlight cone or "force pixel" turns off the spotlight entirely when pixel lighting isn't available. (Does it?)

    Seems like I need a 2nd light that's used only for vertex lighting, and activate at most one of the lights. Is there a way other than interrogating the player selected quality setting, i.e.:
    PlayerPrefs.GetInt("UnityGraphicsQuality", 3)
    (It does seem that I can effectively deactivate the pixel spotlight in my game already, so I just need to do the same for a vertex-based light.)

    Much obliged in advance.
     
  2. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    Not quite sure I understand the problem... Is the light in question a spot light? What shaders are you using (i.e. if it's Glossy or BumpedSpecular; then the bright thing might be specular reflection)?

    Do you have a simple project/package that shows the difference between vertex/pixel? Please send it via Report Bug.app with instructions where to look at.
     
  3. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,324
    If you switch from pixel to vertex lighting then you need to tesselate your geometry some to let the vertex lighting look more realistic. Sub divide your wood table and paper meshes into a lot more faces and vertex lighting should look much better and not wash out.
     
  4. Bampf

    Bampf

    Joined:
    Oct 21, 2005
    Posts:
    369
    I appreciate your interest in the problem. I can't send you the project until tonight (12 hours from now) and I won't have time to properly reduce it to a sample (trying to meet that 3DU deadline this week.)

    I'll try to clarify, keeping in mind that my understanding of the problem may be flawed. If I had an answer to the original questions then I could hack around it, but I am all for understanding the "right" solution as well.

    My game features a flat sheet of white paper lying on a desk (see the "A Tack!" thread in the Showcase forum for a screenshot.) I am striving for a desklamp-like lighting effect, using one spotlight to give a nice edge to the light hitting the desk. (I also have a directional light supplying ambient light.)

    Late in the dev cycle I tried my game on Fantastic and found that the place where the spotlight hits the paper was totally oversaturated. Only happens with pixel lighting. I believe the paper is using the Diffuse shader, but with a spot hitting it dead on I think that's understandable.

    I forced pixel shading just so I could reliably see the problem in the editor, then adjusted the spotlight to reduce the glare. In the end I think I basically rotated the spot so it wasn't pointing straight at the paper, then moved it so I was still getting a nice curved edge to the light where I wanted it. I also reduced the amount of ambient light a little.

    Looks fine on Fantastic now, but if I don't force the spotlight to pixel shade and/or scene quality is set to Simple/Fast, the desk and paper are virtually unlit.

    My uneducated guess is that I've gotten rid of the spotlight glare merely by operating at the outer fringes of the spotlight's cone, and that the same spotlight has virtually no effect on vertex lighting. So I proposed a hack that would allow me to tweak vertex and pixel lighting independently, using two mutually exclusive lights. It's frustrating to fix one lighting mode only to find that I've broken the other, though a unified lighting scheme would be much more elegant.

    I'm definitely up for investigating the proper way to light this scene, but given the deadline I may also need the two-light hack solution. I see now that I can interrogate
    QualitySettings.currentLevel
    rather than go through PlayerPrefs. But perhaps the following would work?
    if (Light.pixelLightCount == 0)
    {
    // enable the spotlight's replacement
    }
     
  5. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    Ok, for a quick hack you could use either QualitySettings or pixelLightCount. You could also just darken the spotlight's color when it's pixel lit.

    I'll play around with spotlights and see whether there's some real problem.
     
  6. Bampf

    Bampf

    Joined:
    Oct 21, 2005
    Posts:
    369
    Thanks for the help. I'll BugReport my project tonight when I get a free minute. It's not large, and maybe that'll save you from chasing a red herring.
     
  7. Bampf

    Bampf

    Joined:
    Oct 21, 2005
    Posts:
    369
    Submitted the project (case 6746.)

    I tried to increase the range of the spotlight when vertex lighting is being used. When it works it looks pretty good. However I'm finding that I can't reliably use either Quality settings or pixelLightCount to decide when adjust the spotlight. Apparently it sometimes reports pixelLightCount == 0 when still using pixel lighting, for instance (either that or the vertex lighting's brightness can vary.)

    Assuming my code is working as intended, I guess I can't anticipate 100% correctly what choice the renderer will use for the spotlight, and so I can't adjust it proactively. Either I set the spotlight to Force Pixel and hope that most people can run the game as intended, or I design the screne so that both forms of lighting work with no adjustment.