OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

Culling and intersects with ocean and model...


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> osgOcean [osgOcean]
View previous topic :: View next topic  
Author Message
tim (tim paige)
User


Joined: 25 Feb 2009
Posts: 31
Location: San Diego

PostPosted: Tue Mar 22, 2011 3:57 pm    Post subject:
Culling and intersects with ocean and model...
Reply with quote

Hi,

When boat is placed in ocean at a specific waterline... when viewing from above, that waterline is also in the boat.
Although my boat is in no immediate danger of sinking... what must I learn in order to exclude the effect of the surface of the ocean from invading my space?

Thank you!

Cheers,
tim
Back to top
View user's profile Send private message
Skylark (Jean-Sébastien Guay)
Professional


Joined: 05 Jan 2009
Posts: 2249

PostPosted: Tue Mar 22, 2011 5:30 pm    Post subject:
Culling and intersects with ocean and model...
Reply with quote

Hi Tim,

Quote:
When boat is placed in ocean at a specific waterline... when viewing from above, that waterline is also in the boat.
Although my boat is in no immediate danger of sinking... what must I learn in order to exclude the effect of the surface of the ocean from invading my space?

We do two things to avoid this issue, none of which is perfect.

1. Make sure the bottom of the boat is closed (so there's an enclosed
volume between the boat's hull and the deck), and make sure the wave
height is always low enough that the waves won't peek through the deck.

2. If we need really high waves, I wrote a shader that gets the position
of 4 corner points of the boat's deck, and discards any fragments of the
ocean surface that are inside these 4 corners. This effectively clips
the ocean surface, but because of time constraints, it was not done in
the best way possible. The constraint we chose to live with is that it's
a 2D test only, i.e. it tests in the XY plane, i.e. if the boat is ever
above the ocean the surface will still look clipped, and if the boat's
hull is curved then you might even see the hole in the ocean surface
when looking at the boat from the side.

If I had to design a better solution (i.e. one that would make it into
osgOcean itself, not one made just to satisfy a client who doesn't like
having water on the boat's deck), I would want to eliminate those
constraints. I would probably make a convex shape that would clip the
ocean surface, or something like that.

Hope this at least gives you some ideas,

J-S
--
______________________________________________________
Jean-Sebastien Guay
http://www.cm-labs.com/
http://whitestar02.dyndns-web.com/


------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
tim (tim paige)
User


Joined: 25 Feb 2009
Posts: 31
Location: San Diego

PostPosted: Tue Mar 22, 2011 8:44 pm    Post subject:
Reply with quote

J-S, Thanks for the hints...

I appreciate the comments. Up to this point I do not yet know what a shader does for a living... except that I presumed it "shaded" surfaces somehow.

So... that will be my first step... I wouldn't have known that they were involved in "cutting" (culling) unwanted sections of objects, except that I also presume that while navigating over the vertices of an object, one could force their wishes upon that object while traversing a plane within it.

Is a shader the right place to do this kind of job?
Are there other places/techniques?
And... I'm sure you or others might suggest the ultimate shading tutorial...
Ahh... I see there is an osgShaders example... perhaps I will find clues to misusing them there.

This soon-to-be-shady character appreciates you pointing me to one more baby-step in the right direction.

Thank you!

Cheers,
tim
Back to top
View user's profile Send private message
Jason Daly
Guest





PostPosted: Tue Mar 22, 2011 11:10 pm    Post subject:
Culling and intersects with ocean and model...
Reply with quote

On 03/22/2011 04:44 PM, tim paige wrote:
Quote:
And... I'm sure you or others might suggest the ultimate shading tutorial...

This one seems good. I haven't read the whole thing, but I've used
sections of it in the past...

http://www.lighthouse3d.com/opengl/glsl/


That, together with the osgshaders example should help get you up to
speed on using shaders in OSG.

--"J"



------------------
Post generated by Mail2Forum
Back to top
Skylark (Jean-Sébastien Guay)
Professional


Joined: 05 Jan 2009
Posts: 2249

PostPosted: Wed Mar 23, 2011 1:37 am    Post subject:
Culling and intersects with ocean and model...
Reply with quote

Hi Tim,

Quote:
I appreciate the comments. Up to this point I do not yet know what a shader does for a living... except that I presumed it "shaded" surfaces somehow.

So... that will be my first step... I wouldn't have known that they were involved in "cutting" (culling) unwanted sections of objects, except that I also presume that while navigating over the vertices of an object, one could force their wishes upon that object while traversing a plane within it.

You'll undoubtedly come across more accurate and complete descriptions,
but to get you started, here is my way of explaining it.

Shaders are essentially small programs that get run by the GPU once per
(different types of items the GPU processes). So for starters there are
vertex shaders (executed once per vertex) and fragment shaders (executed
once per fragment).

BTW, that last one is called pixel shader in D3D land, but in OpenGL we
call it by the more accurate name fragment shader. A fragment is a pixel
that has passed the z buffer test, and so is sure to be written to the
framebuffer.

There are other types now (geometry and tessellation shaders) but the
most used are vertex and fragment shaders. GPUs started as a big,
unprogrammable stack of state variables that controlled a fixed
pipeline. Now more and more stages of the GPU's pipeline are becoming
programmable, and the means to program them is to write shaders.

Quote:
Is a shader the right place to do this kind of job?
Are there other places/techniques?

Shaders were the easiest place I could think of. I could have derived
from osgOcean's geometry class (MipmapGeometry I think) and modified the
actual geometry in OSG each frame to cut the shape of the boat's hull in
the ocean surface, or just flatten the waves' geometry in the area
occupied by the hull. That actually might be the best way of getting the
exact shape of the hull, because when doing things on the GPU you're a
bit limited in what you can do, but on the CPU the only limit would be
the amount of time you're willing to spend per frame to do the cutting.

Quote:
And... I'm sure you or others might suggest the ultimate shading tutorial...
Ahh... I see there is an osgShaders example... perhaps I will find clues to misusing them there.

Jason already sent you the link to lighthouse3d, I also used that one
when I was learning. It will show you the basics of writing lighting and
texturing shaders, but from there you have to use your imagination to
see what else you can do with them.

For instance, when you get to the "Statements and Functions" page
(http://www.lighthouse3d.com/opengl/glsl/index.php?statements) , you'll
see a quick description of the "discard" keyword. This is what I used in
my ocean surface fragment shader to cut the ocean surface. Essentially,
what I had was four uniform vec3 variables defining the corners of the
rectangle I wanted to cut, and I did a simple point-in-rectangle test to
see if the current fragment was inside that rectangle (making sure to
use world space coordinates for both the rectangle corners and the
fragment's position), and if it was I discarded it.

Hope this helps,

J-S
--
______________________________________________________
Jean-Sebastien Guay
http://www.cm-labs.com/
http://whitestar02.dyndns-web.com/


------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
kcbale
User


Joined: 04 Mar 2011
Posts: 68

PostPosted: Wed Mar 23, 2011 8:59 am    Post subject:
Culling and intersects with ocean and model...
Reply with quote

Just to add a little:

This covers a lot of the basics too, great set of tutorials that I recommend to everyone.


http://www.ozone3d.net/tutorials/


[/url]Regards,


Kim.


On 23 March 2011 01:37, Jean-Sébastien Guay < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:
Quote:
Hi Tim,

Quote:
I appreciate the comments. Up to this point I do not yet know what a shader does for a living... except that I presumed it "shaded" surfaces somehow.

So... that will be my first step... I wouldn't have known that they were involved in "cutting" (culling) unwanted sections of objects, except that I also presume that while navigating over the vertices of an object, one could force their wishes upon that object while traversing a plane within it.


You'll undoubtedly come across more accurate and complete descriptions, but to get you started, here is my way of explaining it.

Shaders are essentially small programs that get run by the GPU once per (different types of items the GPU processes). So for starters there are vertex shaders (executed once per vertex) and fragment shaders (executed once per fragment).

BTW, that last one is called pixel shader in D3D land, but in OpenGL we call it by the more accurate name fragment shader. A fragment is a pixel that has passed the z buffer test, and so is sure to be written to the framebuffer.

There are other types now (geometry and tessellation shaders) but the most used are vertex and fragment shaders. GPUs started as a big, unprogrammable stack of state variables that controlled a fixed pipeline. Now more and more stages of the GPU's pipeline are becoming programmable, and the means to program them is to write shaders.

Quote:
Is a shader the right place to do this kind of job?
Are there other places/techniques?


Shaders were the easiest place I could think of. I could have derived from osgOcean's geometry class (MipmapGeometry I think) and modified the actual geometry in OSG each frame to cut the shape of the boat's hull in the ocean surface, or just flatten the waves' geometry in the area occupied by the hull. That actually might be the best way of getting the exact shape of the hull, because when doing things on the GPU you're a bit limited in what you can do, but on the CPU the only limit would be the amount of time you're willing to spend per frame to do the cutting.

Quote:
And... I'm sure you or others might suggest the ultimate shading tutorial...
Ahh... I see there is an osgShaders example... perhaps I will find clues to misusing them there.


Jason already sent you the link to lighthouse3d, I also used that one when I was learning. It will show you the basics of writing lighting and texturing shaders, but from there you have to use your imagination to see what else you can do with them.

For instance, when you get to the "Statements and Functions" page ([url=http://www.lighthouse3d.com/opengl/glsl/index.php?statements]http://www.lighthouse3d.com/opengl/glsl/index.php?statements) , you'll see a quick description of the "discard" keyword. This is what I used in my ocean surface fragment shader to cut the ocean surface. Essentially, what I had was four uniform vec3 variables defining the corners of the rectangle I wanted to cut, and I did a simple point-in-rectangle test to see if the current fragment was inside that rectangle (making sure to use world space coordinates for both the rectangle corners and the fragment's position), and if it was I discarded it.

Hope this helps,

J-S
--
______________________________________________________
Jean-Sebastien Guay     (
Only registered users can see emails on this board!
Get registred or enter the forums!
)
                              http://www.cm-labs.com/
                   http://whitestar02.dyndns-web.com/
_______________________________________________


osg-users mailing list
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org




------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
tim (tim paige)
User


Joined: 25 Feb 2009
Posts: 31
Location: San Diego

PostPosted: Wed Mar 23, 2011 8:59 pm    Post subject:
Reply with quote

J-S, KC, Jason

Trez Cool...
Thank you! An impressive start. I now have a kick in the butt to study up and now also have some nice links with what appears to be great information. Looks like a lot to absorb. I hope to first find a base technique to try for my baby-step and see where it takes me. I appreciate the layman's description of a shader... it makes it seems less ominous. It will take me a little bit to get the lingo into "Tim" language.

So...
I am bookmarked and ready...
In the meantime I implemented the direct input and can now drive my boat around (full of water) with the joystick.

Cheers,
tim
Back to top
View user's profile Send private message
GMan
User


Joined: 23 Jan 2009
Posts: 29

PostPosted: Wed Sep 14, 2011 9:49 pm    Post subject:
Reply with quote

Hi,

I have a decent solution to this problem that doesn't require modifications to the shader and can work with any number of ships in the scene. The stencil buffer can be set up to mark the fragments on the inside of the boat as ineligible for rendering upon by the ocean. Then when the ocean renders, it can fail the stencil test and not draw on those areas. My process for this is:

1) Export the geometry in separate subgraphs so that all exterior boat geometry is under one branch and all interior geometry is under another.

2) Load the file and find interior and exterior graph root nodes.

3) Apply a stencil to the interior to always mark that fragment with an ID like this:

Code:
// The inner stencil should mark it
osg::Stencil* innerStencil = new osg::Stencil;
innerStencil->setFunction(osg::Stencil::ALWAYS);
innerStencil->setFunctionRef(STENCIL_VALUE);
innerStencil->setStencilPassAndDepthPassOperation(osg::Stencil::REPLACE);

interiorGroupState->setAttributeAndModes(innerStencil, osg::StateAttribute::ON);


4) Apply a stencil to the exterior to always unmark anything that might've been marked by a previous draw of the interior that is underneath (depth-wise) like this:

Code:
// The outer stencil should un-mark it so that if part of this mesh
// draws on top of the mNodeToStencil, it doesn't count as 'marked'
osg::Stencil* outerStencil = new osg::Stencil;
outerStencil->setFunction(osg::Stencil::ALWAYS);
outerStencil->setFunctionRef(0);
outerStencil->setStencilPassAndDepthPassOperation(osg::Stencil::REPLACE);

exteriorGroupState->setAttributeAndModes(outerStencil, osg::StateAttribute::ON);


5) Apply a stencil to the ocean geometry so that it tests to see if each fragment has already been drawn on with an interior boat pixel and if so, it fails the stencil test and doesn't draw like this:

Code:
// Tell the ocean tiles that they should not render on
// pixels that are occupied by surface vessels.
osg::Stencil* oceanStencil = new osg::Stencil;
oceanStencil->setFunction(osg::Stencil::NOTEQUAL);
oceanStencil->setFunctionRef(StencilActorComponent::STENCIL_VALUE);
oceanStencil->setStencilPassAndDepthPassOperation(osg::Stencil::KEEP);


6) Ensure that the ocean is drawn AFTER the boats so that the boats could have the stencil buffer already marked and the ocean can properly test before drawing. I didn't have a great way to do this but this sufficed:

