Re: [Flightgear-devel] Cloud altitudes in shader?
On Wed, Jan 11, 2012 at 9:16 AM, Thorsten Renk wrote: >> Rather than passing in the eye position as a uniform, why not >> pass in the cloud altitude instead? Is this simply to avoid >> needing to modify the C++ code? > > I thought uniforms are things which are per frame constant in the scene > and apply to all objects the same way - i.e. I pass light attenuation > (scattering) or terminator position as uniforms to the shader. > > I don't see that cloud altitude falls into that category - it is constant > per cloud, but not per frame throughout the whole scene, I have clouds > with very different altitudes floating around. It seems on would need to > pass it the same way as, say, the top, middle and bottom shade parameters > on a per cloud basis. I think they are constant per object. However, it may be that the interaction between the 3D clouds C++ code and the effects files makes it difficult to set them per-cloud without modifying the C++ code. Once the 2.6.0 release is out the door and the new Impostor code is committed, I'll see if I can add it. -Stuart -- Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex infrastructure or vast IT resources to deliver seamless, secure access to virtual desktops. With this all-in-one solution, easily deploy virtual desktops for less than the cost of PCs and save 60% on VDI infrastructure costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox ___ Flightgear-devel mailing list Flightgear-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/flightgear-devel
Re: [Flightgear-devel] Cloud altitudes in shader?
> Rather than passing in the eye position as a uniform, why not > pass in the cloud altitude instead? Is this simply to avoid > needing to modify the C++ code? I thought uniforms are things which are per frame constant in the scene and apply to all objects the same way - i.e. I pass light attenuation (scattering) or terminator position as uniforms to the shader. I don't see that cloud altitude falls into that category - it is constant per cloud, but not per frame throughout the whole scene, I have clouds with very different altitudes floating around. It seems on would need to pass it the same way as, say, the top, middle and bottom shade parameters on a per cloud basis. Either there's something I do not understand here, but I decided to pass eye altitude largely because that is a constant per frame for the whole scene and I understand what I am doing with it. * Thorsten -- Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex infrastructure or vast IT resources to deliver seamless, secure access to virtual desktops. With this all-in-one solution, easily deploy virtual desktops for less than the cost of PCs and save 60% on VDI infrastructure costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox ___ Flightgear-devel mailing list Flightgear-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/flightgear-devel
Re: [Flightgear-devel] Cloud altitudes in shader?
On Wed, Jan 11, 2012 at 8:09 AM, Thorsten Renk wrote: > I have now a scheme that does seem to do the trick - high stuff and stuff > towards the sun glows properly before lower stuff and stuff away from the > sun. > > http://www.flightgear.org/forums/viewtopic.php?f=47&t=14755&start=15#p147240 Very beautiful! > The idea is: > > * compute the relative vector between eye position and vertex > * get its z-component as altitude difference > * pass the eye position altitude as uniform > * add eye altitude to relative altitude - this is the uncorrected vertex > altitude > * use the known distance to correct for curvature to get the actual > altitude (it's probably off by a few percent, but who cares?) Rather than passing in the eye position as a uniform, why not pass in the cloud altitude instead? Is this simply to avoid needing to modify the C++ code? -Stuart -- Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex infrastructure or vast IT resources to deliver seamless, secure access to virtual desktops. With this all-in-one solution, easily deploy virtual desktops for less than the cost of PCs and save 60% on VDI infrastructure costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox ___ Flightgear-devel mailing list Flightgear-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/flightgear-devel
Re: [Flightgear-devel] Cloud altitudes in shader?
> If you want to know the altitude, you need to have the matrix that > transforms > from the current view position/orientation to the earths center. And you > need > to transform from cartesian space into the earth ellipsoid. The best you > can > do is to do this per vertex. And even that is way too much computation > for > that single altitude that you can just set when you set up the geometry. > The most efficient method is probably to set up a 4 vector plane > equation that > represents the sea level altitude horizontal plane in object > coordinates. This > plane needs to be updated when the cloud object moves significantly by > the cpu > code. In the shader you can then compute the distance to the plane in the > usual way. That would give an altitude per vertex which would be even > exact per fragment by correct interpolation. > > If you only need the altitude per cloud, put that scalar value in a > uniform. That somehow seems way too complicated. We're currently rendering clouds to 45 km, my private hack does 75 km, in my wildest dreams I am speculating about 250 km, cloud altitude is always below 30 km - all these numbers are way smaller than the Earth radius, so a local Cartesian system and the first term of the Taylor expansion in curvature will always be enough to any sane accuracy. I have now a scheme that does seem to do the trick - high stuff and stuff towards the sun glows properly before lower stuff and stuff away from the sun. http://www.flightgear.org/forums/viewtopic.php?f=47&t=14755&start=15#p147240 The idea is: * compute the relative vector between eye position and vertex * get its z-component as altitude difference * pass the eye position altitude as uniform * add eye altitude to relative altitude - this is the uncorrected vertex altitude * use the known distance to correct for curvature to get the actual altitude (it's probably off by a few percent, but who cares?) I have the feeling there should be an even simpler way to do it, but after coordinate-system-crawling for 5 hours yesterday I'm simply not in the mood to try to find out. What derailed me for a while is that the shader doesn't do numerics to high accuracy - the small difference of two individually large numbers doesn't compute very well (I know it's a bad problem), and that screwed things up for a while, and so I thought the scheme itself was flawed, but I think I sorted that out as well. So, thanks for the input to everyone! * Thorsten -- Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex infrastructure or vast IT resources to deliver seamless, secure access to virtual desktops. With this all-in-one solution, easily deploy virtual desktops for less than the cost of PCs and save 60% on VDI infrastructure costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox ___ Flightgear-devel mailing list Flightgear-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/flightgear-devel
Re: [Flightgear-devel] Cloud altitudes in shader?
Hi, On Monday, January 09, 2012 12:00:29 thorsten.i.r...@jyu.fi wrote: > > I don't think the Model matrix will help you much either, as IIRC > > (0,0,0) is the center of the earth spheroid. > > Hm, the line is > > gl_Position = gl_ModelViewProjectionMatrix * gl_Position; > > Doesn't gl_ModelViewProjectionMatrix transform things into 2d screen > coordinates? Yes. > Would it work if I use a different matrix instead? Apparently > > vec4 groundPoint = gl_ModelViewMatrix * vec4(0.0, 0.0, 0.0, 1.0); > > can be used to generate the zero altitude point just below the current > view, so then the length of the difference vector dotted with an 'up' > normal would represent altitude (?) I have lost track of what you want to do. But transforming the 0 vector by the modelview does not give any altitude. It is just the point of the current models origin on eye coordinates. Also the modelview matrix contains the orientation of the view which makes all the coordinate directions hard to interpret. If you want to know the altitude, you need to have the matrix that transforms from the current view position/orientation to the earths center. And you need to transform from cartesian space into the earth ellipsoid. The best you can do is to do this per vertex. And even that is way too much computation for that single altitude that you can just set when you set up the geometry. The most efficient method is probably to set up a 4 vector plane equation that represents the sea level altitude horizontal plane in object coordinates. This plane needs to be updated when the cloud object moves significantly by the cpu code. In the shader you can then compute the distance to the plane in the usual way. That would give an altitude per vertex which would be even exact per fragment by correct interpolation. If you only need the altitude per cloud, put that scalar value in a uniform ... Mathias -- Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex infrastructure or vast IT resources to deliver seamless, secure access to virtual desktops. With this all-in-one solution, easily deploy virtual desktops for less than the cost of PCs and save 60% on VDI infrastructure costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox ___ Flightgear-devel mailing list Flightgear-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/flightgear-devel
Re: [Flightgear-devel] Cloud altitudes in shader?
> > gl_ModelViewMatrix * vec4(0.0, 0.0, 0.0, 1.0); > > > > has always been the position of the camera in world coordinates. > > Sorry for the confusion, This is really the world position of the > object center as stated before. I am going to rest. None of the above assertion are true. Sorry again -Fred -- Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex infrastructure or vast IT resources to deliver seamless, secure access to virtual desktops. With this all-in-one solution, easily deploy virtual desktops for less than the cost of PCs and save 60% on VDI infrastructure costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox ___ Flightgear-devel mailing list Flightgear-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/flightgear-devel
Re: [Flightgear-devel] Cloud altitudes in shader?
> gl_ModelViewMatrix * vec4(0.0, 0.0, 0.0, 1.0); > > has always been the position of the camera in world coordinates. Sorry for the confusion, This is really the world position of the object center as stated before. -Fred -- Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex infrastructure or vast IT resources to deliver seamless, secure access to virtual desktops. With this all-in-one solution, easily deploy virtual desktops for less than the cost of PCs and save 60% on VDI infrastructure costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox ___ Flightgear-devel mailing list Flightgear-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/flightgear-devel
Re: [Flightgear-devel] Cloud altitudes in shader?
Hi Thorsten, > De: thorsten i renk > > > I don't think the Model matrix will help you much either, as IIRC > > (0,0,0) is the center of the earth spheroid. > > Hm, the line is > > gl_Position = gl_ModelViewProjectionMatrix * gl_Position; > > Doesn't gl_ModelViewProjectionMatrix transform things into 2d screen > coordinates? > > Would it work if I use a different matrix instead? Apparently > > vec4 groundPoint = gl_ModelViewMatrix * vec4(0.0, 0.0, 0.0, 1.0); > > can be used to generate the zero altitude point just below the > current view, so then the length of the difference vector dotted with > an 'up' normal would represent altitude (?) gl_ModelViewMatrix * vec4(0.0, 0.0, 0.0, 1.0); has always been the position of the camera in world coordinates. If object center is at altitude 0, and up vector is (0,0,1,0), you could use gl_Vertex.z/gl_Vertex.w as the altitude of the vertex, but you'll probably see numerical inaccuracy because transforming big numbers with matrices of float is not recommended. If you need world coordinates of any vertex, OSG predefined this : // add me to the shader uniform mat4 osg_ViewMatrixInverse; that you can use like this : vec3 wPos = osg_ViewMatrixInverse * gl_ModelViewMatrix * gl_Vertex; Regards, -Fred -- Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex infrastructure or vast IT resources to deliver seamless, secure access to virtual desktops. With this all-in-one solution, easily deploy virtual desktops for less than the cost of PCs and save 60% on VDI infrastructure costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox ___ Flightgear-devel mailing list Flightgear-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/flightgear-devel
Re: [Flightgear-devel] Cloud altitudes in shader?
On Monday 09 January 2012 12:48:25 Emilian Huminiuc wrote: > I know that, that's why I suggested the final position, which should be > actually given by ecPosition.z. (At least for fogging the trees that works > as expected, I assume the trees use roughly the same approach). Actually meant gl_Position.z (ecPosition is in screen coordinates)-- Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex infrastructure or vast IT resources to deliver seamless, secure access to virtual desktops. With this all-in-one solution, easily deploy virtual desktops for less than the cost of PCs and save 60% on VDI infrastructure costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox___ Flightgear-devel mailing list Flightgear-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/flightgear-devel
Re: [Flightgear-devel] Cloud altitudes in shader?
On Monday 09 January 2012 10:31:24 Stuart Buchanan wrote: > On Mon, Jan 9, 2012 at 10:00 AM, >> I don't think the Model matrix will help you much either, as IIRC > >> (0,0,0) is the center of the earth spheroid. > > > > Hm, the line is > > > > gl_Position = gl_ModelViewProjectionMatrix * gl_Position; > > > > Doesn't gl_ModelViewProjectionMatrix transform things into 2d screen > > coordinates? > > Correct (hence my reference to the Model matrix, rather than > ModelViewProjection matrix). > > > Would it work if I use a different matrix instead? Apparently > > > >vec4 groundPoint = gl_ModelViewMatrix * vec4(0.0, 0.0, 0.0, 1.0); > > > > can be used to generate the zero altitude point just below the current > > view, so then the length of the difference vector dotted with an 'up' > > normal would represent altitude (?) > > I didn't know that. > > >> What do you need it for? sunrise/sunset lighting? > > > > Yes, the earthShade factor should affect objects dependent on their > > altitude, basically I want glowing high-altitude clouds whereas the > > lower > > clouds are still dark. > > Thought so. That would be yet another nice effect to add :) > > On Mon, Jan 9, 2012 at 10:08 AM, Emilian Huminiuc wrote: > > In the transition shader (and the other terrain shaders), using > > gl_Vertex.z works as a good aproximation (it's used to determine if > > there should be snow painted, sometimes it behaves funny, but it's > > generally reliable enough), but for clouds maybe using the final value > > of gl_Position.z might give you what you want? > > The gl_Vertex of the terrain has a different coordinate system > (presumably based on > (0,0,0) being the center of the tile at sealevel?) than the clouds > (where (0,0,0) is the > center of the sprite). > > -Stuart > I know that, that's why I suggested the final position, which should be actually given by ecPosition.z. (At least for fogging the trees that works as expected, I assume the trees use roughly the same approach).-- Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex infrastructure or vast IT resources to deliver seamless, secure access to virtual desktops. With this all-in-one solution, easily deploy virtual desktops for less than the cost of PCs and save 60% on VDI infrastructure costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox___ Flightgear-devel mailing list Flightgear-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/flightgear-devel
Re: [Flightgear-devel] Cloud altitudes in shader?
On Mon, Jan 9, 2012 at 10:00 AM, >> I don't think the Model matrix will help you much either, as IIRC >> (0,0,0) is the center of the earth spheroid. > > Hm, the line is > > gl_Position = gl_ModelViewProjectionMatrix * gl_Position; > > Doesn't gl_ModelViewProjectionMatrix transform things into 2d screen > coordinates? Correct (hence my reference to the Model matrix, rather than ModelViewProjection matrix). > Would it work if I use a different matrix instead? Apparently > > vec4 groundPoint = gl_ModelViewMatrix * vec4(0.0, 0.0, 0.0, 1.0); > > can be used to generate the zero altitude point just below the current > view, so then the length of the difference vector dotted with an 'up' > normal would represent altitude (?) I didn't know that. >> What do you need it for? sunrise/sunset lighting? > > Yes, the earthShade factor should affect objects dependent on their > altitude, basically I want glowing high-altitude clouds whereas the lower > clouds are still dark. Thought so. That would be yet another nice effect to add :) On Mon, Jan 9, 2012 at 10:08 AM, Emilian Huminiuc wrote: > In the transition shader (and the other terrain shaders), using gl_Vertex.z > works as a good aproximation (it's used to determine if there should be snow > painted, sometimes it behaves funny, but it's generally reliable enough), > but for clouds maybe using the final value of gl_Position.z might give you > what you want? The gl_Vertex of the terrain has a different coordinate system (presumably based on (0,0,0) being the center of the tile at sealevel?) than the clouds (where (0,0,0) is the center of the sprite). -Stuart -- Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex infrastructure or vast IT resources to deliver seamless, secure access to virtual desktops. With this all-in-one solution, easily deploy virtual desktops for less than the cost of PCs and save 60% on VDI infrastructure costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox ___ Flightgear-devel mailing list Flightgear-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/flightgear-devel
Re: [Flightgear-devel] Cloud altitudes in shader?
On Monday 09 January 2012 09:53:08 Stuart Buchanan wrote: > Hi Thorsten, > > No, I don't think gl_Vertex.z will give you the cloud altitude. That's > just the vertex position relative to the sprite center. glColor is > used to pass in the sprite location relative to the cloud center, and > the Model Matrix places the cloud relative to the rest of the scene. > > I don't think the Model matrix will help you much either, as IIRC > (0,0,0) is the center of the earth spheroid. > > What do you need it for? sunrise/sunset lighting? > > As it happens, the Impostor changes will reduce the number of > variables required by the shader significantly, so I could add it in > as an additional variable if it would be useful. > > -Stuart > > On Mon, Jan 9, 2012 at 8:08 AM, wrote: > > Hi Stuart, > > > > is gl_Vertex.z a reasonably approximate guess for the altitude in which > > the cloud finally appears or do I have to look elsewhere? There's lots > > of > > reshuffling of the vertex coordinates going on in the shader, and I've > > kind of lost track a bit... > > > > * Thorsten > > In the transition shader (and the other terrain shaders), using gl_Vertex.z works as a good aproximation (it's used to determine if there should be snow painted, sometimes it behaves funny, but it's generally reliable enough), but for clouds maybe using the final value of gl_Position.z might give you what you want?-- Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex infrastructure or vast IT resources to deliver seamless, secure access to virtual desktops. With this all-in-one solution, easily deploy virtual desktops for less than the cost of PCs and save 60% on VDI infrastructure costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox___ Flightgear-devel mailing list Flightgear-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/flightgear-devel
Re: [Flightgear-devel] Cloud altitudes in shader?
> I don't think the Model matrix will help you much either, as IIRC > (0,0,0) is the center of the earth spheroid. Hm, the line is gl_Position = gl_ModelViewProjectionMatrix * gl_Position; Doesn't gl_ModelViewProjectionMatrix transform things into 2d screen coordinates? Would it work if I use a different matrix instead? Apparently vec4 groundPoint = gl_ModelViewMatrix * vec4(0.0, 0.0, 0.0, 1.0); can be used to generate the zero altitude point just below the current view, so then the length of the difference vector dotted with an 'up' normal would represent altitude (?) > What do you need it for? sunrise/sunset lighting? Yes, the earthShade factor should affect objects dependent on their altitude, basically I want glowing high-altitude clouds whereas the lower clouds are still dark. * Thorsten -- Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex infrastructure or vast IT resources to deliver seamless, secure access to virtual desktops. With this all-in-one solution, easily deploy virtual desktops for less than the cost of PCs and save 60% on VDI infrastructure costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox ___ Flightgear-devel mailing list Flightgear-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/flightgear-devel
Re: [Flightgear-devel] Cloud altitudes in shader?
Hi Thorsten, No, I don't think gl_Vertex.z will give you the cloud altitude. That's just the vertex position relative to the sprite center. glColor is used to pass in the sprite location relative to the cloud center, and the Model Matrix places the cloud relative to the rest of the scene. I don't think the Model matrix will help you much either, as IIRC (0,0,0) is the center of the earth spheroid. What do you need it for? sunrise/sunset lighting? As it happens, the Impostor changes will reduce the number of variables required by the shader significantly, so I could add it in as an additional variable if it would be useful. -Stuart On Mon, Jan 9, 2012 at 8:08 AM, wrote: > > Hi Stuart, > > is gl_Vertex.z a reasonably approximate guess for the altitude in which > the cloud finally appears or do I have to look elsewhere? There's lots of > reshuffling of the vertex coordinates going on in the shader, and I've > kind of lost track a bit... > > * Thorsten > > > -- > Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex > infrastructure or vast IT resources to deliver seamless, secure access to > virtual desktops. With this all-in-one solution, easily deploy virtual > desktops for less than the cost of PCs and save 60% on VDI infrastructure > costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox > ___ > Flightgear-devel mailing list > Flightgear-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/flightgear-devel -- Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex infrastructure or vast IT resources to deliver seamless, secure access to virtual desktops. With this all-in-one solution, easily deploy virtual desktops for less than the cost of PCs and save 60% on VDI infrastructure costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox ___ Flightgear-devel mailing list Flightgear-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/flightgear-devel
[Flightgear-devel] Cloud altitudes in shader?
Hi Stuart, is gl_Vertex.z a reasonably approximate guess for the altitude in which the cloud finally appears or do I have to look elsewhere? There's lots of reshuffling of the vertex coordinates going on in the shader, and I've kind of lost track a bit... * Thorsten -- Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex infrastructure or vast IT resources to deliver seamless, secure access to virtual desktops. With this all-in-one solution, easily deploy virtual desktops for less than the cost of PCs and save 60% on VDI infrastructure costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox ___ Flightgear-devel mailing list Flightgear-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/flightgear-devel