Re: [osg-users] Access vertexes of a 3D model in the vertex shader

2014-07-09 Thread Solkar Graphics

Becky wrote:
> Could you tell me what do you mean "define a mapping from vertex numbers to 
> st coordinate"? Could I do like this in the fragment shader?


Hi Becky!

The question of yours I was referring to was

Becky wrote:
> Would someone tell me how to access all the vertexes of a 3d model in the 
> vertex shader? 


Given a model of M vertices, M ∈ I := {0M-1}  you want to encode into a 
d-dimensional texture, you have to define a an (injective, "one-on-one") 
function

I := {0M-1} ⊂ {ℕ+ ∪ {0}}
f:  I -> ℝ^d

and store and retrieve vertex data according to that mapping.

With kind regards, 
S.

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





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


Re: [osg-users] Access vertexes of a 3D model in the vertex shader

2014-07-09 Thread ying song
Hello, 

Could you tell me what do you mean "define a mapping from vertex numbers to st 
coordinate"? Could I do like this in the fragment shader?

gl_TexCoord[0].st = vec2(position.x, position.y);
gl_FragColor = texture2D(myTexture, gl_TexCoord[0].st);

where position is the distorted pixel coordinates.

But how to write the vertex shader?

Thanks!

Cheers,
Ying


Solkar wrote:
> 
> Becky wrote:
> > Would someone tell me how to access all the vertexes of a 3d model in the 
> > vertex shader? 
> 
> 
> Hi Becky!
> 
> You would need to define a mapping from vertex numbers to st coordinates,  
> then store the position data in a texture according to that mapping and 
> provide that texture via a sampler uniform.
> .
> 
> Best regards,
> S.


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





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


Re: [osg-users] Access vertexes of a 3D model in the vertex shader

2014-07-09 Thread ying song
Hi Sebastian,

At first I transformed from the camera coordinate system [Xc,Yc,Zc] to the 
pinhole image projecting system [X=Xc/Zc, Y=Yc/Zc]. Then the distorting is 
processed based [X,Y]. At last, the projection matrix is mutiplied and the 
pixel coordinate is getten in this way.

Since the input are the 3d camera coordinates and the output are the pixel 
coordinates, I wonder could I implement this function using the shaders? Should 
I implement the distortion in the vertex shader or in the fragment shader?

Thank you very much,
Ying 





SMesserschmidt wrote:
> Hi Ying,
> 
> 
> 
> > Hi Sebastian ,
> > 
> > The distortion value is a function of the position, and it's for per 
> > vextex. It won't change over time. To be more details, the distortion 
> > function would calculate pixel coordinates(2d) based on vertex 
> > positions(3d).
> > 
> Okay, I somehow don't understand how this could be useful. Usually 
> distortion doesn't change the domain. So either the distortion maps 2d 
> -> 2d in the pixel domain or 3d vertex positions to 3d vertex positions.
> The 3d -> 2d is usually done by the projection matrix, but you can of 
> course apply any projection function in the vertex shader. Maybe you 
> need to reformulate your question in a way I can understand what you are 
> really after.
> 
> 
> So usually in the vertex shader:
> 
> local vertex position(3d) * ModelViewMatrix -> global vertex position 
> relative to view * ProjectionMatrix -> Eyespace position
> 
> The eyespace then is transformed into 2d coordinates before 
> rasterization (window matrix etc).
> The point is, that you can basically do anything in the vertex shader to 
> change the 2d position of the vertex, but the edges will stay straight 
> lines.
> If you need to do some non-linear distortion per pixel you will have to 
> use the fragment shader to distort the resulting image. This is usually 
> done to perform some projection onto curved surfaces or to model some 
> "fishlens" etc.
> 
> So If you can explain what you are after, we might be able to point you 
> into the right direction how to do it with OSG.
> 
> Cheers
> Sebastian
> 
> 
> 
> > 
> > Now I'm really confused about this problem. I found some tutorials and 
> > sample code about Frame Buffer Object and rendering to texture, but there's 
> > no this kind of functions in these code. Since I don't have much experience 
> > in OpenGL and osg, I'm a little lost now.
> > 
> 
> 
> 
> > 
> > I would be appreciate if you could give me some suggestions :)
> > 
> > Thanks,
> > Ying
> > 
> > 
> > 
> > SMesserschmidt wrote:
> > 
> > > Hi Ying,
> > > 
> > > 
> > > > Hi Sebastian ,
> > > > 
> > > > The distortion will be applied to the 3D model's vertexes. So each 
> > > > vertex will be changed to a different position. I wonder how could I 
> > > > achieve this? Should I use 3D texture, and then applying the distortion 
> > > > to the coordinates of the 3D texture?
> > > > 
> > > > 
> > > I'm aware how distortion work I rather wanted to know if the distortion
> > > value is per vertex and is constant or changes over time.
> > > So we need to know if the distortion is a function of time, vertex
> > > index, position or whatever.
> > > 
> > > Try to describe the problem more in depth so we can get an idea of what
> > > you are trying to achieve.
> > > 
> > > Cheers
> > > Sebastian
> > > 
> > > 
> > > > Thank you for the answer! :)
> > > > 
> > > > Cheers,
> > > > Ying
> > > > 
> > > > --
> > > > Read this topic online here:
> > > > http://forum.openscenegraph.org/viewtopic.php?p=59951#59951
> > > > 
> > > > 
> > > > 
> > > > 
> > > > 
> > > > ___
> > > > osg-users mailing list
> > > > 
> > > > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> > > > 
> > > > 
> > > ___
> > > osg-users mailing list
> > > 
> > > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> > > 
> > > --
> > > Post generated by Mail2Forum
> > > 
> > 
> > --
> > Read this topic online here:
> > http://forum.openscenegraph.org/viewtopic.php?p=60079#60079
> > 
> > 
> > 
> > 
> > 
> > ___
> > osg-users mailing list
> > 
> > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> > 
> 
> ___
> osg-users mailing list
> 
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> 
>  --
> Post generated by Mail2Forum


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





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


