Jump to content
  • Advertisement
Sign in to follow this  
glHomeless

OpenGL using effectively multiple textures

This topic is 4229 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, I have a simple problem in opengl. I have got 15 textures which show the motion of clouds. But I don't want to show the textures one after another. I want to merge from one texture to another. That means: I show cloud texture 1. After a few seconds I make that texture a little bit transparent to show in background the cloud texture 2. However this should not take a lot of CPU. How should I program that. I don't want to calculate the new cloud texture and then rendering it. It takes too much time. Could anyone help?

Share this post


Link to post
Share on other sites
Advertisement
I'd suggest using a fragment program which takes two textures and does a simple colour interpolation between them by some value specified in a uniform variable. The three major shading languages have a lerp function. All you have to do every frame is bind the current texture and the next one, set the interpolation value uniform variable, and then render the geometry with the fragment program. Simply vary the interpolation value you specify by time every frame. Should be fairly trivial. Some sample Cg code below...


float gfInterpolation
<
string UIWidget = "slider";
string UIName = "Fade Interpolation";
float UIMin = 0.0;
float UIMax = 1.0;
float UIStep = 0.01;
> = 0.0; // Default - no interpolation

float4
InterpolateBetweenTwoTexturesFP( QuadVertexOutput IN ) : COLOR
{
float4 lCurrTexColour = tex2D( FirstSampler, IN.UV );
float4 lNextTexColour = tex2D( SecondSampler, IN.UV );

return lerp( lCurrTexColour, lNextTexColour , gfInterpolation );
}


To perhaps speed things up, you could stitch all of your textures together into a large texture (I assume that your small textures are power-of-two, which means that making them into a larger texture is trivial), and specifying an additional integer uniform variable, an offset, to a vertex program. If you send the texture coordinates for the texture in the top-right corner, you can use the offset in the vertex program to calculate the texture coordinates for the current texture and the next one. You might need a high Cg profile or GLSL to do this, though. And there'd be a fair bit of branching...maybe it's not such a good idea after all :)

Share this post


Link to post
Share on other sites
Thanks. I will use GLSL to implement what you said. That was my idea too. I just wanted to avoid GLSL.
Thanks again. bye

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!