So I've been looking all over the forums but this is a silent topic. Has anyone successfully created a displacement shader using a heightmap?? Seems pretty commonplace as far as shaders go.
Not commonplace in real time games. There's stuff on the asset store that can do this. Or you could write one and share it with the community.
http://unity3d.com/support/documentation/Components/SL-SurfaceShaderExamples.html Copy the shader that makes the bulgy soldier. Then change _Amount to be a value sampled from a texture. If you want tesselation you might be SOL though.
Hmm... im trying to get a hang on shaders but after checking what you just said I see i still don't get a few things... I mean how do i get the rbg or alpha from the texture there? Can't see a way to do it without writing a lot more stuff... could you (if it's not a bother) be more specific? this is the bulgy soldier shader section... void vert (inout appdata_full v) { v.vertex.xyz += v.normal * "how do i get the texture color here?"; }
Hmm... im trying to get a hang on shaders but after checking what you just said I see i still don't get a few things... I mean how do i easily get the rbg or alpha from the texture there? Can't see a way to do it without writing a lot more stuff... could you (if it's not a bother) be more specific? this is the bulgy soldier shader section... void vert (inout appdata_full v) { v.vertex.xyz += v.normal * "how do i get the texture color here?"; }
No it's not. The only decent uses are with conjunction with tesselation to say, add some detail to distant low poly mountains (BF3 does that I think). Otherwise I can't really think of any uses that will result in a visual improvement that will be worth the fps hit. Also, we can't use tesselation in unity because it's a DX10+ feature.
I really would like to know the same thing, but i keep getting referred to the " shader examples", but I can't really get the solution there either.
Here is how you get texture color (here just get the Red value) and apply it to the normal: Taken from this page on tesselation
Apologies for reviving an ancient thread, but it is the top Google result for "Unity mobile displacement" After following some points on this thread and then some I have ended up with the standard surface shader with : Albedo, Metallic, Occlusion, Emission, Smoothness aaaand Vertex displacement via a displacement map. This does not use tessellation. Code (CSharp): Shader "Mobile/Displacement" { Properties { [NoScaleOffset] _Albedo("Albedo (RGB), Alpha (A)", 2D) = "white" {} [NoScaleOffset] _Metallic("Metallic (R), Occlusion (G), Emission (B), Smoothness (A)", 2D) = "black" {} [NoScaleOffset] _Normal("Normal (RGB)", 2D) = "bump" {} [NoScaleOffset] _DispTex("Displacement Texture", 2D) = "white" {} _Amount("Displacement Amount", Range(0,3)) = 0.5 } SubShader { Tags { "Queue" = "Geometry" "RenderType" = "Opaque" } CGINCLUDE #define _GLOSSYENV 1 ENDCG CGPROGRAM #pragma target 3.0 #include "UnityPBSLighting.cginc" #pragma surface surf Standard vertex:vert #pragma exclude_renderers gles struct Input { float2 uv_Albedo; }; sampler2D _Albedo; sampler2D _Normal; sampler2D _Metallic; float _Amount; sampler2D _DispTex; void vert(inout appdata_full v) { v.vertex.xyz += v.normal * tex2Dlod(_DispTex, float4(v.texcoord.xy, 0, 0)).r * _Amount; } void surf(Input IN, inout SurfaceOutputStandard o) { fixed4 albedo = tex2D(_Albedo, IN.uv_Albedo); fixed4 metallic = tex2D(_Metallic, IN.uv_Albedo); fixed3 normal = UnpackScaleNormal(tex2D(_Normal, IN.uv_Albedo), 1); o.Albedo = albedo.rgb; o.Alpha = albedo.a; o.Normal = normal; o.Smoothness = metallic.a; o.Occlusion = metallic.g; o.Emission = metallic.b; o.Metallic = metallic.r; } ENDCG } FallBack "Diffuse" }