Created
February 23, 2014 17:16
-
-
Save keiranlovett/9174238 to your computer and use it in GitHub Desktop.
unity: iceberg shader
This file contains hidden or 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 "JaaVuori Gradiend Bumped" { | |
// JaaVuori is Iceberg in finnish | |
// | |
// I use finnish in variable, class etc names, maybe bad habit but it helps me to find my "own" code and stuff faster. | |
// | |
Properties { | |
_BumpMap ("Bumpmap", 2D) = "bump" {} | |
_MainTex ("Texture", 2D) = "white" {} | |
// These variables are y levels and colors | |
// ----> Over water surfface, depth 1, depth 2, bottom. | |
_JaaMerenPaallaVari ("JaaMerenPaallaVari", Color) = (0.8,0.9,0.9,1) | |
_RantaViiva ("RantaViiva", Float) = 0 | |
_RantaViivaVari ("RantaViivaVari", Color) = (0.75,0.53,0,1) | |
_ValiSyvyys1 (" ValiSyvyys1 ", Float) = -1 | |
_ValiSyvyys1Vari ("ValiSyvyys1", Color) = (0.75,0.53,0,1) | |
_ValiSyvyys2 (" ValiSyvyys2 ", Float) = -1 | |
_ValiSyvyys2Vari ("ValiSyvyys2", Color) = (0.75,0.53,0,1) | |
_Pohja ("Pohja", Float) = -10 | |
} | |
SubShader { | |
Tags { "RenderType" = "Opaque" } | |
CGPROGRAM | |
#pragma surface surf Lambert | |
struct Input { | |
float3 customColor; | |
float3 worldPos; | |
float2 uv_MainTex; | |
float2 uv_BumpMap; | |
}; | |
sampler2D _BumpMap; | |
sampler2D _MainTex; | |
float _RantaViiva; | |
float4 _JaaMerenPaallaVari; | |
float _ValiSyvyys1; | |
float4 _ValiSyvyys1Vari; | |
float _ValiSyvyys2; | |
float4 _ValiSyvyys2Vari; | |
float4 _RantaViivaVari; | |
float _Pohja; | |
float4 _PohjaVari; | |
float _Level1; | |
float4 _Level1Color; | |
float _WaterLevel; | |
float4 _WaterColor; | |
void surf (Input IN, inout SurfaceOutput o) { | |
// I think this does extra work: | |
o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb; | |
if (IN.worldPos.y >= _RantaViiva) | |
o.Albedo = _JaaMerenPaallaVari; | |
if (IN.worldPos.y <= _RantaViiva) | |
o.Albedo = lerp(_RantaViivaVari, _JaaMerenPaallaVari, (IN.worldPos.y - _ValiSyvyys1)/(_RantaViiva - _ValiSyvyys1)); | |
if (IN.worldPos.y <= _ValiSyvyys1) | |
o.Albedo = lerp(_ValiSyvyys1Vari, _RantaViivaVari, (IN.worldPos.y - _ValiSyvyys2)/(_ValiSyvyys1 - _ValiSyvyys2)); | |
if (IN.worldPos.y <= _ValiSyvyys2) | |
o.Albedo = lerp(_ValiSyvyys2Vari, _ValiSyvyys1Vari, (IN.worldPos.y - _Pohja)/(_ValiSyvyys2 - _Pohja)); | |
o.Normal = UnpackNormal (tex2D (_BumpMap, IN.uv_BumpMap)); | |
} | |
ENDCG | |
} | |
Fallback "Diffuse" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://forum.unity3d.com/threads/201724-Ahoy-sir-A-boat-game-WIP/page2