- Home /
why does this custom shader not work?
i found this shader on a very old post and it was the thing i just needed, sadly i cant get it to work and i dont know why.
Shader "Global-Mapper" {
Properties{
_PeakColor("PeakColor", Color) = (0.8,0.9,0.9,1)
_PeakLevel("PeakLevel", Float) = 300
_Level3Color("Level3Color", Color) = (0.75,0.53,0,1)
_Level3("Level3", Float) = 200
_Level2Color("Level2Color", Color) = (0.69,0.63,0.31,1)
_Level2("Level2", Float) = 100
_Level1Color("Level1Color", Color) = (0.65,0.86,0.63,1)
_WaterLevel("WaterLevel", Float) = 0
_WaterColor("WaterColor", Color) = (0.37,0.78,0.92,1)
_Slope("Slope Fader", Range(0,1)) = 0
}
SubShader{
Tags{ "RenderType" = "Opaque" }
Fog{ Mode Off }
Tags{ "LightMode" = "Always" }
CGPROGRAM
#pragma surface surf Lambert vertex:vert
struct Input {
float3 customColor;
float3 worldPos;
};
void vert(inout appdata_full v, out Input o) {
UNITY_INITIALIZE_OUTPUT(Input, o);
o.customColor = abs(v.normal.y);
}
float _PeakLevel;
float4 _PeakColor;
float _Level3;
float4 _Level3Color;
float _Level2;
float4 _Level2Color;
float _Level1;
float4 _Level1Color;
float _Slope;
float _WaterLevel;
float4 _WaterColor;
void surf(Input IN, inout SurfaceOutput o) {
if (IN.worldPos.y >= _PeakLevel)
o.Albedo = _PeakColor;
if (IN.worldPos.y <= _PeakLevel)
o.Albedo = lerp(_Level3Color, _PeakColor, (IN.worldPos.y - _Level3) / (_PeakLevel - _Level3));
if (IN.worldPos.y <= _Level3)
o.Albedo = lerp(_Level2Color, _Level3Color, (IN.worldPos.y - _Level2) / (_Level3 - _Level2));
if (IN.worldPos.y <= _Level2)
o.Albedo = lerp(_Level1Color, _Level2Color, (IN.worldPos.y - _WaterLevel) / (_Level2 - _WaterLevel));
if (IN.worldPos.y <= _WaterLevel)
o.Albedo = _WaterColor;
o.Albedo *= saturate(IN.customColor + _Slope);
}
ENDCG
}
Fallback "Diffuse"
}
i hope that some1 can help me with this
What's it supposed to do??
Check out this awesome WikiBook. Work through it (its quite straightforward) and by Chapter 2 you will have a good understanding of debugging shaders.
https://en.wikibooks.org/wiki/Cg_Program$$anonymous$$g/Unity
its supposed to change collor depending on the y value for a terrain. like high thing become white and low things become green and lower is green for something like a beach
So if I put this on a cube it should change colour based on the height of the terrain underneath it?
The first part of debugging a shader is finding out why its black and making it be anything other than black; to get you back in to the working range.
Some changes to shaders in Unity 5 broke old shaders, like some automatic 2x light intensity that used to be applied is not there anymore (or something to that effect).
"cant get it to work" tells us nothing about your problem. Also like meat5000 said, it would make sense to actually tell us what the shader is supposed to do (which you did now in a comment but that information should be in the question).
Also you should describe what happens ins$$anonymous$$d and how your actual setup looks like. On what kind of object do you use that shader? Are you sure you set your levels correctly and the object is placed at the right "y" value?
Answer by TheMagican2 · Feb 17, 2016 at 03:54 PM
thank you so much, it was indeed the lighting. i removed
Tags{ "LightMode" = "Always" }
and now its fixed and i can go on improving this shader. ty so much
Ok I said the word "light" but I can't claim credit. You found this on your own; good job ;)
i accepted the answer for you so you got some rep (You dont get it for accepting your own).