Re: [osg-users] Passing location-based data to a fragment shader

2013-07-01 Thread Shahar Kosti
Hi Sebastian,
Thanks for the detailed explanation and the hints regarding texture/world 
coordinates. I've tried binding at the tile level as you suggested, but 
apparently the additional data source is not fast enough to be used at 
real-time.
At this point, I'm going to have the original terrain model regenerated with 
two textures for each tile, instead of constructing the second texture on the 
fly. As far as I understand, binding a second texture should be possible with 
the OSG and TXP formats.
So thanks again for attempting to help with issue.

Best,
Shahar


Sebastian Messerschmidt wrote:
 You don't really need to bind at a level this deep. Usually if the 
 terrain tile is loaded and represent a LOD you want to work with, you 
 can simple add your data texture(s) as uniform to the stateset of the tile.
 Given you have a texture with the data-image called texture you can do 
 it this way in your callback:
 
 osg::StateSet* state_set = node-getOrCreateStateSet();
 osg::Uniform* sampler = new osg::Uniform(MyDataSamper,  2 
 /*texture unit*/);
 
 state_set-setTextureAttribute(unit, texture ,osg::StateAttribute::ON);
 state_set-addUniform(sampler);
 
 With this you bind the texture to a sampler for your shader, at the 
 texture unit 2. Depending on how many textures are already bound you 
 might need to modify the unit.
 In the fragment shader you can now access the texture via:
 
 uniform sampler2D MyDataSampler
 ..
 ..
 
 main()
 {
 vec2 tex_coord = gl_TexCoord[0].st;
 vec4 data = texture2D(MyDataSampler, tex_coord);
 }
 


--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=55008#55008





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Passing location-based data to a fragment shader

2013-07-01 Thread Shahar Kosti
Hi Nick, 

Yes, this is part of what I'm trying to do (I'd like to do the same with osg 
models). I'd be glad if you could elaborate on the different approach, even 
though I would probably go with pre-generating the texture along with the 
archive.

Thanks,
Shahar


Trajce Nikolov NICK wrote:
 Hi Shahar,
 
 I read this post and found it interesting. Just out of curiosity :
 
 
 Each texel in the new texture, should be set based on the world location of 
 the corresponding texel in the current geometry texture
 
 
 
 Are you trying to overlay a texture on top of txp archive and it should be 
 georeferenced? If so, there might be a different approach
 
 
 Nick
 


--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=55009#55009





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Passing location-based data to a fragment shader

2013-06-26 Thread Trajce Nikolov NICK
Hi Shahar,

I read this post and found it interesting. Just out of curiosity :

Each texel in the new texture, should be set based on the world location of
the corresponding texel in the current geometry texture

Are you trying to overlay a texture on top of txp archive and it should be
georeferenced? If so, there might be a different approach

Nick