Re: [osg-users] Access vertexes of a 3D model in the vertex shader

2014-07-01 Thread Solkar Graphics

Becky wrote:
> Would someone tell me how to access all the vertexes of a 3d model in the 
> vertex shader? 


Hi Becky!

You would need to define a mapping from vertex numbers to st coordinates,  
then store the position data in a texture according to that mapping and provide 
that texture via a sampler uniform.
.

Best regards,
S.

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





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


Re: [osg-users] Access vertexes of a 3D model in the vertex shader

2014-06-30 Thread Sebastian Messerschmidt

Hi Ying,



Hi Sebastian ,

The distortion value is a function of the position, and it's for per vextex. It 
won't change over time. To be more details, the distortion function would 
calculate pixel coordinates(2d) based on vertex positions(3d).
Okay, I somehow don't understand how this could be useful. Usually 
distortion doesn't change the domain. So either the distortion maps 2d 
-> 2d in the pixel domain or 3d vertex positions to 3d vertex positions.
The 3d -> 2d is usually done by the projection matrix, but you can of 
course apply any projection function in the vertex shader. Maybe you 
need to reformulate your question in a way I can understand what you are 
really after.



So usually in the vertex shader:

local vertex position(3d) * ModelViewMatrix -> global vertex position 
relative to view * ProjectionMatrix -> Eyespace position


The eyespace then is transformed into 2d coordinates before 
rasterization (window matrix etc).
The point is, that you can basically do anything in the vertex shader to 
change the 2d position of the vertex, but the edges will stay straight 
lines.
If you need to do some non-linear distortion per pixel you will have to 
use the fragment shader to distort the resulting image. This is usually 
done to perform some projection onto curved surfaces or to model some 
"fishlens" etc.


So If you can explain what you are after, we might be able to point you 
into the right direction how to do it with OSG.


Cheers
Sebastian




Now I'm really confused about this problem. I found some tutorials and sample 
code about Frame Buffer Object and rendering to texture, but there's no this 
kind of functions in these code. Since I don't have much experience in OpenGL 
and osg, I'm a little lost now.





I would be appreciate if you could give me some suggestions :)

Thanks,
Ying



SMesserschmidt wrote:

Hi Ying,


Hi Sebastian ,

The distortion will be applied to the 3D model's vertexes. So each vertex will 
be changed to a different position. I wonder how could I achieve this? Should I 
use 3D texture, and then applying the distortion to the coordinates of the 3D 
texture?


I'm aware how distortion work I rather wanted to know if the distortion
value is per vertex and is constant or changes over time.
So we need to know if the distortion is a function of time, vertex
index, position or whatever.

Try to describe the problem more in depth so we can get an idea of what
you are trying to achieve.

Cheers
Sebastian


Thank you for the answer! :)

Cheers,
Ying

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





___
osg-users mailing list

http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


___
osg-users mailing list

http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

  --
Post generated by Mail2Forum


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





___
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] Access vertexes of a 3D model in the vertex shader

