Texture manipulation while keeping the work on the vid card.

Alright. I’ve done quite a lot of work to get a decal baking system working. I’m currently almost there using Texture2Ds and get/setpixels. However, this is only a usable solution for decal textures no bigger than 64x64. Otherwise the .Apply just destroys performance.

I’ve been doing some reading about RenderTextures and direct GL calls. I’m kind of confused as to how to pull it off.

Here’s my current test class that uses Texture2Ds: [link broken??]

Would anyone be able to point me in the right direction and possibly provide some example code for obtaining the same result but with all legwork done on the video card?


EDIT:
Ok, so I’m almost there. Except the calculation for the pixel cords that was used in the old way, can’t be used in the new way. The decals appear in the wrong places.

Here’s the updated code: [link broken??]

The code at the bottom of the update is the new way, the commented block above it is the old. As you can see I’ve copied the pixel coordinate calculations…which are incorrect. What is the proper way to be calculating this?

Figured it out.

So basically you instantiate a new RenderTexture, blit the target texture to it, push a gl matrix, load a pixel matrix, draw the decal texture at the texture coord the ray hit, pop the gl matrix, and set the mainTexture of the target texture to the instantiated RenderTexture.

The position calculation issue I had was that I had the bottom and top of the pixel matrix reversed.