On Tue, Jun 25, 2013 at 3:50 PM, Sebastian Messerschmidt 
sebastian.messerschm...@gmx.de wrote:

 Hi Shahar,

 answers below.

  Sebastian Messerschmidt wrote:

 Hi Shahar Kosti:
 As you don't provide any exact numbers I can only guess. But usually I'd
 bind one or more textures per tile of paged set.
 Depending on your hardware bind of 8192x8192 textures is no problem.
 Can you be a bit more specific on how big the set is?

 Also for the hidden textures - I don't really get what you mean. My best
 guess is, that you mean not displayed.
 Therefore write a custom fragment shader and bind the data-textures
 along with you diffuse or whatever textures to the stateset of the tile.

 As the fragment shader is fully programmable, it is your choice what is
 done with the data.

 cheers
 Sebastian


 Hi Sebastian,

 Sorry for my late reply, it took me some time to get the data.
 One TXP I'm currently looking at, represents a 3000 km² area with texture
 resolution of 5m/pixel. Some areas have better resolution, up to 10
 cm/pixel. The additional metadata has similar resolution. So obviously
 wouldn't fit on a single texture.

 Okay, so the single TXP file represents the whole area? That's kinda hard,
 I thought you have multiple tiles representing parts of your complete data
 set.
 Anyways, First of all, your data sets need to be aligned somehow.



 Regarding your suggestions, could you elaborate on the bind one or more
 textures per tile of paged set approach?

 My current approach (which doesn't work), is to intercept paged nodes
 using a custom ReadFileCallback, which runs a NodeVisitor. The visitor
 finds all Geode objects and then the underlying geometries. I can bind a
 new texture to these geometries, but I'm not sure how to set the values
 correctly.

 You don't really need to bind at a level this deep. Usually if the
 terrain tile is loaded and represent a LOD you want to work with, you can
 simple add your data texture(s) as uniform to the stateset of the tile.
 Given you have a texture with the data-image called texture you can do
 it this way in your callback:

 osg::StateSet* state_set = node-getOrCreateStateSet();
 osg::Uniform* sampler = new osg::Uniform(MyDataSamper,  2 /*texture
 unit*/);

 state_set-**setTextureAttribute(unit, texture
 ,osg::StateAttribute::ON);
 state_set-addUniform(sampler)**;

 With this you bind the texture to a sampler for your shader, at the
 texture unit 2. Depending on how many textures are already bound you might
 need to modify the unit.
 In the fragment shader you can now access the texture via:

 uniform sampler2D MyDataSampler
 ..
 ..

 main()
 {
 vec2 tex_coord = gl_TexCoord[0].st;
 vec4 data = texture2D(MyDataSampler, tex_coord);

 }


  Each texel in the new texture, should be set based on the world location
 of the corresponding texel in the current geometry texture. I'm not sure
 how to do that using the geometry vertex and texture coordinate indices.
 I hope this is clear enough.

 This is a different question. If your terrain-data already contains a base
 texture (like a satellite photo), the gl_TexCoord[0] might be matching
 already.
 If not you might want to use texture coordinate generation in the vertex
 shader to get world-space texture coordinates.
 It totally depends on your data.
 For a first try, I'd load a dummy texture for each tile and pass it to the
 gl_FragColor in the fragment shader to see how your coordinates are.

 cheers
 Sebastian


 Thanks for the help,
 Shahar

 --
 Read this topic online here:
 http://forum.openscenegraph.**org/viewtopic.php?p=54810#**54810http://forum.openscenegraph.org/viewtopic.php?p=54810#54810





 __**_
 osg-users mailing list
 osg-users@lists.**openscenegraph.org osg-users@lists.openscenegraph.org
 http://lists.openscenegraph.**org/listinfo.cgi/osg-users-**
 openscenegraph.orghttp://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


 __**_
 osg-users mailing list
 osg-users@lists.**openscenegraph.org osg-users@lists.openscenegraph.org
 http://lists.openscenegraph.**org/listinfo.cgi/osg-users-**
 openscenegraph.orghttp://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org




-- 
trajce nikolov nick
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Passing location-based data to a fragment shader

2013-06-25 Thread Sebastian Messerschmidt

Hi Shahar,

answers below.

Sebastian Messerschmidt wrote:

Hi Shahar Kosti:
As you don't provide any exact numbers I can only guess. But usually I'd
bind one or more textures per tile of paged set.
Depending on your hardware bind of 8192x8192 textures is no problem.
Can you be a bit more specific on how big the set is?

Also for the hidden textures - I don't really get what you mean. My best
guess is, that you mean not displayed.
Therefore write a custom fragment shader and bind the data-textures
along with you diffuse or whatever textures to the stateset of the tile.

As the fragment shader is fully programmable, it is your choice what is
done with the data.

cheers
Sebastian



Hi Sebastian,

Sorry for my late reply, it took me some time to get the data.
One TXP I'm currently looking at, represents a 3000 km² area with texture 
resolution of 5m/pixel. Some areas have better resolution, up to 10 cm/pixel. 
The additional metadata has similar resolution. So obviously wouldn't fit on a 
single texture.
Okay, so the single TXP file represents the whole area? That's kinda 
hard, I thought you have multiple tiles representing parts of your 
complete data set.

Anyways, First of all, your data sets need to be aligned somehow.



Regarding your suggestions, could you elaborate on the bind one or more textures 
per tile of paged set approach?

My current approach (which doesn't work), is to intercept paged nodes using a 
custom ReadFileCallback, which runs a NodeVisitor. The visitor finds all Geode 
objects and then the underlying geometries. I can bind a new texture to these 
geometries, but I'm not sure how to set the values correctly.
You don't really need to bind at a level this deep. Usually if the 
terrain tile is loaded and represent a LOD you want to work with, you 
can simple add your data texture(s) as uniform to the stateset of the tile.
Given you have a texture with the data-image called texture you can do 
it this way in your callback:


osg::StateSet* state_set = node-getOrCreateStateSet();
osg::Uniform* sampler = new osg::Uniform(MyDataSamper,  2 
/*texture unit*/);


state_set-setTextureAttribute(unit, texture ,osg::StateAttribute::ON);
state_set-addUniform(sampler);

With this you bind the texture to a sampler for your shader, at the 
texture unit 2. Depending on how many textures are already bound you 
might need to modify the unit.

In the fragment shader you can now access the texture via:

uniform sampler2D MyDataSampler
..
..

main()
{
vec2 tex_coord = gl_TexCoord[0].st;
vec4 data = texture2D(MyDataSampler, tex_coord);
}



Each texel in the new texture, should be set based on the world location of the 
corresponding texel in the current geometry texture. I'm not sure how to do 
that using the geometry vertex and texture coordinate indices.
I hope this is clear enough.
This is a different question. If your terrain-data already contains a 
base texture (like a satellite photo), the gl_TexCoord[0] might be 
matching already.
If not you might want to use texture coordinate generation in the vertex 
shader to get world-space texture coordinates.

It totally depends on your data.
For a first try, I'd load a dummy texture for each tile and pass it to 
the gl_FragColor in the fragment shader to see how your coordinates are.


cheers
Sebastian


Thanks for the help,
Shahar

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=54810#54810





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Passing location-based data to a fragment shader

2013-06-23 Thread Shahar Kosti

Sebastian Messerschmidt wrote:
 Hi Shahar Kosti:
 As you don't provide any exact numbers I can only guess. But usually I'd 
 bind one or more textures per tile of paged set.
 Depending on your hardware bind of 8192x8192 textures is no problem.
 Can you be a bit more specific on how big the set is?
 
 Also for the hidden textures - I don't really get what you mean. My best 
 guess is, that you mean not displayed.
 Therefore write a custom fragment shader and bind the data-textures 
 along with you diffuse or whatever textures to the stateset of the tile.
 
 As the fragment shader is fully programmable, it is your choice what is 
 done with the data.
 
 cheers
 Sebastian
 


Hi Sebastian,

Sorry for my late reply, it took me some time to get the data. 
One TXP I'm currently looking at, represents a 3000 km² area with texture 
resolution of 5m/pixel. Some areas have better resolution, up to 10 cm/pixel. 
The additional metadata has similar resolution. So obviously wouldn't fit on a 
single texture.

Regarding your suggestions, could you elaborate on the bind one or more 
textures per tile of paged set approach?

My current approach (which doesn't work), is to intercept paged nodes using a 
custom ReadFileCallback, which runs a NodeVisitor. The visitor finds all Geode 
objects and then the underlying geometries. I can bind a new texture to these 
geometries, but I'm not sure how to set the values correctly. 
Each texel in the new texture, should be set based on the world location of the 
corresponding texel in the current geometry texture. I'm not sure how to do 
that using the geometry vertex and texture coordinate indices.
I hope this is clear enough.

Thanks for the help,
Shahar

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=54810#54810





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Passing location-based data to a fragment shader

2013-06-19 Thread Sebastian Messerschmidt

Hi Shahar Kosti:

Hi Sebastian,
Thanks for your response.

What if the data does not fit in a single 2D texture? in the worst case 
scenario, the terrain format would be TXP (i.e. paged) and the additional data 
resolution would be close to the textures resolution.
Is there any way to have a set of hidden textures, and access them in the 
fragment shader?
As you don't provide any exact numbers I can only guess. But usually I'd 
bind one or more textures per tile of paged set.

Depending on your hardware bind of 8192x8192 textures is no problem.
Can you be a bit more specific on how big the set is?

Also for the hidden textures - I don't really get what you mean. My best 
guess is, that you mean not displayed.
Therefore write a custom fragment shader and bind the data-textures 
along with you diffuse or whatever textures to the stateset of the tile.


As the fragment shader is fully programmable, it is your choice what is 
done with the data.


cheers
Sebastian


Shahar


Sebastian Messerschmidt wrote:

Hi Shahar,
If the data is 2D and simply projected to x,y you could use a 2D texture
and sample it per fragment based on generated texture coordinates



--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=54683#54683





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] Passing location-based data to a fragment shader

2013-06-18 Thread Shahar Kosti
Hi all,

I'm trying to combine two data sources in a shader:
 * Terrain model - a large object in OSG or TXP formats.
 * Metadata grid - a data structure that provides additional information for 2D 
coordinates in the terrain (at a certain resolution).

I'd like to use some of the additional metadata values, in a fragment shader 
that runs on the terrain object. In other words, modify each pixel based on an 
additional value from the metadata grid.

I tried to pass the values as vertex attributes: compute the world location of 
each vertex, and set the vertex attribute from the metadata grid. That didn't 
work very well, as the additional data resolution is very high, almost the same 
as the terrain textures, and the vertices are too far apart from each other.

How would you recommend to pass the required data from the application to the 
shader?

Thanks,
Shahar

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=54673#54673





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Passing location-based data to a fragment shader

2013-06-18 Thread Sebastian Messerschmidt

Hi Shahar,

If the data is 2D and simply projected to x,y you could use a 2D texture 
and sample it per fragment based on generated texture coordinates



Hi all,

I'm trying to combine two data sources in a shader:
  * Terrain model - a large object in OSG or TXP formats.
  * Metadata grid - a data structure that provides additional information for 
2D coordinates in the terrain (at a certain resolution).

I'd like to use some of the additional metadata values, in a fragment shader 
that runs on the terrain object. In other words, modify each pixel based on an 
additional value from the metadata grid.

I tried to pass the values as vertex attributes: compute the world location of 
each vertex, and set the vertex attribute from the metadata grid. That didn't 
work very well, as the additional data resolution is very high, almost the same 
as the terrain textures, and the vertices are too far apart from each other.

How would you recommend to pass the required data from the application to the 
shader?

Thanks,
Shahar

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=54673#54673





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Passing location-based data to a fragment shader

2013-06-18 Thread Shahar Kosti
Hi Sebastian,
Thanks for your response.

What if the data does not fit in a single 2D texture? in the worst case 
scenario, the terrain format would be TXP (i.e. paged) and the additional data 
resolution would be close to the textures resolution.
Is there any way to have a set of hidden textures, and access them in the 
fragment shader?

Shahar 


Sebastian Messerschmidt wrote:
 Hi Shahar,
 If the data is 2D and simply projected to x,y you could use a 2D texture 
 and sample it per fragment based on generated texture coordinates
 


--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=54683#54683





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org