In an FPS I am developing, I am procedurally altering the appearance of textures based on game play events, and would like to know if the way I have implemented this was a good idea.

Right now, on each frame, I am grabbing a pointer to the uncompressed image and writing to it using memset. It's pretty straightforward if I want to have game play events affect the texture's appearance, because all I have to do is tie whatever attribute I like from any game object into the function writing the image data. For example, using this I could get the player's x,y position and draw an x directly to a map texture as the player moves around.

Is there a better way to implement this functionality in general?

My first thought would be to use shaders instead, but I haven't been able to find anyone doing anything like this and I know almost nothing about shaders. I feel like I could be missing something obvious to someone.

I am trying to keep this question as engine-independent as possible, but if relevant, I am using Source Engine procedural materials.


Modifying textures on the CPU is usually very, very slow. What you'd prefer to do is use Render to Texture- you use data from your program in a shader to render to something that is not the screen (render target).

Taking your minimap example, drawing an X on the player is as simple as sending the map background texture, X texture, and the player position to the shader, and blending those two based on the player pos (anything outside where you mark the X is the minimap texture, anything inside is the X, alpha blended on top the map, if i understand the idea). Any parameters that you send to your function that changes the texture with memset you now send as a constant buffer to your shader.

This also works for other types of textures (like ones you map on say, a model, like a soldier) as you can render to texture the original texture with the additional things and then send the new texture as the one you map on the model.

I'm no expert on Source but this seems useful : https://developer.valvesoftware.com/wiki/Adding_a_Dynamic_Scope


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.