#include "Terrain/ConstantBuffers.hlsl" #include "Terrain/ClipmapCommonPS.hlsl" #include "Terrain/ClipmapNormals.hlsl" #include "Terrain/ComputeColor.hlsl" #include "Shaders/RangeOut.hlsl" cbuffer CustomParameters { float4 GeLiveRange; float4 startColorHsv; float4 endColorHsv; float4 staticColor1; float4 staticRange1; float4 staticColor2; float4 staticRange2; float4 staticColor3; float4 staticRange3; float4 staticColor4; float4 staticRange4; float4 wrapMode; }; float sampleTexture(Texture2D source, float2 texCoords) { float2 dimensions; source.GetDimensions(dimensions.x, dimensions.y); float2 offset = float2(0.5 / dimensions.x, -0.5 / dimensions.y); float center = 0; float dist = 0; float h = sampleHeightNoData(source, texCoords, offset, center, dist); return h; } float computeTextureValue(VertexIn In) { int index = 0; float h1 = sampleTexture(imageryTexture[index], In.ImageryTexCoords[index].xy); float h2 = sampleTexture(coarseImageryTexture[index], In.ImageryTexCoords[index].zw); float h = lerp(h1, h2, In.BlendFactor); return h; } float4 hsv2rgb(float4 c) { float4 K = float4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); float3 p = abs(frac(c.xxx + K.xyz) * 6.0 - K.www); float3 rgb = c.z * lerp(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); return float4(rgb.xyz, c.w); } float customMod(float x, float y) { return x - y * floor(x / y); } float4 colorFromValue(float value) { float step = (value - GeLiveRange.x) / GeLiveRange.z; if (staticRange1.x == 1 && value >= staticRange1.y && value <= staticRange1.z) { return staticColor1; } if (staticRange2.x == 1 && value >= staticRange2.y && value <= staticRange2.z) { return staticColor2; } if (staticRange3.x == 1 && value >= staticRange3.y && value <= staticRange3.z) { return staticColor3; } if (staticRange4.x == 1 && value >= staticRange4.y && value <= staticRange4.z) { return staticColor4; } if (wrapMode.x == 0) { step = clamp(step, 0, 1); } else if (wrapMode.x == 1) { step = customMod(step, 1); } else if (wrapMode.x == 2 && (step < 0 || step > 1)) { discard; } float4 hsv = lerp(startColorHsv, endColorHsv, step); return hsv2rgb(hsv); } float4 computeCustomColorGeLive(VertexIn In) { float value; if (GeLiveRange.w == 1) { value = computeTextureValue(In); } else { value = In.WorldPosition.z; } float4 result = colorFromValue(value); return result; } void surfaceFunction(VertexIn In, out RangeOut Out) { float value; if (GeLiveRange.w == 0) { value = computeTextureValue(In); } else { value = In.WorldPosition.z; } Out.Attributes = float4(value, 0, -2, 1); } SurfaceOut surfaceFunction(in VertexIn In) { testClipping(In); color = computeCustomColorGeLive(In); SurfaceOut Out = (SurfaceOut)0; Out.Color = color; float3 n = normalize(mul(computeNormal(In, 1), (float3x3)viewMatrix)); if (!isfinite(n.z)) { Out.Normal = normalize(mul(float3(0, 0, 1), (float3x3)viewMatrix)); } else { Out.Normal = n; } Out.Specular = float3(0.0, 0.0, 0.0); Out.SpecularPower = 10; return Out; }