Also checked the MipMapLevel Solution, and even thought it worked, it had some minor seams between textures… AND ALSO it did not compile for ES2 , as a targeting mobile devices…
I used to struggle with this earlier but now that we are not limited to ~13 or so texture sheets I can’t really see a reason to do it this way anymore. May I ask why you’re not just setting sampler source of the texture 2d to shared instead?
Make your function output just UVs and then sample using a regular TextureSample node but set to “Derivative” mip mode. Then you need to plug in ddx, and ddy of UVs of the same scale but without the atlasing and the mips will be perfect.
If you need to sample the texture in your function, you need to also pass in ddx and ddy to the function using the ddx and ddy nodes. The reason being that ddx and ddy are actually exposed using macro’s with capital DDX,DDY, but due to the way the compiler parses custom nodes it does not seem to work with that either so the only thing I have seen that works is to use the nodes and pass them in.
I just re-read your post and node and it seems like the only thing you were doing is the gradient sample so you shouldn’t end up needing a custom node at all, so option #1 is your best bet.
Also note that even if you solve your mip issue you may see a seam because the texture filtering and mips will blend to the other textures. This too is solvable and I have some material code to do it, but you need to author the textures a certain way (you can use a material to convert them too). If you want to fix just mip0 then you need to have 2 extra pad pixels per cell, and then for each additional perfect mip you want,y you must double the pixels sacrificed.
For example, if you render 8 extra pixels (so 4 per side), that will get you 3 perfect mips which should be pretty good.