Optimizing mirrored texturing?

Hello everyone!

Currently, I am working on some textures that are being mirrored.
Since I may be using those excessively, I am thinking about optimizing them.
When I take a look at those, I realize 3/4 of those textures’ information seems somewhat obsolete.

image01:

I could just be using 1/4 of the resolution, mirroring it on both x and y to get the full texture information, which would save me 75% of texture RAM, because I could just use this instead:

image02:
3100104--234022--image02.png

So now I was thinking about using a shader to mirror just 1/4 of those textures.
Will this be useful? Will I actually optimize by 75%?

I am thinking about the following issues:

  • Maybe the shader will cache the mirrored result anyway, resulting in the full resolution at runtime?
  • If that’s not the case and the shader keeps calculating the full resolution at runtime, will it fundamentally impact GPU performance?

I am trying to target low-end platforms (performance wise), including new 3DS.

Best wishes,
Shu

1 Like

It’s done to handle atlas with tiling textures, the idea is to pingpong the UV, basically it’s done in shader with:
1- scale the UV in shader to the number of atlassed texture
2- frac() to remove the integer (returning a number between 0 and 1) of the UV
3- floor() (I think?) to get the integer part, if it’s even, return 1-frac() else return frac

You would do the same except than for a single mirroring you multiply by 2

1 Like

In the wrap mode for the Texture, there is an option for Mirroring. Use this and the GPU will do the hard work for you.

3100604--234072--mirror.png

3 Likes

@neoshaman
@richardkettlewell
Thank you for your replies!

@richardkettlewell
Is this a 2017.1 feature?
I just checked a texture’s import settings, but I couldn’t find any options beside “Repeat” and “Clamp”.
So I went to Unity’s documentation and the options “Mirror” and “MirrorOnce” only seem to be included in 2017.1
( see Unity - Scripting API: TextureWrapMode for reference ), which still seems to be in beta phase.
Unfortunately, I am still using 5.4.2p2, which has been the last release that my projects survived. 5.5 and 5.6 both caused major issues.

Or should I be able to access those options in 5.4? I’d like to stay at 5.4 as long as possible.
Also, will this option have any significant impact on the GPU? Am I actually saving RAM like this or will there be a cache in full resolution anyway?
I am just asking, because right now I am mostly focused on creating assets, so I can’t really test in a full development context.

Ah, sorry, didn’t realise they were new options for 2017.1 :frowning:

Using only a quarter of the texture and doing the mirroring in the shader using floor/franc etc. will reduce the texture memory cost of your shader. It will increase the math cost. On some mobile platforms, the uv maths will cause dependent texture reads, which is another potential slowdown.

So, the answer of which is better is “it depends”. Best to profile where you can. Or at least look at your entire shader and, of it has lots of other bug texture reads, or lots of maths, maybe you can make an educated guess, at least as a starting point.

One thing is certain: if you use a texture that is 4x bigger, to do mirroring in your artwork, it will have 4x the memory cost.

1 Like

IIRC mirrored geo should be the better option – 3d has been doing this with characters since inception.

2 Likes

@richardkettlewell
I see! Thanks for the clarification! That’s helpful! I guess I will just have to test on device then.
The thing is, I have just become somewhat concerned about graphics size after reading about new 3DS VRAM limit of 10 MB ( New Nintendo 3DS - Wikipedia ).
Maybe you also know about this?:
Can textures be stored in the 256 MB RAM total? Or is RAM used for textures limited to VRAM (10 MB)? If 192 MB (256MB - RAM used by OS) can be accessed, it would be useful to know.

@Torbach78
I thought about using some more polygons, too: Just mirroring the UVs of the polygons. Unfortunately, this will result in a high poly count if I want to repeat the texture a lot.

Oh well, right now I will just work on 1/4 textures. Later on, I can still mirror them in the image files if I need to.

You can also speed up my method by using a integer mod 2 * 1 instead of a if

It’s used in many 3ds game if you look carefully too lol

2 Likes

@neoshaman
Thanks for your answer! I don’t really know if I can reproduce this, because I am using Shader Forge for custom shaders, but I will take a look at it!