├── .gitignore ├── HeightColorBlendRelative.shader ├── HeightColorGradientNoLighting.shader ├── HeightColorGradientReflective.shader ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | [Ll]ibrary/ 2 | [Tt]emp/ 3 | [Oo]bj/ 4 | [Bb]uild/ 5 | [Bb]uilds/ 6 | Assets/AssetStoreTools* 7 | 8 | # Visual Studio cache directory 9 | .vs/ 10 | 11 | # Autogenerated VS/MD/Consulo solution and project files 12 | ExportedObj/ 13 | .consulo/ 14 | *.csproj 15 | *.unityproj 16 | *.sln 17 | *.suo 18 | *.tmp 19 | *.user 20 | *.userprefs 21 | *.pidb 22 | *.booproj 23 | *.svd 24 | *.pdb 25 | *.opendb 26 | 27 | # Unity3D generated meta files 28 | *.pidb.meta 29 | *.pdb.meta 30 | 31 | # Unity3D Generated File On Crash Reports 32 | sysinfo.txt 33 | 34 | # Builds 35 | *.apk 36 | *.unitypackage 37 | -------------------------------------------------------------------------------- /HeightColorBlendRelative.shader: -------------------------------------------------------------------------------- 1 | // HeightColorGradient by @Doomlaser 2 | // Set two colors to blend, min and max distance define the bottom and top Y values between which the colors will blend 3 | // Created by Mark Johns - https://twitter.com/Doomlaser 4 | Shader "Custom/HeightColorBlendRelative" 5 | { 6 | Properties 7 | { 8 | _Color ("Color", Color) = (1,1,1,1) 9 | _MaxColor ("Color in Maxmal", Color) = (0, 0, 0, 0) 10 | _MinDistance ("Min Distance", Float) = 100 11 | _MaxDistance ("Max Distance", Float) = 1000 12 | _MainTex ("Albedo (RGB)", 2D) = "white" {} 13 | _Glossiness ("Smoothness", Range(0,1)) = 0.5 14 | _Metallic ("Metallic", Range(0,1)) = 0.0 15 | } 16 | SubShader 17 | { 18 | Tags { "RenderType"="Opaque" } 19 | LOD 200 20 | 21 | CGPROGRAM 22 | // Physically based Standard lighting model, and enable shadows on all light types 23 | #pragma surface surf Standard fullforwardshadows 24 | 25 | // Use shader model 3.0 target, to get nicer looking lighting 26 | #pragma target 3.0 27 | 28 | sampler2D _MainTex; 29 | 30 | struct Input 31 | { 32 | float2 uv_MainTex; 33 | float3 worldPos; 34 | float4 pos : POSITION; 35 | float3 screenPos; 36 | float4 color : COLOR; 37 | }; 38 | 39 | half _Glossiness; 40 | half _Metallic; 41 | float _MaxDistance; 42 | float _MinDistance; 43 | fixed4 _Color; 44 | float4 _MaxColor; 45 | 46 | // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader. 47 | // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing. 48 | // #pragma instancing_options assumeuniformscaling 49 | UNITY_INSTANCING_BUFFER_START(Props) 50 | // put more per-instance properties here 51 | UNITY_INSTANCING_BUFFER_END(Props) 52 | 53 | void surf (Input IN, inout SurfaceOutputStandard o) 54 | { 55 | // float3 localPos = IN.worldPos - mul(unity_ObjectToWorld, float4(0,0,0,1)).xyz; 56 | float3 localPos = mul(unity_WorldToObject, float4(IN.worldPos,1)).xyz; 57 | half4 dist = localPos.y; 58 | 59 | half4 weight = (dist - _MinDistance) / (_MaxDistance - _MinDistance); 60 | half4 distanceColor = lerp(_Color, _MaxColor, weight); 61 | 62 | // Albedo comes from a texture tinted by color 63 | fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color; 64 | o.Albedo = IN.color.rgb * distanceColor.rgb ; 65 | // Metallic and smoothness come from slider variables 66 | o.Metallic = _Metallic; 67 | o.Smoothness = _Glossiness; 68 | o.Alpha = c.a; 69 | } 70 | ENDCG 71 | } 72 | FallBack "Diffuse" 73 | } 74 | -------------------------------------------------------------------------------- /HeightColorGradientNoLighting.shader: -------------------------------------------------------------------------------- 1 | // HeightColorGradient by Mark Johns - @Doomlaser - https://twitter.com/Doomlaser 2 | // Set two colors to blend, min and max distance define the bottom and top Y values between which the colors will blend 3 | Shader "Custom/HeightColorGradientNoLighting" { 4 | Properties { 5 | _Color ("Color", Color) = (1, 1, 1, 1) 6 | _MaxColor ("Color in Maxmal", Color) = (0, 0, 0, 0) 7 | _MinDistance ("Min Distance", Float) = 100 8 | _MaxDistance ("Max Distance", Float) = 1000 9 | } 10 | SubShader { 11 | Tags { "RenderType"="Opaque" } 12 | 13 | 14 | Zwrite On 15 | 16 | CGPROGRAM 17 | 18 | #pragma surface surf NoLighting 19 | 20 | struct Input { 21 | float2 uv_MainTex; 22 | float3 worldPos; 23 | float3 screenPos; 24 | float4 color : COLOR; 25 | }; 26 | 27 | float _MaxDistance; 28 | float _MinDistance; 29 | float4 _Color; 30 | float4 _MaxColor; 31 | 32 | void surf (Input IN, inout SurfaceOutput o) { 33 | 34 | half4 dist = IN.worldPos.y; 35 | half4 weight = (dist - _MinDistance) / (_MaxDistance - _MinDistance); 36 | half4 distanceColor = lerp(_Color, _MaxColor, weight); 37 | 38 | o.Albedo = IN.color.rgb * distanceColor.rgb ; 39 | 40 | 41 | // o.Alpha = IN.color.a * distanceColor.a; 42 | o.Alpha = 1; 43 | } 44 | fixed4 LightingNoLighting(SurfaceOutput s, fixed3 lightDir, fixed atten) 45 | { 46 | fixed4 c; 47 | c.rgb = s.Albedo; 48 | c.a = s.Alpha; 49 | return c; 50 | } 51 | ENDCG 52 | } 53 | FallBack "Diffuse" 54 | } 55 | -------------------------------------------------------------------------------- /HeightColorGradientReflective.shader: -------------------------------------------------------------------------------- 1 | // HeightColorGradient by Mark Johns - https://twitter.com/Doomlaser 2 | // Set two colors to blend, min and max distance define the bottom and top Y values between which the colors will blend 3 | Shader "Custom/HeightColorGradientReflective" 4 | { 5 | Properties 6 | { 7 | _Color ("Color", Color) = (1,1,1,1) 8 | _MaxColor ("Color in Maxmal", Color) = (0, 0, 0, 0) 9 | _MinDistance ("Min Distance", Float) = 100 10 | _MaxDistance ("Max Distance", Float) = 1000 11 | _MainTex ("Albedo (RGB)", 2D) = "white" {} 12 | _Glossiness ("Smoothness", Range(0,1)) = 0.5 13 | _Metallic ("Metallic", Range(0,1)) = 0.0 14 | } 15 | SubShader 16 | { 17 | Tags { "RenderType"="Opaque" } 18 | LOD 200 19 | 20 | CGPROGRAM 21 | // Physically based Standard lighting model, and enable shadows on all light types 22 | #pragma surface surf Standard fullforwardshadows 23 | 24 | // Use shader model 3.0 target, to get nicer looking lighting 25 | #pragma target 3.0 26 | 27 | sampler2D _MainTex; 28 | 29 | struct Input 30 | { 31 | float2 uv_MainTex; 32 | float3 worldPos; 33 | float3 screenPos; 34 | float4 color : COLOR; 35 | }; 36 | 37 | half _Glossiness; 38 | half _Metallic; 39 | float _MaxDistance; 40 | float _MinDistance; 41 | fixed4 _Color; 42 | float4 _MaxColor; 43 | 44 | // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader. 45 | // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing. 46 | // #pragma instancing_options assumeuniformscaling 47 | UNITY_INSTANCING_BUFFER_START(Props) 48 | // put more per-instance properties here 49 | UNITY_INSTANCING_BUFFER_END(Props) 50 | 51 | void surf (Input IN, inout SurfaceOutputStandard o) 52 | { 53 | half4 dist = IN.worldPos.y; 54 | half4 weight = (dist - _MinDistance) / (_MaxDistance - _MinDistance); 55 | half4 distanceColor = lerp(_Color, _MaxColor, weight); 56 | 57 | // Albedo comes from a texture tinted by color 58 | fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color; 59 | o.Albedo = IN.color.rgb * distanceColor.rgb ; 60 | // Metallic and smoothness come from slider variables 61 | o.Metallic = _Metallic; 62 | o.Smoothness = _Glossiness; 63 | o.Alpha = c.a; 64 | } 65 | ENDCG 66 | } 67 | FallBack "Diffuse" 68 | } 69 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Mark Johns 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Height-Based-Gradient-Color-Shaders-for-Unity 2 | Height Based 2 color gradient shaders for Unity 3 | 4 | Usage: Put these .shader files in your project's Assets/ directory and use them in Unity. 5 | Set two colors to blend, min and max distance define the bottom and top Y values between which the colors will blend 6 | 7 | ![image 1](https://i.imgur.com/v6rCs4c.png)![image 2](https://i.imgur.com/MxJc1Ir.png) ![image 3](https://i.imgur.com/ieYcuKK.png) 8 | 9 | [@Doomlaser](https://twitter.com/Doomlaser) 10 | --------------------------------------------------------------------------------