Code:
// This needs to be drawn after the surface vessels (this works, for now)
GetMatrixNode()->getOrCreateStateSet()->setRenderBinDetails(5, "RenderBin");


The above worked wonderfully for me when I was just using a simple quad for my ocean and not using dtOcean. However, after bring dtOcean into my application, either the stenciling no longer work or I'm not able to make the boats draw before the ocean using the method from above.

So all that said, my main questions are:

How do I apply a stencil to my osgOcean::FFTOceanSurface?
How do I control the render order of dtOcean?


Thank you!

Cheers,
Michael

PS Make sure you are using a stencil buffer or this won't work Razz
I do this before creating my window:
Code:
osg::DisplaySettings* display = osg::DisplaySettings::instance();
display->setMinimumNumStencilBits(8);
[/code]
Back to top
View user's profile Send private message
GMan
User


Joined: 23 Jan 2009
Posts: 29

PostPosted: Tue Sep 27, 2011 10:50 pm    Post subject:
Reply with quote

I've just managed to get the technique described above working. Here is the result:



I've also posted a video showing the difference here: http://www.youtube.com/watch?v=Rf1yJObCLKI

In order to get this to work I had to first understand that the FFTOceanSurface's (Geode derivative) stateset will get overwritten any time a call to FFTOceanSurface::initStateSet is called. Unfortunately, this happens any time one of the many functions in FFTOceanTechnique gets called (ie setLightColor, setWindSpeed, etc...).

