Sign in to follow this  

modifying texture color at runtime

This topic is 4818 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

Hi all, How to modify / change the color of texture at runtime? Is it done by looping through each pixel? Is this way not too slow? That's all. Thanks for your attention.

Share this post


Link to post
Share on other sites
I believe you can also do it by making a texture stage that modulates texture colour with a constant. I don't have the DirectX help handy because I'm not at home - so you'll have to find the commands for yourself.

Share this post


Link to post
Share on other sites
Thanks for the replies.

My specific question is this: How to change a particular color into another color? For example, how to change all blue pixels into red?

What texture operation I should perform?

Thanks a lot.

Share this post


Link to post
Share on other sites
>> Is it done by looping through each pixel?

Does anybody know how to modify a single pixel in DirectX? Do I have to modify the texture memory directly in or is there a function to help me?

Share this post


Link to post
Share on other sites
Quote:
Original post by jammyt
>> Is it done by looping through each pixel?

Does anybody know how to modify a single pixel in DirectX? Do I have to modify the texture memory directly in or is there a function to help me?

Take a look at the D3DXFillTexture functions: D3DXFillTexture() takes a texture and a function pointer to a callback function which is called for every texel in the texture with the texture coordinates, the size of the texel and an arbitrary block of user data. You can write the texel as a float4 vector value and D3D handles all the format conversion for you. D3DXFillTextureTX() is similar only it lets you write the callback function in HLSL which is quite neat - this is also used in the Effects framework to let you procedurally generate textures from an HLSL function in the Effects file.

These functions aren't really intended to be used every frame - they're fine for initialising a texture but if you're wanting to modify a texture every frame you're probably better off just locking the texture and writing to it yourself.

Share this post


Link to post
Share on other sites

This topic is 4818 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