What does "Sampler Type"specifically do? In particular, this texture object will be an input to a custom expression, where it will be named “vert_mat_tex”, and will be sampled with:
float4 mat = Texture2DSample(vert_mat_tex, vert_mat_texSampler, float2(uv_index.x, uv_index.y));
What I need to know is how “Sampler Type” affects the input/output from Texture2DSample. Particulary, the differences between “Color”, “Linear Color”, and “Data”.
But, the only information is gives us is “Sampler Type: The type of data that will be output from the node.”, but never gives any explanation of the different types.
To give more context, I want to use Mat_texture as an array to store some per-vertex information. I have found a way to get the vertex ID closest to the pixel, and want to use the vertex ID to sample the Mat_texture using Texture2DSample. I’ve tried scaling the uv coords to sample the proper position (like by using uv.x * Mat_texture_size), but that doesn’t seem to be giving me the correct value back from the sample…
Color is for sRGB images like diffuse textures.
Linear color is for RGB 0-1 images, making them suitable for displacement maps, roughness maps, etc. If you are trying to encode data that is being retrieved, then you mainly need to make sure the space is linear and has sufficient bit depth for your purpose. Several sampler types may meet these requirements.
As far as storing per vertex data in a texture, a typical way is to have a second UV map where each vertex has a known coordinate. This way the image being sampled need only be as many pixels as verts, usually saving memory. Then the data is baked out / encoded in the texture in the same position as the corresponding vertex. Thus it can sample normally using the relevant UV and automatically retrieve the appropriate data.
You may also need to adjust settings related to filtering, compression and mipmapping to prevent various optimizations and features from altering your encoded data.
What specific features would I need to disable to keep the data from being altered? I create the UTexture directly from C++ and assign it to the parameter in the Dynamic material instance. So far, I have disabled compression and created the texture with
in my script, but how would I disable filtering and mip mapping? as for sampling the texture, right now I’m getting the vertex index, and scaling it by the size of the image to try to get the right element like so:
int mat_tex_width = <num verts>;
int triangle_index = ... ;
float4 mat_orig_v = Texture2DSample(..., ..., float2(triangle_index / (float)mat_tex_width, 0));
But it’s still acting strange, and I think it could be those other settings.
EDIT: After figuring out how to disable mipmaps, filtering, and compression, it still is still acting strangly, but not as strangly as before. I get correct values from the Texture2DSample, but in incorrect positions, so the uv float2(…) part doesn’t seem to behave in the way I would expect it to. (I am getting the correct triangle index, though)