Hi, it's the third thread of the week that i post on the same subject, as you can see i'm a noo... new to the subject. I am making a terrain surface shader, everything works except one thing: shadow. I am displacing the vertices in the vertex shader and the problem is that the shadow of the terrain itself and other objects are being casted on the original shape. Accordig to a lot of threads this is fixed by adding "addshadows" to the #pragma line, wich i did. But it gives this weird ressault where the surface on wich the shadows re casted is the one of the terrain but scaled down to the original mesh(the bounds are larger than the terrain itself so i dont think this is the problem). Here is my code: Code (CSharp): Shader "Example/terrain3" { Properties { frequency ("frequency", Range(0, 0.3)) = 0.03 amplitude ("amplitude", Range (0, 50)) = 5 sLength("terrain side length", Range (10, 300)) = 30 sTex1 ("side Texture1", 2D) = "Default-checker" {} sHTex1 ("side height Texture1", 2D) = "defaulttexture" {} shW1 ("side height wheight1", Range (0, 1)) = 1 sTex2 ("side Texture2", 2D) = "defaulttexture" {} sHTex2 ("side height Texture2", 2D) = "defaulttexture" {} shW2 ("side height wheight2", Range (0, 1)) = 1 uTex1 ("upward Texture1", 2D) = "defaulttexture" {} uHTex1 ("upward height Texture1", 2D) = "defaulttexture" {} uhW1 ("upward height wheight1", Range (0, 1)) = 1 uTex2 ("upward Texture2", 2D) = "defaulttexture" {} uHTex2 ("upward height Texture2", 2D) = "defaulttexture" {} uhW2 ("upward height wheight2", Range (0, 1)) = 1 test("heightBias", Range (-1, 1)) = 0 dotS("dot sharpness", Range (1, 5)) = 2 } SubShader { Tags { "RenderType" = "Opaque" } CGPROGRAM #pragma surface surf Lambert vertex:vert addshadow float random (float2 uv) {return frac(sin(dot(uv,float2(12.9898,78.233))) * 43758.5453123);} float s(float t) {return 6 * pow(t, 5) - 15 * pow(t, 4) + 10 * pow(t, 3);} float lerp(float t, float a, float b) {return a + t * (b - a);} float4 lerp(float t, float4 a, float4 b) {return float4(lerp(t, a.x, b.x), lerp(t, a.y, b.y), lerp(t, a.z, b.z), lerp(t, a.w, b.w));} float slerp(float t, float a, float b) { return lerp(s(t), a, b); } float d(float t) { return 30 * pow(t, 4) - 60 * pow(t, 3) + 30 * pow (t, 2); } float D(float t, float a, float b, float amp, float f) { return (d(t) * (b - a) * amp) * f; } struct noiseI { float val; float3 normal; }; noiseI noise2D(float2 uv, float freq, float amp) { uv *= freq; float2 bottomLeft = floor(uv); float a = random(bottomLeft); float b = random(bottomLeft + float2(1, 0)); float d = random(bottomLeft + 1); float c = random(bottomLeft + float2(0, 1)); float2 pis = frac(uv);//Pos In Square float aD = D(pis.x, a, b, amp, freq); float bD = D(pis.x, c, d, amp, freq); a = slerp(pis.x, a, b); b = slerp(pis.x, c, d); noiseI ni; ni.normal = normalize(float3(-slerp(pis.y, aD, bD),1, -D(pis.y, a, b, amp, freq))); ni.val = slerp(pis.y, a, b) * amp; return ni; } float frequency; float amplitude; float sLength; struct Input { float3 position; float3 normal; }; void vert (inout appdata_full v, out Input o) { v.vertex *= sLength; noiseI ni = noise2D(v.vertex.xz, abs(frequency), amplitude); v.vertex.y = ni.val; v.normal = ni.normal; o.position = v.vertex; o.normal = v.normal; } sampler2D uTex1; sampler2D uHTex1; float uhW1; float4 uTex1_ST; sampler2D uTex2; sampler2D uHTex2; float uhW2; float4 uTex2_ST; sampler2D sTex1; sampler2D sHTex1; float shW1; float4 sTex1_ST; sampler2D sTex2; sampler2D sHTex2; float shW2; float4 sTex2_ST; float test; float dotS; float sharpS(float t, int sharpness) { while(sharpness-- > 1) t = s(t); return t; } float4 blend(float4 s1, float w1, float4 s2, float w2) {return lerp(sharpS(0.5+(w2-w1)/2, 7), s1, s2);} float4 blendS(float4 s1, float w1, float4 s2, float w2, int sharpness) {return lerp(sharpS(0.5+(w2-w1)/2, sharpness), s1, s2);} float4 samp(float2 uv, sampler2D tex, float4 trans) {return tex2D(tex, trans.zw + uv/trans.xy);} float4 sampleFromSides(float3 pos, sampler2D tex, float4 trans , float3 normal) { normal = abs(normal); float4 front = samp(pos.xy, tex, trans); float4 right = samp(pos.zy, tex, trans); float w1 = dot(normal, float3(0, 0, 1)); float w2 = dot(normal, float3(1, 0, 0)); return blendS(front, w1, right, w2, 4); } void surf (Input i, inout SurfaceOutput o) { float3 pos = i.position; float heightWeight = clamp(pos.y / amplitude + test, 0, 1); //upward float4 s1 = samp(pos.xz, uTex1, uTex1_ST); float h1 = samp(pos.xz, uHTex1, uTex1_ST); float w1 = h1 * uhW1 * (1 - heightWeight); float4 s2 = samp(pos.xz, uTex2, uTex2_ST); float h2 = samp(pos.xz, uHTex2, uTex2_ST); float w2 = h2 * uhW2 * heightWeight; s1 = blendS(s1, w1, s2, w2, 6); h1 = blendS(h1, w1, h2, w2, 6); //sides s2 = sampleFromSides(pos, sTex1, sTex1_ST, i.normal); h2 = sampleFromSides(pos, sHTex1, sTex1_ST, i.normal); w1 = h2 * shW1 * (1 - heightWeight); float4 s3 = sampleFromSides(pos, sTex2, sTex2_ST, i.normal); float h3 = sampleFromSides(pos, sHTex2, sTex2_ST, i.normal); w2 = h3 * shW2 * heightWeight; s2 = blend(s2, w1, s3, w2); h2 = blend(h2, w1, h3, w2); //return s2; float dotUP = dot(float3(0, 1, 0), i.normal); o.Albedo = blendS(s1, h1 * pow(dotUP, dotS), s2, h2 * (1 - pow(dotUP, dotS)), 5); } ENDCG } Fallback "Diffuse" } //struct SurfaceOutput //{ // fixed3 Albedo; // diffuse color // fixed3 Normal; // tangent space normal, if written // fixed3 Emission; // half Specular; // specular power in 0..1 range // fixed Gloss; // specular intensity // fixed Alpha; // alpha for transparencies //}; Thanks in advance for your help!