Transition between two texture of skydome

Problems building or running the engine, queries about how to use features etc.
Post Reply
jasonchewy
Gnoblar
Posts: 8
Joined: Sat Feb 10, 2007 1:18 am

Transition between two texture of skydome

Post by jasonchewy » Sat Feb 10, 2007 1:24 am

I've seen this talked about alot, but have not found one with a way to do it.

I've read one where to make two skydomes and change its alphas to make it fade. How do I change the alpha for the skydome? I see no method to set any thing on the skydome..all I have is the setSkyDome(..), and the parameters are on/off, the texture, curvature and distance...nothing about alpha...am I just missing somewhere? also how do I make two skydomes? it seems like there's only one in a scene...

Second way I've read is to use something about a shader/fader thing. How would I actually use something like this and apply it to the skydome?

Thank You.
0 x

zkam83
Greenskin
Posts: 119
Joined: Mon Jul 31, 2006 12:53 pm
Location: Iraq
Contact:

Post by zkam83 » Sat Feb 10, 2007 2:22 am

You cannot have 2 sky domes. You can only mix a sky dome with a sky box if you will.
Ogre API Reference wrote:You can actually combine a sky box and a sky dome if you want, to give a positional backdrop with an overlayed curved cloud layer.
You can, however, have a skydome with a material that lets you fade between 2 textures smoothly (each texture can have it's own scrolling speed). For that you have to write your own shader. Invest some of your time to learn about shaders, it's worth it :wink:.

Rendering sky domes is similar to rendering your scene objects. So if you want to have alpha blending for it, go to it's material script and set "scene_blend alpha_alphablend". Also make sure the texture has an alpha channel.
0 x

jasonchewy
Gnoblar
Posts: 8
Joined: Sat Feb 10, 2007 1:18 am

Post by jasonchewy » Sat Feb 10, 2007 3:33 am

Thank you for your prompt response.

So all of these are done inside the material file. Is there a way to set say the "scene_blend alpha_alphablend" dynamically in the C code of my program?
Or would I need to create many different materials and swap them as the time passes by in the game?
0 x

User avatar
HexiDave
OGRE Expert User
OGRE Expert User
Posts: 1538
Joined: Sat Jan 14, 2006 8:00 pm

Post by HexiDave » Sat Feb 10, 2007 4:33 am

It would likely be faster and cleaner to do it via shader - if you can Zip your sky-dome textures and post the code (or PM me if you prefer) I can give you some code for it. I generally use Cg/HLSL shaders and I can comment it.
0 x

zkam83
Greenskin
Posts: 119
Joined: Mon Jul 31, 2006 12:53 pm
Location: Iraq
Contact:

Post by zkam83 » Sat Feb 10, 2007 11:56 am

Excuse me for the typing error, it is 'scene_blend alpha_blend'.

You would'nt want to change your material script dynamically because then you'll need to have Ogre to re parse it!

Like HexiDave said, let the custom shader handle changing the alpha channel dynamically based on parameters you pass to it (you still need to set alpha_blend though).
0 x

jasonchewy
Gnoblar
Posts: 8
Joined: Sat Feb 10, 2007 1:18 am

Post by jasonchewy » Tue Feb 13, 2007 3:30 pm

I think I'm just using one of the default tutorial texture.

Code: Select all

material CAX/CloudySunsetSky
{
  technique
    {
      pass
        {
          lighting off
          depth_write off

          texture_unit
          {
            texture clouds_tiling.png
            scroll_anim 0.05 0
          }

	}
    }
}
Thanks for helping!
0 x

User avatar
HexiDave
OGRE Expert User
OGRE Expert User
Posts: 1538
Joined: Sat Jan 14, 2006 8:00 pm

Post by HexiDave » Thu Feb 15, 2007 7:43 am

I had responded to this in the PM, but I'll post here for posterity (sharing is good!) You can easily customize this and add more functionality (switching textures after you're done blending, more textures to blend, etc.), but this is just a basic time-based scrolling animation that blends between two textures of variable scale. You can set the scale/textures in the material itself, but you could extend it to take information the same way you set the fBlend factor in the source code. Here we go:

Material file:

Code: Select all

fragment_program skydomePS hlsl
{
	source skydomePS1_4.source
	target ps_1_4
	entry_point ps_main
}

vertex_program skydomeVS hlsl
{
	source skydomeVS1_1.source
	target vs_1_1
	entry_point vs_main
}