2014-06-30 Thread ying song
Hi Sebastian , 

The distortion value is a function of the position, and it's for per vextex. It 
won't change over time. To be more details, the distortion function would 
calculate pixel coordinates(2d) based on vertex positions(3d). 

Now I'm really confused about this problem. I found some tutorials and sample 
code about Frame Buffer Object and rendering to texture, but there's no this 
kind of functions in these code. Since I don't have much experience in OpenGL 
and osg, I'm a little lost now.

I would be appreciate if you could give me some suggestions :)

Thanks, 
Ying



SMesserschmidt wrote:
> Hi Ying,
> 
> > Hi Sebastian ,
> > 
> > The distortion will be applied to the 3D model's vertexes. So each vertex 
> > will be changed to a different position. I wonder how could I achieve this? 
> > Should I use 3D texture, and then applying the distortion to the 
> > coordinates of the 3D texture?
> > 
> I'm aware how distortion work I rather wanted to know if the distortion 
> value is per vertex and is constant or changes over time.
> So we need to know if the distortion is a function of time, vertex 
> index, position or whatever.
> 
> Try to describe the problem more in depth so we can get an idea of what 
> you are trying to achieve.
> 
> Cheers
> Sebastian
> 
> > 
> > Thank you for the answer! :)
> > 
> > Cheers,
> > Ying
> > 
> > --
> > Read this topic online here:
> > http://forum.openscenegraph.org/viewtopic.php?p=59951#59951
> > 
> > 
> > 
> > 
> > 
> > ___
> > osg-users mailing list
> > 
> > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> > 
> 
> ___
> osg-users mailing list
> 
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> 
>  --
> Post generated by Mail2Forum


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





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


Re: [osg-users] Access vertexes of a 3D model in the vertex shader

2014-06-27 Thread ying song
Hi Sebastian ,

I'm sorry for the confusion.

The distortion value is a function of position, and it's for per vextex. It 
won't changed over time. 

To be more details, the distortion function will calculate the pixel 
coordinates based on the passing vertex positions.

Thanks!
Ying

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





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


Re: [osg-users] Access vertexes of a 3D model in the vertex shader

2014-06-26 Thread Sebastian Messerschmidt

Hi Ying,

Hi Sebastian ,

The distortion will be applied to the 3D model's vertexes. So each vertex will 
be changed to a different position. I wonder how could I achieve this? Should I 
use 3D texture, and then applying the distortion to the coordinates of the 3D 
texture?
I'm aware how distortion work I rather wanted to know if the distortion 
value is per vertex and is constant or changes over time.
So we need to know if the distortion is a function of time, vertex 
index, position or whatever.


Try to describe the problem more in depth so we can get an idea of what 
you are trying to achieve.


Cheers
Sebastian


Thank you for the answer! :)

Cheers,
Ying

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





___
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] Access vertexes of a 3D model in the vertex shader

2014-06-26 Thread ying song
Hi Sebastian ,

The distortion will be applied to the 3D model's vertexes. So each vertex will 
be changed to a different position. I wonder how could I achieve this? Should I 
use 3D texture, and then applying the distortion to the coordinates of the 3D 
texture?

Thank you for the answer! :)

Cheers,
Ying

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





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


Re: [osg-users] Access vertexes of a 3D model in the vertex shader

2014-06-26 Thread Sebastian Messerschmidt

Hi Ying,

This is not possible directly. The vertex shader processes one vertex 
per run.
You could check gl_VertexId [1] if you need to know which vertex is 
being processed in the current run.
Another option is to store the distortion information inside an vertex 
attribute per vertex.
Since you didn't explain what the source of your distortion information 
is we can only guess what you really want here ;-)


Cheers
Sebastian


[1] https://www.opengl.org/sdk/docs/man/html/gl_VertexID.xhtml


Hello,

Would someone tell me how to access all the vertexes of a 3d model in the 
vertex shader?

I want to render a distorted model by chaning the positions of the 3d model's 
vertexes. I tried to use 'gl_Vertex' to access the vertexes, but seems that it 
didn't work.

Hope someone could help me on this.

Thank you!

Cheers,
ying

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





___
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] Access vertexes of a 3D model in the vertex shader

2014-06-26 Thread ying song
Hello,

Would someone tell me how to access all the vertexes of a 3d model in the 
vertex shader? 

I want to render a distorted model by chaning the positions of the 3d model's 
vertexes. I tried to use 'gl_Vertex' to access the vertexes, but seems that it 
didn't work.

Hope someone could help me on this.

Thank you!

Cheers,
ying

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





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