понедельник, 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? 

To get texture dimension in pixels you need to create your own custom node.


Add input node so, custom node will be able to recive a texture object as parameter. Rename it to GetTextureSize or whatever you like.


In the Code field paste following:


Use and do not forget to LEARN 







Комментариев нет:

Отправить комментарий