material SkydomeShaderBlend
{
	technique
	{
		pass
		{
			fragment_program_ref skydomePS
			{


				//Shader Constant: fBlend
				param_named fBlend float 0.000000


			}

			vertex_program_ref skydomeVS
			{
				//Shader Constant: matViewProjection
				param_named_auto matViewProjection viewproj_matrix

				//Shader Constant: fAnimSpeed
				param_named fAnimSpeed float2 -20.0 10.0

				//Shader Constant: fTime0_1
				param_named_auto fTime0_1 time_0_1 120.0

				// This is a weird one - I just smashed two float2's together
				// The first two float parameters are for the first texture
				// The second two floats are for the second texture
				// Thus, texture 0 is scaled 5 in both x and y
				// and texture 1 is scaled 10 in both x and y
				// When using float4's you get x,y,z, and w,
				// so just pretend it's x,y ; x,y instead of x,y ; z,w
				param_named fTexScales float4 5.0 5.0 10.0 10.0
			}

			texture_unit
			{
				texture EarthClouds.jpg 2d
			}

			texture_unit
			{
				texture cloud.tga 2d
			}
		}
	}
}
Obviously those two textures are placeholders from my tests, change to what you want (and adjust scale values as per the comments.)

skydomePS1_4.source

Code: Select all

sampler2D Texture0; //First texture sampler
sampler2D Texture1; // Second texture sampler
float fBlend; // Blend factor, float range [0.0, 1.0]
float4 ps_main(float2 TexCoord0 : TEXCOORD0, float2 TexCoord1 : TEXCOORD1) : COLOR0
{   
   // Get the two colors from the textures
   float4 tex0 = tex2D(Texture0, TexCoord0);
   float4 tex1 = tex2D(Texture1,TexCoord1);
    
   // Return the linear interpolated value, based on the Blend factor
   // i.e. if fBlend is 0.6, it returns 60% tex0, 40% tex1 (think that's right - might be reverse)
   return( lerp(tex0, tex1, fBlend) );
   
}
skydomeVS1_1.source

Code: Select all

float4x4 matViewProjection; // view projection matrix
float2 fAnimSpeed; // 2D vector for animation speed
float fTime0_1; // Time from Ogre, range [0.0, 1.0]
float4 fTexScales; // Scaling for both textures, 2 float2's together; see material file comments

struct VS_INPUT 
{
   float4 Position : POSITION0;
   float2 TexCoord : TEXCOORD0;
   
};

struct VS_OUTPUT 
{
   float4 Position : POSITION0;
   float2 TexCoord0 : TEXCOORD0; 
   float2 TexCoord1 : TEXCOORD1;  
};