To get around this I am waiting until after the stateset gets created the first time and then applying the stencil to it. If did it beforehand, it would be wiped out in the call initStateSet. Then whenever I change the lightColor (my app has changing time of day), i recreate the stencil on the next frame since the stateset for this surface will also have been recreated.

This process would be made much easier if ocean surface only created a new stateset if a previous one didn't exist. Is there a reason for recreating it?
Back to top
View user's profile Send private message
Skylark (Jean-Sébastien Guay)
Professional


Joined: 05 Jan 2009
Posts: 2249

PostPosted: Wed Sep 28, 2011 12:25 am    Post subject:
Culling and intersects with ocean and model...
Reply with quote

Hi Michael,

Quote:
This process would be made much easier if ocean surface only created a new stateset if a previous one didn't exist. Is there a reason for recreating it?

No reason other than laziness. If any attribute that's being stored in
the stateset gets changed, rather than just changing that attribute (and
potentially others that depend on it, and so on) and thus scattering the
code that creates the state set in many different methods, we just dirty
the state set which causes it to be recreated and repopulated in the
next frame.

You're welcome to do it differently if you want and submit the change.
In fact it would really be nice if you could merge your technique into
osgOcean's own code and submit the change. I'm sure many people would
appreciate such functionality, if you have the time to do it.

