tags:

views:

147

answers:

2

I have two textures that are both .jpg, which represent a sky (one during the day, one at night). My question is, is it possible for me to fade one texture into the other? They are created with D3DXCreateTextureFromFileInMemoryEx. How can I perform this kind of transition? I don't wish to create two objects, just change the texture gradually.

To be clear, I wish to, over time, slowly blend from one texture to another (and back). However, I don't wish the fade to be going on at all times. Thanks in advance for any advice you can offer.

+2  A: 

You have quite a few options here -

You can use both textures with texture blending to transition from one texture to the other.

However, if you're doing this over a long period of time, you may want to precompute a third texture (the blended state) and just use it as a single texture. Occasionally, recompute the "new" state. This will potentially simplify your rendering, since you'd be using a single texture (that you change slowly over time) instead of having to always do multi-texturing just for this effect. (If you're not doing anything else but this with the objects you're texturing, and if the textures aren't huge, a simple 2 texture multi-texture is no big deal, though.)

Reed Copsey
how is texture blending done? do the files need to be .pngs for this to work, or do .jpgs suffice?
4501
The texture blending happens on the GPU - either through multitexturing or as part of your shader. The format is irrelevant at this point, since they're all just D3D textures.
Reed Copsey
Interesting. How can one perform this over a span of time to move slowly between two separate textures?
4501
You just increase the interpolation coefficient slowly over time. Do a search for *linear interpolation* and *rendering to texture buffers/render targets*.
Cecil Has a Name
A: 

Use a pixel shader.

float t : register(c0);

float4 t1 = tex2D(g_sampler1, texcoord);
float4 t2 = tex2D(g_sampler2, texcoord);

float4 result = lerp(t1, t2, t);

where you pass in t as your linear interpolation amount. t = 0.0 gives you the first texture, t = 1.0 gives you the second texture, and it interpolates linearly in-between.

Your file format then makes no difference, and it avoids a third texture being computed.

tsalter