Last active
July 11, 2022 07:04
-
-
Save thallippoli/10549185 to your computer and use it in GitHub Desktop.
Pulsing shader in Unity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Shader "Custom/Glow" { | |
Properties { | |
_MainTex ("Base (RGB)", 2D) = "white" {} | |
_GlowColor ("Glow Color", Color ) = ( 1.0, 1.0, 1.0, 1.0 ) | |
_Frequency( "Glow Frequency", Float ) = 1.0 | |
_MinPulseVal( "Minimum Glow Multiplier", Range( 0, 1 ) ) = 0.5 | |
} | |
SubShader { | |
Tags { "RenderType"="Opaque" } | |
LOD 200 | |
CGPROGRAM | |
#pragma surface surf Lambert | |
sampler2D _MainTex; | |
fixed4 _GlowColor; | |
half _Frequency; | |
half _MinPulseVal; | |
struct Input { | |
float2 uv_MainTex; | |
}; | |
void surf (Input IN, inout SurfaceOutput o) | |
{ | |
half4 c = tex2D (_MainTex, IN.uv_MainTex); | |
half posSin = 0.5 * sin( _Frequency * _Time.x ) + 0.5; | |
half pulseMultiplier = posSin * ( 1 - _MinPulseVal ) + _MinPulseVal; | |
o.Albedo = c.rgb * _GlowColor.rgb * pulseMultiplier; | |
o.Alpha = c.a; | |
} | |
ENDCG | |
} | |
FallBack "Diffuse" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
_Time.x should be _Time.y