понедельник, 18 июля 2022 г.

How to get texture size in Unreal Material Editor?


Let be a shader that wants texture dimensions, f.e to evaluate texture aspect. It's a common situation if the shader is going to render something in screenspace and you want to prevent stretching. Another common situation if it's necessary to process texture pixel by pixel. Or combine two different textures with various aspects. The texture coordinates are always in (0,1) so there no clue about texture aspect. Of course, you can pass dimensions as parametrs, but that sucks. Defenitely it should be something much simpler, but where?