As you can see by the title of my question, I am very rookie in what regards messing with the fragment shader. I have experience using the geometry, vertex and calculate shader, though.
Still, what I am trying to is pretty basic: just to access specific textures within a texture atlas. As basic as such a task is, and as much as I search online, it is still unclear to me how to properly locate the texture within the texture atlas. For instance, assume we pass to the shader an atlas of size 256x128, composed by 4x2 textures of 64x64 pixels each, to be stored and sampled in the following variables:
Texture2D _SpriteTex;
SamplerState sampler_SpriteTex
How can I inform within the shader the specific part of _SpriteTex that I want to use for the current mesh?
Initially, I thought that it had to do with the following command in the fragment shader:
// Fragment Shader -----------------------------------------------
float4 frag(frag_input i) : COLOR
{
return _SpriteTex.Sample(sampler_SpriteTex, i.tex0);
}
But the problem is that i.tex0 is one float2 coordinate, making it impossible to specify where a texture within the atlas begins and ends.
Could anyone help out with such a basic misunderstanding? Thanks!