Search Unity

Specular highlights with 2D Lights

Discussion in '2D' started by johanolofsson, Apr 23, 2020.

  1. johanolofsson

    johanolofsson

    Joined:
    Nov 21, 2018
    Posts:
    94
    Hi, I want to add specular highlights to my 2D game but there seems to be no obvious way of doing this using the current impl. of 2D lights (I'm using the 2020 beta version).

    I've successfully managed to implement emissive effects by making my own shader/material based on the the Sprite-Lit-Default shader. However, since specular highlights require the position of the light source this can't be done in this pass but rather in the actual lighting pass which is implemented in the Light2D shaders in the 2D package. I've managed to get a decent understanding of the implementation of the Renderer2D and it should be fairly simple to modify the Lighting shaders. (I guess I also need to add a pass which generates the specular input texture to the lighting pass). However I'm not that much of a fan of modifying the shaders in the 2D package, that will just make a mess whenever they are updated, but there seem to be no way of replacing them from the outside. I suppose I could create my own renderer deriving from the Renderer2D and just reuse and modify the current impl. But again that will not be fun when a new improved version arrives.

    Does anyone have any suggestions on how to go about it and if there are any plans on supporting specular highlights with shininess maps in the 2D shaders in the near future?
     
    Weeros, cassidyg, pry_bar and 2 others like this.
  2. Cambesa

    Cambesa

    Joined:
    Jun 6, 2011
    Posts:
    119
    I'm also having the same situation. My current idea is to pass a number of light positions relative to the texture in world space to the shader and use the cross product vs the normals and some mathematical calculations to create specular highlights on the main texture.
     
  3. oTaijjo

    oTaijjo

    Joined:
    Nov 3, 2019
    Posts:
    30
    Also struggling with this. Are there any working approaches to this or new ideas?
     
  4. Weeros

    Weeros

    Joined:
    Oct 5, 2018
    Posts:
    4
    I'm struggling with this as well. I've been looking for alternatives - I suppose before 2D lights were a thing, some games used the 3D lighting pipeline for similar effects (see e.g. this Gamasutra article for a well known example) - at some point I was thinking if perhaps either the regular shader graph or popular 3rd party shader graph (such as Amplify) could be used to build a more versatile 2D lighting approach that could utilize specular maps in addition to normal maps, but so far I haven't found anything usable, and I'm still very new to all this so couldn't even figure out how 3D lights would be used in 2D project. But maybe this will help someone few steps forward?