Transition between two texture of skydome
-
- Gnoblar
- Posts: 8
- Joined: Sat Feb 10, 2007 1:18 am
Transition between two texture of skydome
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.
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.
-
- Greenskin
- Posts: 119
- Joined: Mon Jul 31, 2006 12:53 pm
- Location: Iraq
- x 2
- Contact:
You cannot have 2 sky domes. You can only mix a sky dome with a sky box if you will.
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.
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 .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.
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.
-
- Gnoblar
- Posts: 8
- Joined: Sat Feb 10, 2007 1:18 am
- HexiDave
- OGRE Expert User
- Posts: 1538
- Joined: Sat Jan 14, 2006 8:00 pm
- x 1
-
- Greenskin
- Posts: 119
- Joined: Mon Jul 31, 2006 12:53 pm
- Location: Iraq
- x 2
- Contact:
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).
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).
-
- Gnoblar
- Posts: 8
- Joined: Sat Feb 10, 2007 1:18 am
I think I'm just using one of the default tutorial texture.
Thanks for helping!
Code: Select all
material CAX/CloudySunsetSky
{
technique
{
pass
{
lighting off
depth_write off
texture_unit
{
texture clouds_tiling.png
scroll_anim 0.05 0
}
}
}
}
- HexiDave
- OGRE Expert User
- Posts: 1538
- Joined: Sat Jan 14, 2006 8:00 pm
- x 1
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:
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
skydomeVS1_1.source
In Ogre, as global declarations (generally outside your frame-listener and application code and at the top, under #include directives):
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:
That'll keep it from throwing errors when you close.
Put this in your createScene() code:
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:
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.
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
}
}
}
}
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) );
}
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 );
}
Code: Select all
Ogre::MaterialPtr mActiveMaterial;
Ogre::Pass* mActivePass;
Ogre::GpuProgramPtr mActiveFragmentProgram;
Ogre::GpuProgramParametersSharedPtr mActiveFragmentParameters;
Put this in your application's destructor's code:
Code: Select all
mActiveFragmentParameters.setNull();
mActiveFragmentProgram.setNull();
mActiveMaterial.setNull();
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();
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;
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.
-
- Gnoblar
- Posts: 8
- Joined: Sat Feb 10, 2007 1:18 am
- HexiDave
- OGRE Expert User
- Posts: 1538
- Joined: Sat Jan 14, 2006 8:00 pm
- x 1
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.
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.
-
- Gnoblar
- Posts: 8
- Joined: Sat Feb 10, 2007 1:18 am
-
- Gnoblar
- Posts: 8
- Joined: Sat Feb 10, 2007 1:18 am
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...
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...
- HexiDave
- OGRE Expert User
- Posts: 1538
- Joined: Sat Jan 14, 2006 8:00 pm
- x 1
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.
Next, I don't know why comments would affect it, but just delete all the commented lines, I suppose.
-
- Gnoblar
- Posts: 8
- Joined: Sat Feb 10, 2007 1:18 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.
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.
- HexiDave
- OGRE Expert User
- Posts: 1538
- Joined: Sat Jan 14, 2006 8:00 pm
- x 1
-
- Gnoblar
- Posts: 8
- Joined: Sat Feb 10, 2007 1:18 am