Skydome and far clip plane?
- AshMcConnell
- Silver Sponsor
- Posts: 605
- Joined: Fri Dec 14, 2007 11:44 am
- Location: Northern Ireland
- x 16
- Contact:
Skydome and far clip plane?
Hi Folks,
I am trying to get a skydome to work using: -
_sceneMgr->setSkyDome(true, "Standard_3", 10, 1, 500, true);
My far clip plane is set to 700, but in certain directions I just see the background colour. If i set the skydome distance to 2000 i don't see it at all, i was under the impression that the clip plane wasn't used when showing the skydome. Is there any way to clip "normal" objects at a lower level than the sky dome distance?
Thanks for your help
All the best,
Ash
I am trying to get a skydome to work using: -
_sceneMgr->setSkyDome(true, "Standard_3", 10, 1, 500, true);
My far clip plane is set to 700, but in certain directions I just see the background colour. If i set the skydome distance to 2000 i don't see it at all, i was under the impression that the clip plane wasn't used when showing the skydome. Is there any way to clip "normal" objects at a lower level than the sky dome distance?
Thanks for your help
All the best,
Ash
- madmarx
- OGRE Expert User
- Posts: 1671
- Joined: Mon Jan 21, 2008 10:26 pm
- x 50
Re: Skydome and far clip plane?
>>>Is there any way to clip "normal" objects at a lower level than the sky dome distance?
Most of the time, it is another way round : skies (skydome/skybox/skyplane) are drawn first with "depth_write off", so you can draw them at distance = 3, and draw the objects at distance = 50, they both will show up (with clip near = 1 and clip far = 2000), with skies behind the objects.
If whatever, you really need to clip normal objects at another level, you can render your viewport in two times. (but i think it's a bad idea) :
(everything rendered manually here).
It must be possible too to get directly the renderoperation of the skies for the first render (making it very quickier to execute).
Most of the time, it is another way round : skies (skydome/skybox/skyplane) are drawn first with "depth_write off", so you can draw them at distance = 3, and draw the objects at distance = 50, they both will show up (with clip near = 1 and clip far = 2000), with skies behind the objects.
If whatever, you really need to clip normal objects at another level, you can render your viewport in two times. (but i think it's a bad idea) :
Code: Select all
// first draw the far part with your skies.
camera->setNearClipPlane(2000.0);
camera->setNearClipPlane(4000000.0);
viewport->update(); // very inefficient if you have thousands of object because frustum culling will be calculated.
viewport->setClearBuffer(true,FBT_DEPTH); // clean everything but the color
camera->setNearClipPlane(1.0);
camera->setFarClipPlane(2000.0);
viewport->update();
viewport->setClearBuffer(true,FBT_DEPTH|FBT_COLOR);
It must be possible too to get directly the renderoperation of the skies for the first render (making it very quickier to execute).
Tutorials + Ogre searchable API + more for Ogre1.7 : http://sourceforge.net/projects/so3dtools/
Corresponding thread : http://www.ogre3d.org/forums/viewtopic. ... 93&start=0
Corresponding thread : http://www.ogre3d.org/forums/viewtopic. ... 93&start=0
- xadhoom
- Minaton
- Posts: 973
- Joined: Fri Dec 28, 2007 4:35 pm
- Location: Germany
- x 1
Re: Skydome and far clip plane?
I thought it would be more efficient to draw things like a skybox after all solid objects and before all transparent objects. You would save millions of shader operations in best case (if you can´t see the sky because of a wall/floor/terrain).
Ofcourse you have to make a depth test then, but maybe it can be simplified by just checking if there is a value less "max" (I´m not sure if such a depth test actually exists...).
IMHO this would be more performant though especially if you use complex sky rendering like Caelum.
Any experiences about that?
xad
Ofcourse you have to make a depth test then, but maybe it can be simplified by just checking if there is a value less "max" (I´m not sure if such a depth test actually exists...).
IMHO this would be more performant though especially if you use complex sky rendering like Caelum.
Any experiences about that?
xad
- madmarx
- OGRE Expert User
- Posts: 1671
- Joined: Mon Jan 21, 2008 10:26 pm
- x 50
Re: Skydome and far clip plane?
Well, in case you are in fixed pipeline, I thought it was not anymore that important. I don't use shaders on skybox. But it has certainly fillrate impact with shader, xadhoom you are right.
What you propose could be done with :
sceneManager->_setSkyDome ( true,materialName, curvature,tiling,distance, RENDER_QUEUE_MAIN+1);
for the render queue, it depends on which renderqueue group is used by the transparent objects (could be RENDER_QUEUE_MAIN_7..).
Or even better if you need that bad to save shaders : early z is also possible.
render everything not-transparent with depth_write on, colour-write off (but of course you still need vertex shader, domain shader, hull shader, and geometry shader to be calculated).
RenderableListener allows you to discard any depth_write off / transparent material, and replace material.
If you really really need to save shader, you can also go with deferred shading (like starcraft 2, gta4, & so on), but it is not so 'direct forward' .
What you propose could be done with :
sceneManager->_setSkyDome ( true,materialName, curvature,tiling,distance, RENDER_QUEUE_MAIN+1);
for the render queue, it depends on which renderqueue group is used by the transparent objects (could be RENDER_QUEUE_MAIN_7..).
Or even better if you need that bad to save shaders : early z is also possible.
render everything not-transparent with depth_write on, colour-write off (but of course you still need vertex shader, domain shader, hull shader, and geometry shader to be calculated).
RenderableListener allows you to discard any depth_write off / transparent material, and replace material.
If you really really need to save shader, you can also go with deferred shading (like starcraft 2, gta4, & so on), but it is not so 'direct forward' .
Tutorials + Ogre searchable API + more for Ogre1.7 : http://sourceforge.net/projects/so3dtools/
Corresponding thread : http://www.ogre3d.org/forums/viewtopic. ... 93&start=0
Corresponding thread : http://www.ogre3d.org/forums/viewtopic. ... 93&start=0
- AshMcConnell
- Silver Sponsor
- Posts: 605
- Joined: Fri Dec 14, 2007 11:44 am
- Location: Northern Ireland
- x 16
- Contact:
Re: Skydome and far clip plane?
HI Guys,
Thank you both for the replies! I was intending to use either fixed function or perhaps a simple shader to begin with. My approach is get something working - then think about making it fancy .
Would a simple shader that output the simple / unlit texture be the fastest route (in terms of framerate)? I am a graphics newbie really, i have been concentrating on other aspects of my game up to now.
The scene is a simple outdoor racing track, I just want to create a simple background rather than the current clear blue "sky" .
Thanks again!
All the best,
Ash
Thank you both for the replies! I was intending to use either fixed function or perhaps a simple shader to begin with. My approach is get something working - then think about making it fancy .
Would a simple shader that output the simple / unlit texture be the fastest route (in terms of framerate)? I am a graphics newbie really, i have been concentrating on other aspects of my game up to now.
The scene is a simple outdoor racing track, I just want to create a simple background rather than the current clear blue "sky" .
Madmarx, sorry to be a newbie, but could you explain a little more about this, I don't quite get what you mean. My current near clip is 0.2 and far is 700 (in order to avoid z fighting problems). How do I keep the skydome within that distance but not in front of the distant objects?so you can draw them at distance = 3, and draw the objects at distance = 50, they both will show up (with clip near = 1 and clip far = 2000), with skies behind the objects.
Thanks again!
All the best,
Ash
- madmarx
- OGRE Expert User
- Posts: 1671
- Joined: Mon Jan 21, 2008 10:26 pm
- x 50
Re: Skydome and far clip plane?
quick answer :
1/ concerning your frustum culling:
700 / 0.2 = 700 * 5 = 3500. It's to much IMO for most apps. Try to have a ratio Far/Near at 2000 to get best results.
2/ in your skydome construction, I see that you have only 1 tile. it could be source of the problem.
3/ try
_sceneMgr->setSkyDome(true, "Standard_3", 10, 7, 3, true);
->It will create a skydome with 49 tiles at distance 3.
-> 0.2(near)< 3(distance skydome) <700(far) so it will be visible.
->your skydome is drawn first (because of the 6th parameter).
-> other objects will be drawn after it. Normally they wouldn't show up if object_distance>skydomedistance.
-> so when drawing the skydome, you need to use a special material, which will simulate infinite distance.
-> the material must not write in the depht/Z buffer.
-> in order to only "color" the skydome, but not write into the Z buffer
-> you need to look at your "Standard_3" and in the pass(es), add :
depth_write off
->And if it is drawn first, you can also add :
depth_check off
more details in "3.1.2 Passes" in the manual.
Hope it is simplier?
1/ concerning your frustum culling:
700 / 0.2 = 700 * 5 = 3500. It's to much IMO for most apps. Try to have a ratio Far/Near at 2000 to get best results.
2/ in your skydome construction, I see that you have only 1 tile. it could be source of the problem.
3/ try
_sceneMgr->setSkyDome(true, "Standard_3", 10, 7, 3, true);
->It will create a skydome with 49 tiles at distance 3.
-> 0.2(near)< 3(distance skydome) <700(far) so it will be visible.
->your skydome is drawn first (because of the 6th parameter).
-> other objects will be drawn after it. Normally they wouldn't show up if object_distance>skydomedistance.
-> so when drawing the skydome, you need to use a special material, which will simulate infinite distance.
-> the material must not write in the depht/Z buffer.
-> in order to only "color" the skydome, but not write into the Z buffer
-> you need to look at your "Standard_3" and in the pass(es), add :
depth_write off
->And if it is drawn first, you can also add :
depth_check off
more details in "3.1.2 Passes" in the manual.
Hope it is simplier?
Tutorials + Ogre searchable API + more for Ogre1.7 : http://sourceforge.net/projects/so3dtools/
Corresponding thread : http://www.ogre3d.org/forums/viewtopic. ... 93&start=0
Corresponding thread : http://www.ogre3d.org/forums/viewtopic. ... 93&start=0
- AshMcConnell
- Silver Sponsor
- Posts: 605
- Joined: Fri Dec 14, 2007 11:44 am
- Location: Northern Ireland
- x 16
- Contact:
Re: Skydome and far clip plane?
Hi MadMarx,
Great! The penny has dropped . I understand what you mean now.
1/ Yeah, I've heard this before - I think there may be a way to render the close objects with a low near clipplane (my cockpit really) and then render the rest with a better ratio'd Far / Near.
2/ My skydome texture seems to be for 360 degrees, should i still tile?
3/ Great! Makes sense now - I thought that drawing it close would mean that i wouldnt see my "normal" scene objects, which was wrong of course, because not writing to the depth buffer allows the other objects to be rendered.
My world is actually a different co-ordinate system to ogre's, so i've added an orientation to rotate it: -
Here is the texture: -
Here is a screenshot: -
Is it simply a case of rotating the texture?
Thanks for your help - a couple of things have clicked for me today
All the best,
Ash
Great! The penny has dropped . I understand what you mean now.
1/ Yeah, I've heard this before - I think there may be a way to render the close objects with a low near clipplane (my cockpit really) and then render the rest with a better ratio'd Far / Near.
2/ My skydome texture seems to be for 360 degrees, should i still tile?
3/ Great! Makes sense now - I thought that drawing it close would mean that i wouldnt see my "normal" scene objects, which was wrong of course, because not writing to the depth buffer allows the other objects to be rendered.
My world is actually a different co-ordinate system to ogre's, so i've added an orientation to rotate it: -
I *think* this should rotate it to Z up. The dome certainly appears in all 360 degrees (which it didn't before i rotated), but the texture seems to be going the wrong direction.Ogre::Quaternion ori, rotz, roty;
rotz.FromAngleAxis(Ogre::Degree(-90), Vector3::UNIT_Z);
roty.FromAngleAxis(Ogre::Degree(90), Vector3::UNIT_Y);
ori = roty * rotz;
_sceneMgr->_setSkyDome(true, "Standard_3",10, 1, 3, RENDER_QUEUE_SKIES_EARLY,ori);
Here is the texture: -
Here is a screenshot: -
Is it simply a case of rotating the texture?
Thanks for your help - a couple of things have clicked for me today
All the best,
Ash
- AshMcConnell
- Silver Sponsor
- Posts: 605
- Joined: Fri Dec 14, 2007 11:44 am
- Location: Northern Ireland
- x 16
- Contact:
Re: Skydome and far clip plane?
Should I be using a cubemap with a skydome?
- madmarx
- OGRE Expert User
- Posts: 1671
- Joined: Mon Jan 21, 2008 10:26 pm
- x 50
Re: Skydome and far clip plane?
By the way you need to add :
lighting off
in the pass of your material.
If you want to rotate a texture, you can also do it directly in the texture_unit script.
It is extremely useful because you don't need to recompile to make some tests.
You can also stretch it, make it move & so on from script.
I personnaly use only cubemap. But cubemap texture is more complex to create (needs 6 textures with given angles & so on).
In your case, I would personnaly have created a manualobject halfsphere from code. I don't really see the point of skydome.
Is it the more appropriated for your needs? maybe.
Good luck!
lighting off
in the pass of your material.
If you want to rotate a texture, you can also do it directly in the texture_unit script.
It is extremely useful because you don't need to recompile to make some tests.
You can also stretch it, make it move & so on from script.
I personnaly use only cubemap. But cubemap texture is more complex to create (needs 6 textures with given angles & so on).
In your case, I would personnaly have created a manualobject halfsphere from code. I don't really see the point of skydome.
Is it the more appropriated for your needs? maybe.
Good luck!
Tutorials + Ogre searchable API + more for Ogre1.7 : http://sourceforge.net/projects/so3dtools/
Corresponding thread : http://www.ogre3d.org/forums/viewtopic. ... 93&start=0
Corresponding thread : http://www.ogre3d.org/forums/viewtopic. ... 93&start=0
- AshMcConnell
- Silver Sponsor
- Posts: 605
- Joined: Fri Dec 14, 2007 11:44 am
- Location: Northern Ireland
- x 16
- Contact:
Re: Skydome and far clip plane?
Thanks again madmarx,
I have just used a dome created and textured in max and moved it around with the camera position, works nicely!
Thanks!
All the best,
Ash
I have just used a dome created and textured in max and moved it around with the camera position, works nicely!
Thanks!
All the best,
Ash
- AshMcConnell
- Silver Sponsor
- Posts: 605
- Joined: Fri Dec 14, 2007 11:44 am
- Location: Northern Ireland
- x 16
- Contact:
Re: Skydome and far clip plane?
Hi Folks,
Found a pretty good overview as to why (and how) to render your skybox / dome last: -
http://ati.amd.com/developer/SwedenTech ... Tricks.pdf
I am going to try and do it the vertex shader method, I will report back if anyone is interested.
All the best,
Ash
Found a pretty good overview as to why (and how) to render your skybox / dome last: -
http://ati.amd.com/developer/SwedenTech ... Tricks.pdf
I am going to try and do it the vertex shader method, I will report back if anyone is interested.
All the best,
Ash
- AshMcConnell
- Silver Sponsor
- Posts: 605
- Joined: Fri Dec 14, 2007 11:44 am
- Location: Northern Ireland
- x 16
- Contact:
Re: Skydome and far clip plane?
Ok here is the shader code: -
and the program file: -
and the material: -
Make sure you remember to turn the depth_check on for the material, or it'll render in front of your "normal" objects.
Also I changed the renderQueueGroup of the entity of the textured mesh I loaded in order that the skies are rendered last. Note I am not using ogre's internal skydome mechanism here, just a textured dome that I move to the camera position each time.
I hope this helps some googler
All the best,
Ash
Code: Select all
void main_vp(
float4 position : POSITION,
float2 texCoord0: TEXCOORD0,
out float4 oPosition : POSITION,
out float2 uv0 : TEXCOORD0,
uniform float4x4 worldViewProj
)
{
oPosition = mul(worldViewProj, position);
oPosition.z = oPosition.w;
uv0 = texCoord0;
}
void main_fp(
float2 texCoord : TEXCOORD0,
out float4 color : COLOR,
uniform sampler2D decalMap : TEXUNIT0
)
{
color = tex2D(decalMap, texCoord);
}
Code: Select all
vertex_program SkydomeVP cg
{
source ashtrack.cg
entry_point main_vp
profiles vs_1_1
default_params
{
param_named_auto worldViewProj worldviewproj_matrix
}
}
fragment_program SkydomeFP cg
{
source ashtrack.cg
entry_point main_fp
profiles ps_2_x arbfp1
}
and the material: -
Code: Select all
material 14-Default
{
receive_shadows off
transparency_casts_shadows off
technique Map#200
{
pass Map#201
{
ambient 0.698039 0.698039 0.698039 1
diffuse 0.698039 0.698039 0.698039 1
specular 0.898039 0.898039 0.898039 1 20
emissive 0 0 0 1
scene_blend one zero
depth_check on
depth_write off
depth_func less_equal
depth_bias 0 0
alpha_rejection always_pass 0
cull_hardware clockwise
cull_software back
lighting off
shading gouraud
polygon_mode solid
colour_write on
max_lights 8
start_light 0
iteration once
vertex_program_ref SkydomeVP
{
param_named_auto worldViewProj worldviewproj_matrix
}
fragment_program_ref SkydomeFP
{
}
texture_unit Map#202
{
texture dusksky.jpg 2d unlimited
binding_type fragment
tex_coord_set 0
tex_address_mode wrap wrap wrap
tex_border_colour 0 0 0 1
filtering trilinear
max_anisotropy 1
mipmap_bias 0
colour_op_ex modulate src_texture src_current
alpha_op_ex modulate src_texture src_current
colour_op_multipass_fallback one zero
env_map off
}
}
}
}
Also I changed the renderQueueGroup of the entity of the textured mesh I loaded in order that the skies are rendered last. Note I am not using ogre's internal skydome mechanism here, just a textured dome that I move to the camera position each time.
Code: Select all
entity->setRenderQueueGroup(Ogre::RENDER_QUEUE_SKIES_LATE);
All the best,
Ash