instantreality forum
news: Welcome to the instantreality forums!
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
January 17, 2018, 02:30:59 am


Login with username, password and session length


Pages: [1]
  Print  
Author Topic: get viewer position for shader  (Read 4250 times)
settgast
Newbie
*
Posts: 19


View Profile
« on: August 11, 2010, 08:38:31 am »

Hi,

I think, this is really simple:


How do I get the position of the current camera and route it to a shader?


I already tried to get the position of the navigator, but failed to set up the viewpoint correctly (at least I guess):

<Scene DEF='scene'>         
    <Viewpoint DEF='viewRT'/>
....


<ComposedShader DEF='shader'>
            <field accessType='inputOutput' name='view_position' type='SFVec3f' value='0.7 0.7 0.7'/>

....


<ROUTE fromNode='viewRT' fromField='..?.position.?..' toNode='shader' toField='view_position' />


Cheers,
Volker
Logged
yjung
Administrator
Sr. Member
*****
Posts: 260


View Profile
« Reply #1 on: August 11, 2010, 05:21:00 pm »

Hi Volker,

you can e.g. use the Viewpoint's transformation_request outslot and route it to a MatrixDecomposer for getting the position and orientation.

Bye
Yvonne

P.S.: Wieder gut heimgekommen?
Logged
settgast
Newbie
*
Posts: 19


View Profile
« Reply #2 on: August 12, 2010, 01:24:45 pm »

Ah, thank You! It _is_ simple :-)

Best regards,
Volker

PS: Danke, gut zurück und dann hatte ich noch eine Woche Urlaub. Ich hoffe, Ihr seid auch alle gut nach Darmstadt zurück!
Logged
vaifrax
Newbie
*
Posts: 11


View Profile
« Reply #3 on: July 14, 2011, 12:30:35 pm »

I have a related question. I want to pass the eye position in world coordinates to my shader, in a stereo setup. I can compute the offset manually, but how do I know/make a distinction whether currently rendering for the right or left eye?

One hack might be to try and analyze the perspective matrix, but I'm sure there is a better way.
Logged
kschwenk
Administrator
Newbie
*****
Posts: 11


View Profile
« Reply #4 on: July 20, 2011, 10:04:56 am »

Not tested but:
There are a few special shader parameters that are filled in by the system.
Their names start with 'OSG'. If you declare parameters with these names, they should automatically have the correct values in the shader.
Here are a few examples:

Code:
        <ComposedShader DEF='ComposedShader'>
          <field accessType='inputOutput' name='OSGWorldMatrix' type='SFMatrix4f' value='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0'/>
          <field accessType='inputOutput' name='OSGInvViewMatrix' type='SFMatrix4f' value='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0'/>
          <field accessType='inputOutput' name='OSGStereoLeftEye' type='SFInt32' value='-1'/>
          <field accessType='inputOutput' name='OSGCameraPosition' type='SFVec3f' value='0 0 0'/>

Logged
kschwenk
Administrator
Newbie
*****
Posts: 11


View Profile
« Reply #5 on: July 20, 2011, 10:08:35 am »

Oh, and to answer your question:
OSGStereoLeftEye is
-1 for mono
1 for left eye
0 for right eye
Logged
vaifrax
Newbie
*
Posts: 11


View Profile
« Reply #6 on: July 21, 2011, 05:16:20 pm »

thank you, I tested OSGCameraPosition in the CAVE and it works!

Now the my whole JavaScript is not necessary any more.

Browsing the web for the keyword reveals some more variables and source code, very handy:
http://www.opensg.org/doxygen/classOSG_1_1ShaderVariableOSG.html

In case there is a better documentation, please send the link.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.15 | SMF © 2011, Simple Machines