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

UV Light Reveal Shader

Discussion in 'Shaders' started by Mokzen, Dec 20, 2021.

  1. Mokzen

    Mokzen

    Joined:
    Oct 10, 2016
    Posts:
    102
    Hi guys.

    So, I'm trying to reveal a texture on a plane only if a UV flashlight is shining upon it.

    I stumbled upon the following shader:

    Code (CSharp):
    1. Shader "Lighting Only" {
    2.     Properties {
    3.         _Color ("Main Color", Color) = (1,1,1,1)
    4.         _MainTex ("Base (RGB)", 2D) = "white" {}
    5.     }
    6.  
    7.     SubShader {
    8.         Blend SrcAlpha One
    9.         ZWrite Off
    10.         Tags {Queue = Transparent}
    11.         ColorMask RGB
    12.         // Vertex lights
    13.         Pass {
    14.             Tags {"LightMode" = "Vertex"}
    15.             Lighting On
    16.             Material {
    17.                 Diffuse [_Color]
    18.             }
    19.             SetTexture [_MainTex] {
    20.                 constantColor [_Color]
    21.                 Combine texture * primary DOUBLE, texture * constant
    22.             }
    23.         }
    24.     }
    25.  
    26.     Fallback "VertexLit", 2
    27.  
    28. }
    This works for spotlights shining a white light, but it does not work when I turn the flashlight to a purple color.

    I admit, I do not have any experience coding shaders, but I don't see any handles to tweak a setting related to my issue.

    Would any of you know of a quick fix for this, or would it require significant work, keeping my inexperience in mind?

    Thanks, and happy holidays! =)
     
  2. bauyrsaq

    bauyrsaq

    Joined:
    Jul 12, 2022
    Posts:
    3
    Hey, did you fixed it?
     
  3. DEEnvironment

    DEEnvironment

    Joined:
    Dec 30, 2018
    Posts:
    437
    Hello

    UV light reveal shader can be made in amplify editor.

    the idea is you have a “UV Filtered Color” that is the color you set your light and when shine on it gets revealed. you should also consider

    Threshold Reveal Color
    this is a float used to make fine adjustments for the intensity from your additional light

    Threshold Reveal Color Temp
    this is one of the trickier parts that in Unity is not well documented. Lights have a Temperature value that runs in a different way however still contributes to the light color. This Light Temperature also currently does not get included within Light layers. One way to work around this is to filter thru blackbody http://www.vendian.org/mncharity/dir3/blackbody/
    the radiation ranges from 7800-40000 should let you deal with filtering white light more easy.

    If you’re working in URP, also consider Main Light Influence completely off. Note this is not necessary in BIRP built in pipelines.

    upload_2023-1-14_21-57-5.png upload_2023-1-14_21-57-57.png
     
  4. DEEnvironment

    DEEnvironment

    Joined:
    Dec 30, 2018
    Posts:
    437
    Note amplify also has some simple shader examples for UV revel in built-in pipeline to help you get started.

    if you’re looking to skip the learning process and just wish to have a full working set my asset called “DE Environment” has a full set of them included also in URP 10x 12x and 14x forward+.. all shader functions are included

    https://assetstore.unity.com/packages/vfx/shaders/de-environment-183775#reviews

    upload_2023-1-14_22-7-43.png