J-S
--
______________________________________________________
Jean-Sebastien Guay
http://www.cm-labs.com/
http://whitestar02.dyndns-web.com/


------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
kcbale
User


Joined: 04 Mar 2011
Posts: 68

PostPosted: Wed Sep 28, 2011 8:30 am    Post subject:
Culling and intersects with ocean and model...
Reply with quote

Hi Michael,

Nice looking simulator you've got there, it's great to see osgOcean in the wild.


K.

On 28 September 2011 01:28, Jean-Sébastien Guay < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:
Quote:
Hi Michael,

Quote:
This process would be made much easier if ocean surface only created a new stateset if a previous one didn't exist.  Is there a reason for recreating it?


No reason other than laziness. If any attribute that's being stored in the stateset gets changed, rather than just changing that attribute (and potentially others that depend on it, and so on) and thus scattering the code that creates the state set in many different methods, we just dirty the state set which causes it to be recreated and repopulated in the next frame.

You're welcome to do it differently if you want and submit the change. In fact it would really be nice if you could merge your technique into osgOcean's own code and submit the change. I'm sure many people would appreciate such functionality, if you have the time to do it.

J-S
--
______________________________________________________
Jean-Sebastien Guay    jean-sebastien.guay@cm-labs.com (
Only registered users can see emails on this board!
Get registred or enter the forums!
)
                              http://www.cm-labs.com/
                   http://whitestar02.dyndns-web.com/

