Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Technique for blinking lights on a texture

Discussion in 'Scripting' started by ENNEMMEE, Jul 25, 2015.

  1. ENNEMMEE

    ENNEMMEE

    Joined:
    Apr 4, 2012
    Posts:
    32
    Not sure if "Scripting" is the right place for my question or if would be better placed into the "Graphics" forum.

    I want to have blinking lights on a space ship hull. Just like the position lights that airplanes have. Real lights would have too much of a performance impact and this doesn't really have to affect lighting in any way, so a cheaper approach would be nice. I know that there is a way by creating a shader that makes such lights blink using the time delta and a sin function on a color channel (mostly alpha channel) of a texture... i think it was a shader for pusalting shields or sth... that can surely be abused for my purpose i hope... I simply can not remember how this was done and I can't find anything here on the forums :-( (probably i'm searching for the wrong terms)
    The programming is not the problem but could anyone give me a hint that might enlighten me?
     
  2. gorbit99

    gorbit99

    Joined:
    Jul 14, 2015
    Posts:
    1,350
    Materials have an "emit" feature, you could change that via scripting, and mybe you coukd change the darkness of it too, it can give out a nice effect, and it's performance friendly too.
     
    Kiwasi likes this.
  3. Jamster

    Jamster

    Joined:
    Apr 28, 2012
    Posts:
    1,102
    Not sure about performance but I would use flashing halos, you get a nice glow to the lights as you would in clouds etc :)
     
  4. William_Lee_Sims

    William_Lee_Sims

    Joined:
    Oct 11, 2014
    Posts:
    40
    I second gorbit99's technique. Copy your ship's texture and make it black everywhere except your lights (which are white). In the Standard material you set the Emission texture to the black/white image and you can change it's brightness dynamically. I forget which values you have to change in the material (you might search around), but I think you can change the glow color with "_EmissionColor" and toggle it between black and white to get the blink.
     
    Kiwasi likes this.
  5. ENNEMMEE

    ENNEMMEE

    Joined:
    Apr 4, 2012
    Posts:
    32
    Thanks a lot for your answers, and yes - scripting is a good option. This morning I maybe found the other method I was intending to use. Based on those shield shaders from http://wiki.unity3d.com/index.php?title=Shield that use a time-based sine-value to modify the alpha-channel of a texture i might be able to reach my goal.

    Pseudo code:
    float t = abs(_SinTime); // values from 0 to +1
    float a = int(texture.Alpha / 255); // casting alpha/255 to an int results in values for 0 for anything <255 and 1 for alpha=255
    o.Alpha = a * int(t); // reducing t to being either 0 or 1;

    That way I might be able to create a shader-only solution without the need to script anything. As I'm currently working on a voxel-based game I don't want every single voxel to be scripted.
     
  6. vrod2000

    vrod2000

    Joined:
    May 28, 2020
    Posts:
    16
    what if this blinking light is within an asset bundle? I can make an emission blink via script fine in Unity, but one it is bundled and inserted into the game, it no longer works or gives very unwanted results.