Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //input.Int is the interpolated position in object space, as opposed to the clip space in SV_Position
- float3 pos = input.Int.xyz;
- //load normal map and calculate missing component
- float3 n;
- n.xz = (g_Normal.Sample(samAnisotropic, input.Tex).xy * 2 - 1);
- n.y = sqrt(1 - min(1.0f, n.x * n.x + n.z * n.z));
- n = normalize(n);
- //calculate slope and height for texture blending
- float slope = 1 - n.y;
- float height = (sqrt(max(0, pos.x * pos.x + pos.y * pos.y + pos.z * pos.z)) - g_TerrainScaling.x)/(g_TerrainScaling.y);
- //alphas for texture blending
- float a1 = smoothstep(smoothstep(smoothstep(smoothstep(smoothstep(slope + 0.15f))))); //dirt
- float a2 = smoothstep(smoothstep(smoothstep(smoothstep(height + 0.1f)))); //rock
- float a3 = smoothstep(smoothstep(smoothstep(smoothstep(smoothstep(smoothstep(height - 0.1f)))))); //snow
- float a4 = smoothstep(smoothstep(abs(pos.y/g_TerrainScaling.x) + 0.45f)); //desert
- //load different textures
- float3 grass = t_Grass.Sample(samAnisotropic, tex * 50).xyz;
- float3 dirt = t_Dirt.Sample(samAnisotropic, tex * 50).xyz;
- float3 rock = t_Rock.Sample(samAnisotropic, tex * 50).xyz;
- float3 sand = t_Sand.Sample(samAnisotropic, tex * 50).xyz;
- float3 snow = t_Snow.Sample(samAnisotropic, tex * 50).xyz;
- float3 water = t_Water.Sample(samAnisotropic, tex * 25).xyz;
- d = (((grass * (1 - a1) + a1 * dirt) * (a4) + (1 - a4) * sand) * (1 - a2) + a2 * rock) * (1 - a3) + a3 * snow; //(1 - a3) * ((1 - a2) * ((1 - a1) * grass + dirt * a1) + snow * a2) + rock * a3;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement