13.4 C
New York
Saturday, October 18, 2025

unity – Drawing textures to a RenderTexture + rotating in 90° intervals


For context: I’m presently engaged on a BepInEx Plugin for the Unity-based sport Hole Knight: Silksong. The purpose is to have the ability to exchange the bottom sport sprites with customized ones. The sport makes use of Sprite Atlases, and the one means I’ve gotten customized sprites to work is by changing your entire atlas texture. One other customized sprite mod does this too, however this requires customers to offer a whole modified atlas texture, moderately than particular person information for every sprite. The thought of my mod is to assemble the atlas at runtime, in order that customers will solely ever should cope with particular person sprite picture information.

The principle subject I’ve is efficiency. Some sprites should be rotated (completely both 90° clockwise or counter-clockwise) earlier than being assembled into the atlas texture, so I carried out a rotation technique utilizing the SetPixel() and GetPixel() strategies, however that is extremely gradual when coping with the hundreds of sprites the sport has.

My new method is to exchange the “vanilla” atlas texture with a RenderTexture my mod creates, and rendering the customized sprite textures onto it, since this must be a lot quicker than the CPU-based shenanigans I used to be coping with earlier than.

tl;dr – Given a goal RenderTexture, a smaller supply Texture, vacation spot pixel coordinates on the goal texture, in addition to details about whether or not the supply must be rotated 90° clockwise or counter-clockwise, how would I draw the supply texture onto the goal texture?

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles