- Home /
Normal Extrusion with Vertex Modifier shader using a depthmap
I have a question about the Normal Extrusion with Vertex Modifier shader from unity's Surface Shader Examples.
Is it posible to use this shader but make the height of the vertices be based on a heightmap? and if so, how would this be done?!?
Shader "Example/Normal Extrusion" {
Properties {
_MainTex ("Texture", 2D) = "white" {}
_Amount ("Extrusion Amount", Range(-1,1)) = 0.5
}
SubShader {
Tags { "RenderType" = "Opaque" }
CGPROGRAM
#pragma surface surf Lambert vertex:vert
struct Input {
float2 uv_MainTex;
};
float _Amount;
void vert (inout appdata_full v) {
v.vertex.xyz += v.normal * _Amount;
}
sampler2D _MainTex;
void surf (Input IN, inout SurfaceOutput o) {
o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb;
}
ENDCG
}
Fallback "Diffuse"
}
Comment
Answer by sjhoey · Feb 17, 2014 at 03:21 PM
Try this:
void vert (inout appdata_full v) {
#if !defined(SHADER_API_OPENGL)
float4 tex = tex2Dlod(_HeightMap, float4(v.texcoord.xy,0,0));
v.vertex.z += tex.b;
#endif
}
It might not be the best option, but it worked for me.
Your answer

Follow this Question
Related Questions
Using displacementmap on-the-fly (shader or function)? 0 Answers
How to add "fat" feature to the Standard.shader? 1 Answer
How to apply specific texture for specific triangle in mesh based on height in shader? 0 Answers
Tessellation/displacement is transparent, shouldn't be 2 Answers
How to force the compilation of a shader in Unity? 5 Answers