_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org (
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org




------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
GMan
User


Joined: 23 Jan 2009
Posts: 29

PostPosted: Wed Sep 28, 2011 4:47 pm    Post subject:
Re: Culling and intersects with ocean and model...
Reply with quote

Skylark wrote:

You're welcome to do it differently if you want and submit the change.
In fact it would really be nice if you could merge your technique into
osgOcean's own code and submit the change. I'm sure many people would
appreciate such functionality, if you have the time to do it.


Hi J-S,
I'd be happy to contribute this back at some point but I have some concerns.

- First, getting this working correctly is dependent on being able to apply the stencil to only the inside the ship since we want the water to still draw over the outside, but not the inside. From a generic perspective, it would probably be ok to just specify which geometry (or subgraphs with the stencil set) should not be allowed to have ocean drawn over it.

- The second concern is that in order for the ocean to know it should not draw over any particular fragment, the stencil needs to have already been set before the ocean gets there. This means that the ocean needs to be told to draw at a later phase (higher render bin number than that for used for ships in this case). I'm guessing this may be undesirable for some/many applications.

Thoughts?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> osgOcean [osgOcean] All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts Regarding Culling in osg Rambabu General 2 Sat Apr 22, 2017 7:21 am View latest post
No new posts Convert .obj model into .osg model darshanpopat Plugins [osgPlugins] 1 Thu Mar 30, 2017 1:57 pm View latest post
No new posts issue with 3ds model after upgrading ... filnet General 5 Thu Feb 09, 2017 1:27 pm View latest post
No new posts Triton Ocean Rambabu General 10 Tue Dec 13, 2016 11:17 am View latest post
No new posts Upon Clicking the mouse left button t... Rambabu General 6 Mon Dec 05, 2016 7:34 am View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP