Blue channel for height in standard shader
Hello,
I want to make standard shader that for height requires information in B channel of texture. What I need to change in code to make this work? Or maybe someone could point me in some direction how to do it?
Sorry, I dont know anything about shader coding :/
Best.
Comment
Answer by BTCallahan · May 06, 2016 at 03:28 PM
@lordpx I'm assuming you're using a plane with several subdivisions (as opposed to a terrain object)? If that's the case then hopefully the following should help you out:
Shader "Custom/HeightMap" {
Properties {
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_HeightMapTex ("Height Map", 2D) = "white" {}
_HeightMapFactor ("Factor", Range(0.001,10)) = 1.0//optional, you may want more control over how much the texture influences the height
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Standard fullforwardshadows vertex:vert
#pragma target 3.0 //or whatever your target is
sampler2D _HeightMapTex;
sampler2D _Color;
fixed4 _Color;
float _HeightMapFactor;
struct Input {
float2 uv_MainTex;
};
void vert (inout appdata_full v) {
v.vertex.y += _HeightMapTex.b * _HeightMapFactor;
//alternatively: v.vertex.y = _HeightMapTex.b * _HeightMapFactor;
}
//After that just put in a standard surface shader
void surf (Input IN, inout SurfaceOutputStandard o) {
// Albedo comes from a texture tinted by color
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
}
ENDCG
}
FallBack "Diffuse"
}