For our Map Grid shader, in the vertex shader we are sampling the Height/Normal from the DiffMap, as follows:
Texture2D tDiffMap : register(t0);
SamplerState sDiffMap : register(s0);
void VS(....)
{
....
float2 diffVal = Sample2DLod0(DiffMap, iTexCoord).rg;
// 'r' component is our "elevation value"
// 'g' component encodes our normal - used for crude shadowing
}
===
And it is working on Windows (haven’t tested Android/iOS mobile). In order to avoid ‘interpolation’ between adjacent pixel values, we offset our iTexCoord value with “half Pixel size” to guarantee we’re sampling in the exact center of each pixel - -and so there is no interpolation. This is a bit awkward, but works.
I have seen talk of a alternate method called “texelFetch” which may be more suited for the Vertex Shader, and grabbing pixel data without interpolation.
We need this to work on Windows, UWP, iOS, and Android alike. It’s OK if it only runs on newer mobile devices (2015 or newer).
My Questions are:
- Does our current method ‘Sample2DLod0’ work for our targeted platforms? (e.g. non-old mobile)
- Is the ‘texelFetch’ method a better choice? And if so, what are the benefits? (e.g. runs faster?)
I was seeing talk from 2013 about some mobile devices not supporting texture sampling from the Vertex Shader. I assume this is no longer an issue, yes?