VS_OUTPUT vs_main( VS_INPUT Input )
{
   VS_OUTPUT Output;
   
   // Get final vertex position
   Output.Position = mul( matViewProjection, Input.Position );

   // Speed vector multiplied by time gives you current offset
   float2 fAnimBonus = float2(fAnimSpeed.x,fAnimSpeed.y)*fTime0_1;

   // When scaling texture coordinates, you're basically repeating the texture faster for larger values, so I reversed it
   // Just scales the texture coordinates and adds the offset
   Output.TexCoord0 = float2(Input.TexCoord.x * 1/fTexScales.x, Input.TexCoord.y * 1/fTexScales.y) + fAnimBonus;
   Output.TexCoord1 = float2(Input.TexCoord.x * 1/fTexScales.z, Input.TexCoord.y * 1/fTexScales.w) + fAnimBonus;
   
   return( Output );
   
}
In Ogre, as global declarations (generally outside your frame-listener and application code and at the top, under #include directives):

Code: Select all

Ogre::MaterialPtr	  mActiveMaterial;
Ogre::Pass*			  mActivePass;
Ogre::GpuProgramPtr	  mActiveFragmentProgram;
Ogre::GpuProgramParametersSharedPtr mActiveFragmentParameters;
That way you'll be able to access them from frame listener and the createScene() code.

Put this in your application's destructor's code:

Code: Select all

		mActiveFragmentParameters.setNull();
		mActiveFragmentProgram.setNull();
		mActiveMaterial.setNull();
That'll keep it from throwing errors when you close.

Put this in your createScene() code:

Code: Select all

        // Create a skydome
        mSceneMgr->setSkyDome(true, "SkydomeShaderBlend", 5, 8);

		mActiveMaterial = static_cast<MaterialPtr>(MaterialManager::getSingleton().getByName("SkydomeShaderBlend"));
		mActivePass = mActiveMaterial->getTechnique(0)->getPass(0);
		mActiveFragmentProgram = mActivePass->getFragmentProgram();
		mActiveFragmentParameters = mActivePass->getFragmentProgramParameters();
The last parameter for setSkyDome might not be needed, but that was there when I copied it *shrug*.

Now, here's just example code for changing the fBlend value - put this in your framelistener's frameStarted() code:

Code: Select all

		static Real fBlend = 0.0;
		static bool bFadeUp = true;
		mActiveFragmentParameters->setNamedConstant("fBlend",fBlend);
		if(bFadeUp)
			fBlend += evt.timeSinceLastFrame;
		else
			fBlend -= evt.timeSinceLastFrame;

		if (fBlend >= 1.0)
			bFadeUp = false;
		else if(fBlend <= 0.0)
			bFadeUp = true;
The important part is the mActiveFragmentParameters->setNamedConstant() function - that's where you set the material's values that the shader uses.

Hope that helps out - if you need help using this (I just dumped it in with the SkyDome demo) or it throws errors (I'm using Eihort RC1), let me know.
0 x

jasonchewy
Gnoblar
Posts: 8
Joined: Sat Feb 10, 2007 1:18 am

Post by jasonchewy » Thu Feb 22, 2007 1:50 am

ran into problem when I got to this line:
mActiveFragmentParameters->setNamedConstant("fBlend",fBlend);

it says that it can't find the fBlend parameter.

also if I run this without the above line, all I see on the sky is white....

any idea?
0 x

User avatar
HexiDave
OGRE Expert User
OGRE Expert User
Posts: 1538
Joined: Sat Jan 14, 2006 8:00 pm

Post by HexiDave » Thu Feb 22, 2007 6:57 am

What version of Ogre are you running with?
Are there any Ogre.log file errors pertaining to the textures/material/shaders?
Did you just run it as-is without changing the textures to ones that exist (mine weren't from Ogre)?

What graphics card do you have?

That should help narrow the problem down. I'm guessing either you didn't supply your own textures or your card doesn't support the shaders.
0 x

jasonchewy
Gnoblar
Posts: 8
Joined: Sat Feb 10, 2007 1:18 am

Post by jasonchewy » Thu Feb 22, 2007 11:12 pm

ahh, I did find an error with the material file, from the orge.log
"Error in material FadingSky at line 26 of skyFading.material: Unrecognised command: Shader"
It didn't like this line:
"Shader Constant: fBlend"
0 x

jasonchewy
Gnoblar
Posts: 8
Joined: Sat Feb 10, 2007 1:18 am

Post by jasonchewy » Thu Feb 22, 2007 11:22 pm

From searching on similar code on the forum, I find that that line suppose to be commented...
so I did...but no...still doesn't work...same error.
I'm running 1.2.4 (Dagon) of orge.

I'm running same code as yours, except the texture files are changed.

and I'm running this on a laptop with crappy intel integrated video card.
but that shouldn't cause this problem....if anything I just see nothing or it's very laggy...
0 x

User avatar
HexiDave
OGRE Expert User
OGRE Expert User
Posts: 1538
Joined: Sat Jan 14, 2006 8:00 pm

Post by HexiDave » Fri Feb 23, 2007 1:58 am

Well you should try the skeletal animation demo and see if it runs with Hardware skinning or Software skinning (think it still displays that.) If it shows software skinning, then your card probably doesn't support shaders.

Next, I don't know why comments would affect it, but just delete all the commented lines, I suppose.
0 x

jasonchewy
Gnoblar
Posts: 8
Joined: Sat Feb 10, 2007 1:18 am

Post by jasonchewy » Fri Feb 23, 2007 7:47 am

actually come to think about it, I think my video doesn't support something.....I remember I couldn't play some game on my laptop, because the video card lacks the support of one thing....it could have been the shaders
but not sure if lacking the shaders causes the fblend to be not found....but I'll try that skeleton demo and see what happens..but I'll be back on my desktop by then...so everything maybe work then...
I'll keep you posted.
0 x

User avatar
HexiDave
OGRE Expert User
OGRE Expert User
Posts: 1538
Joined: Sat Jan 14, 2006 8:00 pm

Post by HexiDave » Fri Feb 23, 2007 7:56 am

Well it would cause it AND your material showing up blank because it didn't support the shaders - the whole effect was done with shaders. So, when the material failed due to lack of support, it would also fail to get a shader variable since that technique was skipped.
0 x

jasonchewy
Gnoblar
Posts: 8
Joined: Sat Feb 10, 2007 1:18 am

Post by jasonchewy » Sun Mar 04, 2007 10:17 pm

I've tried again on my desktop, and the same result.
I've decided to give up on this idea, as I'm doing this for a project, time's running out.

Thanks for all your help, and I hope those posted code would help others out there.
0 x

Post Reply