// The 3D data
MyTexture2D<float> ShaderTextureFloat: register(t0);
// A simple Sampler
SamplerState Sampler : register(s0);
struct VertexShaderOutput
{
// The calculated position in the texture (0..1) space
float4 Position : SV_Position;
//The position of the pixel in X,Y integers
float2 TextureUV : TEXCOORD0;
};
float main(VertexShaderOutput input) : SV_Target
{
float2 pos = input.TextureUV;
// simplified Sobel filter
float x0 = ShaderTextureFloat.SampleLevel(Sampler, pos - ddx(pos), 0);
float x1 = ShaderTextureFloat.SampleLevel(Sampler, pos + ddx(pos), 0);
float y0 = ShaderTextureFloat.SampleLevel(Sampler, pos - ddy(pos), 0);
float y1 = ShaderTextureFloat.SampleLevel(Sampler, pos + ddy(pos), 0);
return sqrt((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0));
}