user189320
user189320

Reputation:

Is it possible to progressively alpha-blend between two textures in one location created with D3DXCreateTextureFromFileInMemoryEx?

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.

Upvotes: 2

Views: 475

Answers (2)

tsalter
tsalter

Reputation: 287

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.

Upvotes: 1

Reed Copsey
Reed Copsey

Reputation: 564333

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.)

Upvotes: 2

Related Questions