English 中文(简体)
Is it possible to progressively alpha-blend between two textures in one location created with D3DXCreateTextureFromFileInMemoryEx?
原标题:
  • 时间:2009-11-09 17:43:43
  •  标签:
  • c++
  • directx

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.

最佳回答

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

问题回答

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.





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签