Search Unity

How would I implement a custom lighting model?

Discussion in 'Shaders' started by iko79, Oct 21, 2013.

  1. iko79

    iko79

    Joined:
    Jan 21, 2013
    Posts:
    45
    Hi folks,

    I spent some time to implement a postpro-shader which does some scene-lighting based on additional, custom light sources. The objective was to enable IES profiles [1] which basically describe light distributions, depending on light vector angles. In order to get all the information I need for lighting into my postpro shader, I had to render the respective g-buffers (world-positions, normals, main color, specular color, shininess, etc.) by myself, at least I couldn't find a way to re-use the ones which I suppose have to be generated for deferred lighting anyway. The current implementation works fairly well, however, having to render my own g-buffers, I lose a lot of flexibility since this confilicts with the implementation of several materials -- the current imlementation does not support multitexturing, alpha textures, semi-transparency, etc, not to mention all the fancy surface-shaders I would like to use on my models.

    So there where several questions emerging while I tried to implement this properly: was I wrong in the first place, doing this as a post-pro shader? Would there be a way of using the already present g-buffers? What would be the best approach of implementing this? Would there even be a way of writing a custom lighting model which would work with all existing materials?

    (Note that my IES profile light sources need to support non-symmetric profiles.)

    Cheers,
    iko


    [1] http://www.cgarena.com/freestuff/tutorials/max/ieslights/
     
  2. aoxiangyuntian

    aoxiangyuntian

    Joined:
    Jun 20, 2013
    Posts:
    7
  3. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    From what you've said about your implementation, it sounds like you're doing a lot of work that's already being done. How far do you think you are from being able to do all the lighting yourself, and avoid the built-in deferred system entirely?
     
  4. iko79

    iko79

    Joined:
    Jan 21, 2013
    Posts:
    45
    @aoxiangyuntian: I just sent an e-mail to the developer, then I realized it's you :) So never mind the mail, I'm gonna ask here:

    The package looks good – however, I’ve got a question regarding IES profile support. You state you’re “compatible” with all IES format but you don’t state you’re “compliant”. In you demo I’ve seen only axial-symmetric (thus 1D) profiles (I can't tell if the one on the right is non-symmetric or just rotated). Do you also support non-symmetric (2D) profiles? Such as profiles one would need to describe e.g. car headlights?

    @Daniel:
    Yeah, that's what I was thinking, that I had to do a lot of redundant work since I couldn't find a way to make use of Unity's g-buffers. Actually, I got the impression, that I'm not that far from doing all the lighting by myself, but I wouldn't accomplish the visual quality. E.g. my current shadow mapping implementation sucks since it doesn't use cascades. And I still don't have a clue how I would do this with supporting all built-in surface shaders. Unity is sometimes just a black box to me and quite frankly, I don't understand these surfaces shaders at all.
     
  5. Ewanuk

    Ewanuk

    Joined:
    Jul 9, 2011
    Posts:
    257
    iko79, did you get any response from the developer?

    I'm looking that that asset store item myself, but I need to know more before I purchase, my questions are in line with yours