I’m pretty much a shader graph noob and managed to scrape together quite a sophisticated shader from a few different tutorials that allows me to automatically map a texture onto any object without needing any specific texture mapping from the model.
So far his worked great, however, when using a texture that has very distinct lines it starts looking quite pixelated/jagged when further away. I am assuming it is an anti-aliasing issue where I need to anti-alias the final mapped output texture prior to assigning it to the material’s base color. Can anyone give me pointers on how I could achieve that?
Below are a few reference pictures on how the shader works and of course the shader graph itself.
The “World Space” parent shader takes a simple diffuse texture, color and tiling parameter.
I just tried changing the AA settings for textures & objects. Any changes to any AA related settings have no impact on the material itself, only the rendered meshes seem to be rendered smoother. Great idea though!
Hi, the reason is that you are using “Sample Texture 2D LOD” instead of just “Sample Texture 2D” in “Sample Texture World Space”. “Sample Texture 2D LOD” only samples one mipmap level and because you did not provide any input to the “LOD” port, it will default to LOD0, which is the full-size texture, and never use any mipmaps, resulting in these aliasing issues, as the texture has to be resized on the fly by the GPU.
You’re right, I completely missed that. I assume that when I was recreating the shader I accidentally used the wrong node haha.
It turns out it was a combination of factors that lead to mip maps not working.
I was using the wrong node in the shader always forcing a mip map level to 0.
I was using a runtime-generated texture downloaded from my database. It turns out that directly using the texture you get when using DownloadHandlerTexture.GetContent(request) always returns a texture with no mip maps. I fixed this by adjusting my download method to the below:
public async Task<Texture2D> DownloadTextureFromUrl(string downloadUrl)
{
using (UnityWebRequest request = UnityWebRequestTexture.GetTexture(downloadUrl))
{
var asyncOperation = request.SendWebRequest();
while (!asyncOperation.isDone)
{
await Task.Yield();
}
if (request.result == UnityWebRequest.Result.Success)
{
var texture = DownloadHandlerTexture.GetContent(request);
//Generate mip map able texture from downloaded texture.
var mmTexture = new Texture2D(texture.width, texture.height, texture.format, true);
mmTexture.SetPixelData(texture.GetRawTextureData<byte>(), 0);
mmTexture.Apply(true, true);
Object.Destroy(texture);
return mmTexture;
}
Debug.LogError("Error downloading texture: " + request.error);
return null;
}
}