Sign in to follow this  

How to paint to a texture

This topic is 3572 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a basic 3D room I can walk around in and I want the user to be able to click and draw on the wall, kind of like tagging. Right now I have fairly large walls that are texture mapped. I was thinking about painting the texture in very small quads and determining which quad the user had the mouse over and making that part of the texture a specific color. Unfortunately I don't know how to change the color of the original texture. Any suggestions?

Share this post


Link to post
Share on other sites
There's two main ways you can do that. You can either

A) Lock the texture so you can directly access the pixel data, then have your app fill in the colors manually. This can be slow, as locking the texture can stall the GPU and will cause data to be sent across the bus. Reading back data is generally even worse performance, which you need for alpha blending.

B) Make the textures render targets (or copy the texture to a render target texture) and then draw on that like you would the backbuffer. This is fast, and allows you to use the same techniques you use elsewhere (drawing primitives, pixel shaders, etc.).

EDIT: A third option would be not to modify the textures at all, but to instead use decals. A decal being a flat quad with a texture that you render directly "on top of" the surface you want modified.

Share this post


Link to post
Share on other sites
Here are a couple of easier (and faster) ways.

One possibility (your own "decal"):

Construct a separate small mesh of the size, shape and color you want for the mouseover. Draw it at the mouseover position. If necessary to avoid z-fighting, raise the mouseover mesh by a fraction of a unit, or disable depth testing for just this draw. (like a decal)

It's a bit more complicated but another option:

Construct the full texture you want but set 1 pixel (say at 0,0) to the color you want.

Construct the walls as small quads.

Detect the mouseover and set the texture coords to that quad to 0,0 to "texture map" the quad to the single pixel. You'll have to "remember" the original quad and tex coords to restore them when the mouse moves.

Share this post


Link to post
Share on other sites
Thanks for the ideas. The decal thing won't work for my project because the general idea is I have these rooms that the user can walk around in and pick up various spray paint cans. So basically we want to be able to allow the user to paint the walls with various colors however they feel like it, and we don't want them to be able to undo anything.

I know this probably isn't the most efficient matter but right now we have particle systems for the various nozzles of the spray cans that allow to user to specify "paint brushes" if you will. Some spread out more than others and what not. Right now we just made it so if the particle collides with the wall it "sticks" and gives us an OK effect but obviously if you spray for a long time we are talking about a ton of objects and that just doesn't work.



Share this post


Link to post
Share on other sites
If you can support multiple texture stages, how about maintaining a second alpha texture for each wall?

Initialize the second texture with alpha=0.

Draw to the second texture with a high-alpha paint :-) and alphablend it on top of the existing texture.

When a spray can is lit off, set the 2nd texture as a render target and draw particle sprites or colored lines at the appropriate locations.

If you can't support multiple texture stages, create a second wall vertex buffer, textured with the second texture and blend it over the first wall.

Share this post


Link to post
Share on other sites

This topic is 3572 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this