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.

Free nightvision shader for unity free

Discussion in 'Shaders' started by skatermichi98, May 28, 2012.

  1. skatermichi98

    skatermichi98

    Joined:
    Feb 5, 2012
    Posts:
    22
    Hi ,
    here is a free nightvision replacement shader for the free and pro version of unity. I just converted a shader from a website. Just attach this script to the main camera, and see the effect.

    Here's the script:

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class NightVision : MonoBehaviour
    6. {
    7.     public bool bright = true;
    8.     public float brightness = 2.0f;
    9.     public Shader nightvisionShader;
    10.    
    11.     public void OnEnable()
    12.     {
    13.         nightvisionShader = Shader.Find( "UnityFree/NightVision" );
    14.     }
    15.    
    16.     public void OnPreCull()
    17.     {
    18.         if( bright )
    19.         {
    20.             Shader.SetGlobalFloat("_Brightness", brightness );
    21.             Shader.SetGlobalFloat("_Bright", 1.0f );
    22.         }
    23.         else
    24.         {
    25.             Shader.SetGlobalFloat("_Bright", 0.0f );
    26.         }
    27.        
    28.         if( nightvisionShader )
    29.             transform.camera.SetReplacementShader( nightvisionShader , null );
    30.     }
    31. }
    32.  
    And here is the shader:

    Code (csharp):
    1.  
    2. Shader "UnityFree/NightVision" {
    3.     Properties {
    4.         _MainTex ("Base (RGB)", 2D) = "white" {}
    5.         _Brightness ("Brightness Amount", Float ) = 2.0
    6.         _Bright ("Bright Areas", Float ) = 1.0
    7.     }
    8.     SubShader {
    9.         Pass {
    10.            
    11.             CGPROGRAM
    12.             #pragma vertex vert_img
    13.             #pragma fragment frag
    14.             #pragma fragmentoption ARB_precision_hint_fastest
    15.             #include "UnityCG.cginc"
    16.  
    17.             uniform sampler2D _MainTex;
    18.             uniform float _Brightness;
    19.             uniform float _Bright;
    20.                    
    21.             half4 frag (v2f_img i) : COLOR {
    22.                 half4 tex = tex2D( _MainTex, i.uv );
    23.                
    24.                 // greyscale the pixel color values
    25.                 half4 grey = dot( half3( 0.222, 0.707, 0.071 ), tex );
    26.                
    27.                 if(_Bright == 1.0 ) {
    28.                     // white out bright spots
    29.                     if( grey.x > 0.4 )
    30.                         grey *= _Brightness;
    31.                 }
    32.                
    33.                 // boost the green channel     
    34.                 grey.y *= 2.5;
    35.                
    36.                 return grey;        
    37.             }
    38.         ENDCG
    39.         }
    40.     }
    41. }
    42.  
    If anybody knows why the skybox disappears , please tell me:)
     
    Last edited: Oct 3, 2012
  2. MerlinWoffSwiss

    MerlinWoffSwiss

    Joined:
    Jul 20, 2013
    Posts:
    2
    Hi
    Very cool shader!! Thanks a lot, but I have a problem with the Transparent Textures, witch I use in my Game. The are with this Shader no longer transparent.

    Do you know a solution

    Merlin Woff
     
  3. Drakhex666

    Drakhex666

    Joined:
    Sep 4, 2014
    Posts:
    2
    Is there a mobile version?