Re: [osg-users] texture to file

2009-08-27 Thread Engvall Åsa
Try to use 
m_rImage->setInternalTextureFormat(GL_LUMINANCE32F_ARB);  

Åsa

-Ursprungligt meddelande-
Från: osg-users-boun...@lists.openscenegraph.org 
[mailto:osg-users-boun...@lists.openscenegraph.org] För J.P. Delport
Skickat: den 27 augusti 2009 10:50
Till: OpenSceneGraph Users
Ämne: Re: [osg-users] texture to file


Hi,

Peter Wraae Marino wrote:
> Hi osgUsers,
> 
> I'm still battling with the luminance texture to file.
> The problem is I need to save a texture with 32bit floating point 
> value for each pixel in the texture as a file and load it in at a 
> later time. (16bit can also be used if 32bit isn't supported).
> 
> I have tried all these combinations:
> 
> m_rImage = new osg::Image;
> //m_rImage->allocateImage( 1024, 1024, 1, GL_LUMINANCE, GL_BYTE );
> // fails
> //m_rImage->allocateImage( 1024, 1024, 8, GL_LUMINANCE, GL_BYTE );
> // fails
> //m_rImage->allocateImage( 1024, 1024, 24, GL_LUMINANCE, GL_BYTE );   
> // fails
> //m_rImage->allocateImage( 1024, 1024, 16, GL_LUMINANCE, GL_FLOAT );  // fails
> //m_rImage->allocateImage( 1024, 1024, 32, GL_LUMINANCE, GL_FLOAT );  // fails
> //m_rImage->allocateImage( 1024, 1024, 24, GL_LUMINANCE, GL_4_BYTES
> );// fails with crash
> //m_rImage->allocateImage( 1024, 1024, 24, GL_RGB, GL_BYTE ); 
> //
> works ( image 8bit in each RGB )
> //m_rImage->allocateImage( 1024, 1024, 24, GL_RGB, GL_FLOAT );
> //
> works ( image 8bit in each RGB ), but all values zero
> //m_rImage->allocateImage( 1024, 1024, 24, GL_RGB, GL_4_BYTES );  
> //
> fails with crash
> //m_rImage->allocateImage( 1024, 1024, 32, GL_RED, GL_FLOAT );
> //
> works, but fails when writing image to file

mmm, I think the third parameter of allocateImage is the depth, as in for a 3D 
texture, not bit depth. So for a 2D image should always be 1.

jp

--
This message is subject to the CSIR's copyright terms and conditions, e-mail 
legal notice, and implemented Open Document Format (ODF) standard. 
The full disclaimer details can be found at 
http://www.csir.co.za/disclaimer.html.

This message has been scanned for viruses and dangerous content by MailScanner, 
and is believed to be clean.  MailScanner thanks Transtec Computers for their 
support.

___
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] Problem to get textures from a .flt model

2008-06-16 Thread Engvall Åsa
Hi everybody!

I am new to OSG and this is my first posting to OSG users.
I have some problems to retrieve the textures from a .flt model and would like 
to know what I'm doing wrong.

In main, the model is loaded in this way:

osg::Group* Ground = dynamic_cast 

(osgDB::readNodeFile("C:/Program/Multigen-Paradigm/creator_3_2/tutorials/DesktopTutor/Models/arena.flt"));

I use a node visitor to find all geodes in the scenegraph "Ground" and the 
apply function looks like this:

for (unsigned int i=0; igetStateSet();
osg::Texture* Texture = dynamic_cast 
(StateSet->getTextureAttribute(0, osg::StateAttribute::TEXTURE));

--- modify the texture ---
}

The node visitor is executed and counts the drawables, but the function 
getStateSet() returns the null pointer. If I use getOrCreateStateSet() instead, 
an empty StateSet is created. What should I do to retrieve the textures?
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Problem to get textures from a .flt model - resolved

2008-06-17 Thread Engvall Åsa
Thank you for quick answers Brede and John!
I used the option preserveFace and now it works. 

Best regards,
Asa


-Ursprungligt meddelande-
Från: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] För Brede Johansen
Skickat: den 17 juni 2008 09:42
Till: OpenSceneGraph Users
Ämne: Re: [osg-users] Problem to get textures from a .flt model

Hi Åsa,

The OpenFlight face attributes are initially attached to the face geode.  If 
you rely on the original structure of the .flt file you should disable the post 
optimizer in the OpenFlight reader with the reader option preserveFace.

http://www.openscenegraph.org/projects/osg/wiki/Support/KnowledgeBase/OpenFlight

Regards,
Brede


On Tue, Jun 17, 2008 at 8:24 AM, Engvall Åsa <[EMAIL PROTECTED]> wrote:
> Hi everybody!
>
> I am new to OSG and this is my first posting to OSG users.
> I have some problems to retrieve the textures from a .flt model and 
> would like to know what I'm doing wrong.
>
> In main, the model is loaded in this way:
>
> osg::Group* Ground = dynamic_cast
>
> (osgDB::readNodeFile("C:/Program/Multigen-Paradigm/creator_3_2/tutoria
> ls/DesktopTutor/Models/arena.flt"));
>
> I use a node visitor to find all geodes in the scenegraph "Ground" and 
> the apply function looks like this:
>
> for (unsigned int i=0; i {
> osg::StateSet* StateSet = 
> (currentGeode.getDrawable(i))->getStateSet();
> osg::Texture* Texture = dynamic_cast 
> (StateSet->getTextureAttribute(0, osg::StateAttribute::TEXTURE));
>
> --- modify the texture ---
> }
>
> The node visitor is executed and counts the drawables, but the 
> function
> getStateSet() returns the null pointer. If I use getOrCreateStateSet() 
> instead, an empty StateSet is created. What should I do to retrieve 
> the textures?
>
> ___
> 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 mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] camera view matrix problems...

2008-06-23 Thread Engvall Åsa
Hi,

I think you need a matrix that makes a conversion from "Y up" to "Z up". Here 
is some code that I use for setting the camera manually:

osg::Matrixd cameraMatrix;
osg::Matrixd cameraRotation;
osg::Matrixd cameraTrans;

cameraRotation.makeRotate(
osg::DegreesToRadians(0.0), osg::Vec3(0,1,0),   
// roll
osg::DegreesToRadians(-15.0), osg::Vec3(1,0,0), 
// pitch
osg::DegreesToRadians(-90.0), osg::Vec3(0,0,1));
// yaw 

cameraTrans.makeTranslate(-1000, 0, 300);
cameraMatrix = cameraRotation*cameraTrans;

// The view matrix is the inverse of the camera position matrix.
cameraMatrix.invert(cameraMatrix);

// Conversion to OpenGL "Y up" standard.
osg::Matrixd rotationToYUp;
rotationToYUp.makeRotate(-M_PI/2.0, osg::Vec3(1.0, 0.0, 0.0)); 
cameraMatrix = cameraMatrix*rotationToYUp;  
camera->setViewMatrix(cameraMatrix); 

Regards, 
Asa

-Ursprungligt meddelande-
Från: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] För Tueller, Shayne R Civ 
USAF AFMC 519 SMXS/MXDEC
Skickat: den 24 juni 2008 00:22
Till: OpenSceneGraph Users
Ämne: Re: [osg-users] camera view matrix problems...

Paul,

I was assuming that setViewMatrix() behaved the same way as the OpenGL 
modelview matrix, that is, world to eye.

I tried negating the translation part which seems to have moved me to the right 
place but I'm facing straight down on top of my terrain (azimuth view) with my 
orientation setting at (0.0, 0.0, 0.0). When I change the orientation angles to 
something other than 0.0, nothing shows up again. 

I'm confused...

All I want to do is fix my camera position and orientation...heading around z, 
pitch around x, and roll around y. It can't be that hard can it?

-Shayne

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Paul Martz
Sent: Monday, June 23, 2008 4:13 PM
To: 'OpenSceneGraph Users'
Subject: Re: [osg-users] camera view matrix problems...

The OpenGL view matrix is an inverse transform. Try negating the translation.
   -Paul
 




From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Tueller, Shayne R Civ USAF AFMC 519 
SMXS/MXDEC
Sent: Monday, June 23, 2008 3:44 PM
To: osg-users@lists.openscenegraph.org
Subject: [osg-users] camera view matrix problems...



I'm attempting to explicitly set the view matrix for a camera in 
osgViewer. I'm not using viewer->run() so I'm not using the default camera 
manipulator. Here's the code I'm using:

 

osg::Matrixf vm;

vm.setRotate(osg::Quat(0.0, osg::Vec3(0.0, 0.0, 1.0),

   0.0, osg::Vec3(1.0, 
0.0, 0.0),

   0.0, osg::Vec3(0.0, 
1.0, 0.0)));

vm.setTrans(osg::Vec3f(eyex, eyey, eyez));

viewer->getCamera()->setViewMatrix(vm);

 

I'm expecting to see a view of the terrain that is centered around 
(eyex, eyey, eyez) and I see nothing. Can someone tell me what I'm doing wrong 
in the code above?

 

Thanks,

-Shayne

 

P.S. When I use the command:

 

viewer->setViewMatrixAsLookAt() 

 

with the same eye point (with lookat and up vectors), I can see the 
terrain as expected.

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


[osg-users] Varying shader variable /= 0 in vertex shader, is == 0 in fragment shader

2008-11-03 Thread Engvall Åsa
Hi osg-users!

I'm trying to write my first shader, it is a very simple test program which 
sets the color on a sphere. 
The color depends on whether the sphere has moved relative to its position in 
the previous frame.

I use two varying variables, which are set in the vertex shader, see the code 
below. If the sphere has moved, the variable called displacementNDC is /= 0.
Then I expect that it should still be /= 0 in the fragment shader, but by some 
reason the value is == 0.
The other varying variable, "green", does not change when going from vertex 
shader to fragment shader.
(Just for test, I also tried to put the variable called currentPosClip in a 
varying variable. Testing for currentPosClip == 0 in the vertex shader returned 
false, but it returned true in the fragment shader.)

Please, can anybody explain what is happening? Why are the values changing to 
zero?

Regards, 
Asa 

---Vertex shader --
uniform mat4 prevModelViewProjectionMatrix;
varying vec2 displacementNDC;
varying vec4 green; 

void main()
{
// Calculate the previous and current position in clip space.
vec4 currentPosClip = gl_ModelViewProjectionMatrix*gl_Vertex;   // 
Transforms vertex position 
vec4 previousPosClip = prevModelViewProjectionMatrix*gl_Vertex; // from 
object space to clip space.

gl_Position = ftransform(); 

// Calculate displacement in NDC space.
vec2 displacementNDC = currentPosClip.xy/currentPosClip.w - 
previousPosClip.xy/previousPosClip.w;

// If the displacement is zero, varying variable "green" is set to the RGBA 
value for green.
if (displacementNDC == vec2(0,0))   // 
Object has not moved.
green = vec4(0, 1, 0, 0);
else
// Object has moved.
green = vec4(0.0);
}
---End vertex shader --

---Fragment shader --
varying vec2 displacementNDC;
varying vec4 green; 

void main()
{
if (displacementNDC == vec2(0,0))
gl_FragColor = vec4(1,0,0,1) + green;
else
gl_FragColor = vec4(0,0,1,1) + green;
}
---End fragment shader --


When the sphere has moved, the resulting color should be blue. But it becomes 
red.

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


Re: [osg-users] Varying shader variable /= 0 in vertex shader... resolved

2008-11-03 Thread Engvall Åsa
Of course!
Thank you very much! Sometimes it's hard to see such easy things,  I think this 
happens to other people too... Doesn't it? :-)
Getting this answer was a perfect start of the working day. Now I feel very 
happy and will take further steps into the shader world. 
 
Asa



Från: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] För Andreas Lindmark
Skickat: den 3 november 2008 17:31
Till: OpenSceneGraph Users
Ämne: Re: [osg-users] Varying shader variable /= 0 in vertex shader,is == 0 in 
fragment shader


This line:
vec2 displacementNDC = currentPosClip.xy/currentPosClip.w - 
previousPosClip.xy/previousPosClip.w;
should be
displacementNDC = currentPosClip.xy/currentPosClip.w - 
previousPosClip.xy/previousPosClip.w;

Otherwise you will be declaring a new variable with the name displacementNDC 
the main function as scope.

/Andreas


2008/11/3 Engvall Åsa <[EMAIL PROTECTED]>


Hi osg-users! 

I'm trying to write my first shader, it is a very simple test program 
which sets the color on a sphere. 
The color depends on whether the sphere has moved relative to its 
position in the previous frame. 

I use two varying variables, which are set in the vertex shader, see 
the code below. If the sphere has moved, the variable called displacementNDC is 
/= 0.

Then I expect that it should still be /= 0 in the fragment shader, but 
by some reason the value is == 0. 
The other varying variable, "green", does not change when going from 
vertex shader to fragment shader. 
(Just for test, I also tried to put the variable called currentPosClip 
in a varying variable. Testing for currentPosClip == 0 in the vertex shader 
returned false, but it returned true in the fragment shader.)

Please, can anybody explain what is happening? Why are the values 
changing to zero? 

Regards, 
Asa 

---Vertex shader -- 
uniform mat4 prevModelViewProjectionMatrix; 
varying vec2 displacementNDC; 
varying vec4 green; 

void main()
{ 
// Calculate the previous and current position in clip space. 
vec4 currentPosClip = gl_ModelViewProjectionMatrix*gl_Vertex;   
// Transforms vertex position 
vec4 previousPosClip = prevModelViewProjectionMatrix*gl_Vertex; 
// from object space to clip space. 

gl_Position = ftransform(); 

// Calculate displacement in NDC space. 
vec2 displacementNDC = currentPosClip.xy/currentPosClip.w - 
previousPosClip.xy/previousPosClip.w; 

// If the displacement is zero, varying variable "green" is set to 
the RGBA value for green. 
if (displacementNDC == vec2(0,0))   
// Object has not moved. 
green = vec4(0, 1, 0, 0); 
else
// Object has moved. 
green = vec4(0.0); 
} 
---End vertex shader -- 

---Fragment shader -- 
varying vec2 displacementNDC; 
varying vec4 green; 

void main() 
{
if (displacementNDC == vec2(0,0)) 
gl_FragColor = vec4(1,0,0,1) + green; 
else 
gl_FragColor = vec4(0,0,1,1) + green; 
} 
---End fragment shader -- 


When the sphere has moved, the resulting color should be blue. But it 
becomes red. 


___
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] Render to texture problem

2008-11-06 Thread Engvall Åsa
Hi!

I want to render the scene to a texture and use the texture in a shader. The 
texture image is saved to file by a postdraw callback, so I can look at it. I'm 
doing something wrong because the texture becomes all gray.
My scene graph looks like this:

RTT camera  root
   | |
   \/
world

The main viewer looks at the root and the shader program is applied to the root 
stateset. Below is a code snippet.

I would be very grateful if somebody could point out what I'm doing wrong.
Thanks in advance,

Åsa Engvall


// Create a scene texture.
osg::Texture2D* texture = new osg::Texture2D;
texture->setResizeNonPowerOfTwoHint(false);
texture->setTextureSize(traits->width, traits->height);
texture->setInternalFormat(GL_RGBA);
texture->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::NEAREST);
texture->setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::NEAREST);
osg::Image* textureImage = new osg::Image;
textureImage->allocateImage(traits->width, traits->height, 1, GL_RGBA, 
GL_UNSIGNED_BYTE);
texture->setImage(0, textureImage);

// Add program and uniforms to the root's stateset.
osg::StateSet* state = root->getOrCreateStateSet();
state->addUniform(numberOfTimeStepsU);
state->addUniform(timeConstantU);
state->addUniform(frameTimeU);
state->addUniform(sceneTextureU);
state->addUniform(prevModelViewMatrixU);
state->addUniform(prevModelViewProjectionMatrixU);
state->setAttributeAndModes(motionBlurProgram, osg::StateAttribute::ON);
state->setTextureAttributeAndModes(0, texture, osg::StateAttribute::ON);

// Create a camera that renders the scene to a texture.
osg::Camera* RTTcamera = new osg::Camera;
RTTcamera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);  
RTTcamera->setClearColor(osg::Vec4(1,1,1,1));
RTTcamera->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
RTTcamera->setViewport(0, 0, traits->width, traits->height);
RTTcamera->setComputeNearFarMode(osg::Camera::DO_NOT_COMPUTE_NEAR_FAR);
RTTcamera->setRenderOrder(osg::Camera::PRE_RENDER);
RTTcamera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);
RTTcamera->attach(osg::Camera::COLOR_BUFFER, texture);
RTTcamera->addChild(world);
RTTcamera->attach(osg::Camera::COLOR_BUFFER, textureImage);
RTTcamera->setPostDrawCallback(new ScreenShotCallback(traits->width, 
traits->height, *textureImage, GL_RGB, GL_UNSIGNED_BYTE));


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


Re: [osg-users] Render to texture problem

2008-11-07 Thread Engvall Åsa
I thought that the texture must be in RGBA to be used in a shader. The callback 
was just for debugging, so I didn't think so much about the format. Now I have 
changed to RGBA format in the callback too. I have also set the viewer to 
singlethreaded, using this command: 
viewer.setThreadingModel(osgViewer::Viewer::SingleThreaded);
 
Unfortunately, the texture is still gray.

Åsa

-Ursprungligt meddelande-
Från: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] För J.P. Delport
Skickat: den 7 november 2008 08:22
Till: OpenSceneGraph Users
Ämne: Re: [osg-users] Render to texture problem

Hi,

any reason why you have RGBA texture, but RGB in callback?

jp

Engvall Åsa wrote:
> Hi!
> 
> I want to render the scene to a texture and use the texture in a shader. 
> The texture image is saved to file by a postdraw callback, so I can 
> look at it. I'm doing something wrong because the texture becomes all gray.
> 
> My scene graph looks like this:
> 
> RTT camera  root
>| |
>\/
> world
> 
> The main viewer looks at the root and the shader program is applied to 
> the root stateset. Below is a code snippet.
> 
> I would be very grateful if somebody could point out what I'm doing wrong.
> Thanks in advance,
> 
> Åsa Engvall
> 
> 
> // Create a scene texture.
> osg::Texture2D* texture = new osg::Texture2D;
> texture->setResizeNonPowerOfTwoHint(false);
> texture->setTextureSize(traits->width, traits->height); 
> texture->setInternalFormat(GL_RGBA);
> texture->setFilter(osg::Texture2D::MIN_FILTER, 
> texture->osg::Texture2D::NEAREST); 
> texture->setFilter(osg::Texture2D::MAG_FILTER, 
> texture->osg::Texture2D::NEAREST);
> osg::Image* textureImage = new osg::Image;
> textureImage->allocateImage(traits->width, traits->height, 1, GL_RGBA,
> GL_UNSIGNED_BYTE);
> texture->setImage(0, textureImage);
> 
> // Add program and uniforms to the root's stateset.
> osg::StateSet* state = root->getOrCreateStateSet();
> state->addUniform(numberOfTimeStepsU);
> state->addUniform(timeConstantU);
> state->addUniform(frameTimeU);
> state->addUniform(sceneTextureU);
> state->addUniform(prevModelViewMatrixU);
> state->addUniform(prevModelViewProjectionMatrixU);
> state->setAttributeAndModes(motionBlurProgram, 
> state->osg::StateAttribute::ON); setTextureAttributeAndModes(0, 
> state->texture, osg::StateAttribute::ON);
> 
> // Create a camera that renders the scene to a texture.
> osg::Camera* RTTcamera = new osg::Camera;
> RTTcamera->setReferenceFrame(osg::Transform::ABSOLUTE_RF); 
> RTTcamera->setClearColor(osg::Vec4(1,1,1,1));
> RTTcamera->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
> RTTcamera->setViewport(0, 0, traits->width, traits->height); 
> RTTcamera->setComputeNearFarMode(osg::Camera::DO_NOT_COMPUTE_NEAR_FAR)
> RTTcamera->; setRenderOrder(osg::Camera::PRE_RENDER);
> RTTcamera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJ
> RTTcamera->ECT); attach(osg::Camera::COLOR_BUFFER, texture); 
> RTTcamera->addChild(world); attach(osg::Camera::COLOR_BUFFER, 
> RTTcamera->textureImage); setPostDrawCallback(new 
> RTTcamera->ScreenShotCallback(traits->width,
> traits->height, *textureImage, GL_RGB, GL_UNSIGNED_BYTE));
> 
> 
> 
> --
> --
> 
> ___
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.
> org

--
This message is subject to the CSIR's copyright terms and conditions, e-mail 
legal notice, and implemented Open Document Format (ODF) standard. 
The full disclaimer details can be found at 
http://www.csir.co.za/disclaimer.html.

This message has been scanned for viruses and dangerous content by MailScanner, 
and is believed to be clean.  MailScanner thanks Transtec Computers for their 
support.

___
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] Render to texture problem

2008-11-07 Thread Engvall Åsa
No, it isn't. Should it be? 
I tried to draw the scenegraph in my first message, but it's not easy just 
using text. 
If you want more code, please tell me. 

Åsa

-Ursprungligt meddelande-
Från: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] För J.P. Delport
Skickat: den 7 november 2008 09:42
Till: OpenSceneGraph Users
Ämne: Re: [osg-users] Render to texture problem

Hi,

is your RTT camera the child of anything? I'm just guessing without having an 
example to run.

jp

Engvall Åsa wrote:
> I thought that the texture must be in RGBA to be used in a shader. The 
> callback was just for debugging, so I didn't think so much about the 
> format. Now I have changed to RGBA format in the callback too. I have 
> also set the viewer to singlethreaded, using this command: 
> viewer.setThreadingModel(osgViewer::Viewer::SingleThreaded);
>  
> Unfortunately, the texture is still gray.
> 
> Åsa
> 
> -Ursprungligt meddelande-
> Från: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] För J.P. Delport
> Skickat: den 7 november 2008 08:22
> Till: OpenSceneGraph Users
> Ämne: Re: [osg-users] Render to texture problem
> 
> Hi,
> 
> any reason why you have RGBA texture, but RGB in callback?
> 
> jp
> 
> Engvall Åsa wrote:
>> Hi!
>>
>> I want to render the scene to a texture and use the texture in a shader. 
>> The texture image is saved to file by a postdraw callback, so I can 
>> look at it. I'm doing something wrong because the texture becomes all gray.
>>
>> My scene graph looks like this:
>>
>> RTT camera  root
>>| |
>>\/
>> world
>>
>> The main viewer looks at the root and the shader program is applied 
>> to the root stateset. Below is a code snippet.
>>
>> I would be very grateful if somebody could point out what I'm doing wrong.
>> Thanks in advance,
>>
>> Åsa Engvall
>>
>>
>> // Create a scene texture.
>> osg::Texture2D* texture = new osg::Texture2D;
>> texture->setResizeNonPowerOfTwoHint(false);
>> texture->setTextureSize(traits->width, traits->height); 
>> texture->setInternalFormat(GL_RGBA);
>> texture->setFilter(osg::Texture2D::MIN_FILTER,
>> texture->osg::Texture2D::NEAREST);
>> texture->setFilter(osg::Texture2D::MAG_FILTER,
>> texture->osg::Texture2D::NEAREST);
>> osg::Image* textureImage = new osg::Image;
>> textureImage->allocateImage(traits->width, traits->height, 1, 
>> textureImage->GL_RGBA,
>> GL_UNSIGNED_BYTE);
>> texture->setImage(0, textureImage);
>>
>> // Add program and uniforms to the root's stateset.
>> osg::StateSet* state = root->getOrCreateStateSet();
>> state->addUniform(numberOfTimeStepsU);
>> state->addUniform(timeConstantU);
>> state->addUniform(frameTimeU);
>> state->addUniform(sceneTextureU);
>> state->addUniform(prevModelViewMatrixU);
>> state->addUniform(prevModelViewProjectionMatrixU);
>> state->setAttributeAndModes(motionBlurProgram,
>> state->osg::StateAttribute::ON); setTextureAttributeAndModes(0, 
>> state->texture, osg::StateAttribute::ON);
>>
>> // Create a camera that renders the scene to a texture.
>> osg::Camera* RTTcamera = new osg::Camera;
>> RTTcamera->setReferenceFrame(osg::Transform::ABSOLUTE_RF); 
>> RTTcamera->setClearColor(osg::Vec4(1,1,1,1));
>> RTTcamera->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
>> RTTcamera->setViewport(0, 0, traits->width, traits->height);
>> RTTcamera->setComputeNearFarMode(osg::Camera::DO_NOT_COMPUTE_NEAR_FAR
>> RTTcamera->) ; setRenderOrder(osg::Camera::PRE_RENDER);
>> RTTcamera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OB
>> RTTcamera->J ECT); attach(osg::Camera::COLOR_BUFFER, texture); 
>> RTTcamera->addChild(world); attach(osg::Camera::COLOR_BUFFER, 
>> RTTcamera->textureImage); setPostDrawCallback(new 
>> RTTcamera->ScreenShotCallback(traits->width,
>> traits->height, *textureImage, GL_RGB, GL_UNSIGNED_BYTE));
>>
>>
>>
>> -
>> -
>> --
>>
>> ___
>> osg-users mailing list
>> osg-users@lists.openscenegraph.org
>> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.
>> org
> 
> --
> This message is subject to the CSIR's copyright terms and conditions, e-mail 
> legal notice, and implemented Open Document Format (ODF) standard. 

Re: [osg-users] Render to texture problem

2008-11-07 Thread Engvall Åsa
Thank you J P and Andreas! Now it works.

It isn't obvious to me why the RTT camera must be under the viewer. I just 
thought of the viewer as a camera which looks at the scene. Is the viewer more 
like something that collects the pictures from all cameras and make them 
visible to the user?  

Trying to learn more...

Åsa
 

-Ursprungligt meddelande-
Från: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] För J.P. Delport
Skickat: den 7 november 2008 13:47
Till: OpenSceneGraph Users
Ämne: Re: [osg-users] Render to texture problem

I just read quickly, but it seems your camera is still not under the viewer, try

viewer.setSceneData(root);

jp

Engvall Åsa wrote:
> Hi again!
> Now I have changed my scenegraph according to your drawing, and put 
> the RTT camera under a root node, but it still doesn't work.
>  
> This time I attach all the code in my application, hope anybody has 
> time to have a look at it.
>  
> Åsa
>  
> 
> // Create group nodes.
> osg::Group* root = new osg::Group;
> osg::Group* worldParent = new osg::Group;
> osg::Group* world = new osg::Group;
> root->addChild(worldParent);
> worldParent->addChild(world);
> 
> // Create a sphere object.
> osg::Sphere* sphere = new osg::Sphere(osg::Vec3(0, 0, 0), 10);
> osg::ShapeDrawable* sphereDrawable = new osg::ShapeDrawable(sphere);
> sphereDrawable->setColor(osg::Vec4(0, 0, 0, 1));
> osg::Geode* object = new osg::Geode();
> object->addDrawable(sphereDrawable);
> 
> // Create a transform node for the sphere object.
> osg::PositionAttitudeTransform* objectTransform = new 
> osg::PositionAttitudeTransform;
> objectTransform->addChild(object);
> world->addChild(objectTransform);
> 
> // Create a viewer that looks at the world.
> osgViewer::Viewer viewer;
> viewer.setThreadingModel(osgViewer::Viewer::SingleThreaded);
> viewer.setSceneData(worldParent);
> 
> // Create a graphics window.
> osg::ref_ptr traits = new 
> osg::GraphicsContext::Traits;
> traits->x = 100;
> traits->y = 100;
> traits->width = 640;
> traits->height = 480;
> traits->windowDecoration = true;
> traits->doubleBuffer = true;
> traits->sharedContext = 0;
> 
> // Create main camera.
> osg::ref_ptr gc = 
> osg::GraphicsContext::createGraphicsContext(traits.get());
> osg::ref_ptr camera = viewer.getCamera();
> camera->setGraphicsContext(gc.get());
> camera->setViewport(new osg::Viewport(0, 0, traits->width, 
> camera->traits->height));
> GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
> camera->setDrawBuffer(buffer);
> camera->setReadBuffer(buffer);
> camera->setClearColor(osg::Vec4(1,1,1,1));
> 
> // Camera callback for capturing the image.
> osg::Image* image = new osg::Image;
> camera->setPostDrawCallback(new ScreenShotCallback(traits->width,
> traits->height, *image, GL_RGBA, GL_UNSIGNED_BYTE));
> 
> // Create shader objects.
> osg::Shader* motionBlurVertexShader = new 
> osg::Shader(osg::Shader::VERTEX);
> osg::Shader* motionBlurFragmentShader = new 
> osg::Shader(osg::Shader::FRAGMENT);
> motionBlurVertexShader->loadShaderSourceFromFile
>  ("H:/My Documents/Visual Studio
> 2008/Projects/osg_sfunction/osg_sfunction/motionblur.vert");
> motionBlurFragmentShader->loadShaderSourceFromFile
>  ("H:/My Documents/Visual Studio
> 2008/Projects/osg_sfunction/osg_sfunction/motionblur.frag");
> 
> // Add shader objects to a program.
> osg::Program* motionBlurProgram = new osg::Program;
> motionBlurProgram->addShader(motionBlurVertexShader);
> motionBlurProgram->addShader(motionBlurFragmentShader);
> 
> // Define uniforms that will be passed to the shader.
> osg::Uniform* numberOfTimeStepsU = new 
> osg::Uniform("numberOfTimeSteps", int(10));
> osg::Uniform* timeConstantU = new osg::Uniform("timeConstant", 
> float(0.01));
> osg::Uniform* frameTimeU = new osg::Uniform("frameTime", float(0.02));
> osg::Uniform* sceneTextureU = new osg::Uniform("sceneTexture", 0);
> osg::Uniform* prevModelViewMatrixU = new 
> osg::Uniform(osg::Uniform::FLOAT_MAT4, "prevModelViewMatrix");
> osg::Uniform* prevModelViewProjectionMatrixU = new 
> osg::Uniform(osg::Uniform::FLOAT_MAT4, 
> "prevModelViewProjectionMatrix");
> 
> // Create a scene texture.
> osg::Texture2D* texture = new osg::Texture2D;
> texture->setResizeNonPowerOfTwoHint(false);
> texture->setTextureSize(traits->width, traits->height); 
> texture->setInternalFormat(GL_RGBA);
> texture->setFilter(osg::Texture2D::MIN_FILTER, 
> texture->osg::Texture2D::NEAREST); 
> texture->setFilter(osg::Texture2D::MAG_FILTER, 
> texture->osg::

Re: [osg-users] Render to texture problem - resolved

2008-11-07 Thread Engvall Åsa
OK, that sounds logical.
Thank you, bye for now!

Åsa

-Ursprungligt meddelande-
Från: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] För Robert Osfield
Skickat: den 7 november 2008 14:22
Till: OpenSceneGraph Users
Ämne: Re: [osg-users] Render to texture problem

Hi Asa,

On Fri, Nov 7, 2008 at 1:16 PM, Engvall Åsa <[EMAIL PROTECTED]> wrote:
> It isn't obvious to me why the RTT camera must be under the viewer. I just 
> thought of the viewer as a camera which looks at the scene. Is the viewer 
> more like something that collects the pictures from all cameras and make them 
> visible to the user?

It's the viewer that drivers the rendering as part of the
viewer.renderingTraversals() called from the viewer.frame() method.
The viewer can only render what it knows about it, Camera's don't go off 
rendering by themselves.

Robert.
___
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] Render to texture problem

2008-11-07 Thread Engvall Åsa
mera::FRAME_BUFFER_OBJECT);
RTTcamera->attach(osg::Camera::COLOR_BUFFER, texture);
root->addChild(RTTcamera);
RTTcamera->addChild(world);
RTTcamera->attach(osg::Camera::COLOR_BUFFER, textureImage);
RTTcamera->setPostDrawCallback(new ScreenShotCallback(traits->width, 
traits->height, *textureImage, GL_RGBA, GL_UNSIGNED_BYTE));

// Object position in world coordinates.
objectTransform->setPosition(osg::Vec3(-25, 0, 0)); 

// Camera position in world coordinates.
osg::Matrixd cameraMatrix;
osg::Matrixd cameraRotation;
osg::Matrixd cameraTrans;
cameraRotation.makeRotate(osg::DegreesToRadians(0.0), osg::Vec3(0,1,0), // roll
osg::DegreesToRadians(0.0), osg::Vec3(1,0,0), // pitch
osg::DegreesToRadians(0.0), osg::Vec3(0,0,1)); // yaw 
cameraTrans.makeTranslate(0, -500, 0);
cameraMatrix = cameraRotation*cameraTrans;

// The view matrix is the inverse of the camera position matrix.
osg::Matrixd viewMatrix = cameraMatrix.inverse(cameraMatrix);
osg::Matrixd rotationToYUp;// Conversion to OpenGL "Y up" standard.
rotationToYUp.makeRotate(-M_PI/2.0, osg::Vec3(1.0, 0.0, 0.0)); 
viewMatrix = viewMatrix*rotationToYUp; 

// Set view and projection matrices.
camera->setViewMatrix(viewMatrix);
camera->setProjectionMatrixAsPerspective(10., 4.0/3.0, 1., 1000.);
RTTcamera->setViewMatrix(viewMatrix);
RTTcamera->setProjectionMatrixAsPerspective(10., 4.0/3.0, 1., 1000.);

// Create callbacks for updating uniform values.
osg::NodePath np;
np.push_back(objectTransform);
prevModelViewMatrixU->setUpdateCallback(new 
UpdateUniformCallback(UpdateUniformCallback::MODEL_VIEW, np, camera.get()));
prevModelViewProjectionMatrixU->setUpdateCallback(new 
UpdateUniformCallback(UpdateUniformCallback::MODEL_VIEW_PROJECTION, np, 
camera.get()));

// Show first frame.
if (!viewer.isRealized())
{
viewer.realize();
}
viewer.frame();
if (image->data())
{
osgDB::writeImageFile(*image, "h:/temp/blurImage1.bmp");
}
if (textureImage->data())
{
osgDB::writeImageFile(*textureImage, "h:/temp/textureImage1.bmp");
}

// Move the sphere object.
objectTransform->setPosition(osg::Vec3(25, 0, 0)); 

// Show second frame.
viewer.frame();
if (image->data())
{
osgDB::writeImageFile(*image, "h:/temp/blurImage2.bmp");
}
if (textureImage->data())
{
osgDB::writeImageFile(*textureImage, "h:/temp/textureImage2.bmp");
}
while (!viewer.done())
{
viewer.frame();
}





Från: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] För Andreas Lindmark
Skickat: den 7 november 2008 10:33
Till: OpenSceneGraph Users
Ämne: Re: [osg-users] Render to texture problem


The camera has to be somewhere in the scenegraph under the root. 
Something like this:

 Root
 /\
RTTCamera  Node1
 \/
World

Set the uniforms that you currently set at the Root in Node1 instead and they 
will not be used when rendering with the RTTCamera.

/Andreas


2008/11/7 Engvall Åsa <[EMAIL PROTECTED]>


No, it isn't. Should it be?
I tried to draw the scenegraph in my first message, but it's not easy 
just using text.
If you want more code, please tell me.


Åsa

-Ursprungligt meddelande-
Från: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] För J.P. Delport

Skickat: den 7 november 2008 09:42

Till: OpenSceneGraph Users
Ämne: Re: [osg-users] Render to texture problem

Hi,

is your RTT camera the child of anything? I'm just guessing without 
having an example to run.

jp

Engvall Åsa wrote:
> I thought that the texture must be in RGBA to be used in a shader. The
> callback was just for debugging, so I didn't think so much about the
> format. Now I have changed to RGBA format in the callback too. I have
> also set the viewer to singlethreaded, using this command:
> viewer.setThreadingModel(osgViewer::Viewer::SingleThreaded);
>
> Unfortunately, the texture is still gray.
>
> Åsa
>
        > -Ursprungligt meddelande-
> Från: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] För J.P. Delport
> Skickat: den 7 november 2008 08:22
> Till: OpenSceneGraph Users
> Ämne: Re: [osg-users] Render to texture problem
>
> Hi,
>
> any reason why you have RGBA texture, but RGB in callback?
>
> jp
>
> Engvall Åsa wrote:
>> Hi!
>>
>> I want to render the scene to a texture and use the texture in a 
shader.
>> The texture image is saved to file by a postdraw callback, so I can
>> look at it. I'm doing something wrong b

[osg-users] RTT - texture is not what I expected

2008-11-11 Thread Engvall Åsa
Recently, I tried to render the scene to a texture, and after some help I got 
something in the texture. 
Now, I've found that the texture doesn't show the scene but the previous frame. 
With shading and everything. How is that possible?

My scene graph looks like this:

root
/   \
RTTcamera worldParent
\  /
world

The shader is applied to the worldParent and the RTTcamera is pre render. 
I want the RTT camera to see the world "as it is", with no shading, and render 
the scene to a texture. This texture should then be used in the shader.

What am I doing wrong this time??? I would be thankful for any help.

Regards,
Åsa Engvall

-Code---

int main()
{
// Create group nodes.
osg::Group* root = new osg::Group;
osg::Group* worldParent = new osg::Group;
osg::Group* world = new osg::Group;
root->addChild(worldParent);
worldParent->addChild(world);

// Create a sphere object.
osg::Sphere* sphere = new osg::Sphere(osg::Vec3(0, 0, 0), 10);  
osg::ShapeDrawable* sphereDrawable = new osg::ShapeDrawable(sphere);
sphereDrawable->setColor(osg::Vec4(0, 0, 0, 1));

osg::Geode* object = new osg::Geode();
object->addDrawable(sphereDrawable);

// Declare transform nodes for dynamic objects.
osg::PositionAttitudeTransform* objectTransform = new 
osg::PositionAttitudeTransform;
objectTransform->addChild(object);  
world->addChild(objectTransform);

// Create a viewer that looks at the world.
osgViewer::Viewer viewer;
viewer.setThreadingModel(osgViewer::Viewer::SingleThreaded);
viewer.setSceneData(root);

// Create a graphics window.
osg::ref_ptr traits = new 
osg::GraphicsContext::Traits;
traits->x = 100;
traits->y = 100;
traits->width = 640;
traits->height = 480;
traits->windowDecoration = true;
traits->doubleBuffer = true;
traits->sharedContext = 0;

// Attach a camera to the graphics window.
osg::ref_ptr gc = 
osg::GraphicsContext::createGraphicsContext(traits.get());
osg::ref_ptr camera = viewer.getCamera();
camera->setGraphicsContext(gc.get());
camera->setViewport(new osg::Viewport(0, 0, traits->width, 
traits->height));
GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
camera->setDrawBuffer(buffer);
camera->setReadBuffer(buffer);
camera->setClearColor(osg::Vec4(1,1,1,1));

// Camera callback for capturing the image. 
osg::Image* image = new osg::Image; 
camera->setPostDrawCallback(new ScreenShotCallback(traits->width, 
traits->height, *image, GL_RGBA, GL_UNSIGNED_BYTE));

  // Create shader objects.
osg::Shader* motionBlurVertexShader = new 
osg::Shader(osg::Shader::VERTEX);
osg::Shader* motionBlurFragmentShader = new 
osg::Shader(osg::Shader::FRAGMENT);
motionBlurVertexShader->loadShaderSourceFromFile
("H:/My Documents/Visual Studio 
2008/Projects/osg_sfunction/osg_sfunction/motionblur.vert");
motionBlurFragmentShader->loadShaderSourceFromFile
("H:/My Documents/Visual Studio 
2008/Projects/osg_sfunction/osg_sfunction/motionblur.frag");

// Add shader objects to a program.
osg::Program* motionBlurProgram = new osg::Program;
motionBlurProgram->addShader(motionBlurVertexShader);
motionBlurProgram->addShader(motionBlurFragmentShader);

// Define uniforms that will be passed to the shader.
osg::Uniform* numberOfTimeStepsU = new 
osg::Uniform("numberOfTimeSteps", int(10));
osg::Uniform* timeConstantU = new osg::Uniform("timeConstant", 
float(0.01));
osg::Uniform* frameTimeU = new osg::Uniform("frameTime", float(0.02));
osg::Uniform* sceneTextureU = new osg::Uniform("sceneTexture", 0);
osg::Uniform* prevModelViewMatrixU = new 
osg::Uniform(osg::Uniform::FLOAT_MAT4, "prevModelViewMatrix");
osg::Uniform* prevModelViewProjectionMatrixU = new 
osg::Uniform(osg::Uniform::FLOAT_MAT4, "prevModelViewProjectionMatrix");

// Create a scene texture.
osg::Texture2D* texture = new osg::Texture2D;
texture->setResizeNonPowerOfTwoHint(false);
texture->setTextureSize(traits->width, traits->height);
texture->setInternalFormat(GL_RGBA);
texture->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::NEAREST);
texture->setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::NEAREST);
osg::Image* textureImage = new osg::Image;
  textureImage->allocateImage(traits->width, traits->height, 1, GL_RGBA, 
GL_UNSIGNED_B

[osg-users] Problem updating uniforms

2008-12-02 Thread Engvall Åsa
Hi osg-users!

I have a shader attached to a subgraph. The shader uses a uniform which needs 
to be updated in every frame. The uniform is related to the modelviewmatrix, 
and should thus get a different value for every node in the subgraph. 

I have tried to use a osg::Uniform::Callback, but the callback is only called 
for the parent node in the subgraph. 
I think it would work if I declare a uniform for each node, and attach an 
updating callback to each uniform, but there must be a more clever way do to it?

Any help would be appreciated!
Regards, 

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


Re: [osg-users] Problem updating uniforms

2008-12-02 Thread Engvall Åsa
I agree, but what I need in the shader is the modelViewMatrix from the previous 
frame. 
(By the way, it's for creating motion blur.)
What would be the best way to accomplish this?
 
Asa 


-Ursprungligt meddelande-
Från: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] För Robert Osfield
Skickat: den 2 december 2008 14:51
Till: OpenSceneGraph Users
Ämne: Re: [osg-users] Problem updating uniforms

Hi Asa,

I was strongly recommend trying to use compute what you need from variables 
already available to your in the shader, do a per drawable binding of an 
uniform would awkward to implement and provide poor performance.

Please note that you have gl_ModeViewMatrix and osg_ViewMatrix available in 
shaders as well a range of other variables.

Robert.

On Tue, Dec 2, 2008 at 1:47 PM, Engvall Åsa <[EMAIL PROTECTED]> wrote:
> Hi osg-users!
>
> I have a shader attached to a subgraph. The shader uses a uniform 
> which needs to be updated in every frame. The uniform is related to 
> the modelviewmatrix, and should thus get a different value for every 
> node in the subgraph.
>
> I have tried to use a osg::Uniform::Callback, but the callback is only 
> called for the parent node in the subgraph.
> I think it would work if I declare a uniform for each node, and attach 
> an updating callback to each uniform, but there must be a more clever 
> way do to it?
>
> Any help would be appreciated!
> Regards,
>
> Åsa Engvall
>
> ___
> 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 mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Problem updating uniforms

2008-12-02 Thread Engvall Åsa
Thank you, I will do that! 
Asa

-Ursprungligt meddelande-
Från: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] För Robert Osfield
Skickat: den 2 december 2008 15:15
Till: OpenSceneGraph Users
Ämne: Re: [osg-users] Problem updating uniforms

Hi Asa,

Have a look at the osgParticle::PreciptionEffect as it caches the previous 
frames modelview matrix to enable it to compute motion blurr of the rain 
particles.  This is done just for the precipitation effect drawables though.

Robert.

On Tue, Dec 2, 2008 at 2:08 PM, Engvall Åsa <[EMAIL PROTECTED]> wrote:
> I agree, but what I need in the shader is the modelViewMatrix from the 
> previous frame.
> (By the way, it's for creating motion blur.) What would be the best 
> way to accomplish this?
>
> Asa
>
>
> -Ursprungligt meddelande-
> Från: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] För Robert Osfield
> Skickat: den 2 december 2008 14:51
> Till: OpenSceneGraph Users
> Ämne: Re: [osg-users] Problem updating uniforms
>
> Hi Asa,
>
> I was strongly recommend trying to use compute what you need from variables 
> already available to your in the shader, do a per drawable binding of an 
> uniform would awkward to implement and provide poor performance.
>
> Please note that you have gl_ModeViewMatrix and osg_ViewMatrix available in 
> shaders as well a range of other variables.
>
> Robert.
>
> On Tue, Dec 2, 2008 at 1:47 PM, Engvall Åsa <[EMAIL PROTECTED]> wrote:
>> Hi osg-users!
>>
>> I have a shader attached to a subgraph. The shader uses a uniform 
>> which needs to be updated in every frame. The uniform is related to 
>> the modelviewmatrix, and should thus get a different value for every 
>> node in the subgraph.
>>
>> I have tried to use a osg::Uniform::Callback, but the callback is 
>> only called for the parent node in the subgraph.
>> I think it would work if I declare a uniform for each node, and 
>> attach an updating callback to each uniform, but there must be a more 
>> clever way do to it?
>>
>> Any help would be appreciated!
>> Regards,
>>
>> Åsa Engvall
>>
>> ___
>> 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 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 mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] ComputeBoundsVisitor problem

2009-02-11 Thread Engvall Åsa
Hi osg-users!

I want to use a ComputeBoundsVisitor for finding the bounds of an object. The 
object belongs to the class GroundObject, which is derived from osg::Node.
Please have a look at this short function. The visitor is probably not 
executed, and the resulting bounding box is not valid.

void GroundObject::calculateDistanceToGround(void)
{
// Calculate distance from local origin to ground.
osg::ComputeBoundsVisitor cbv;
accept(cbv);
osg::BoundingBox box = cbv.getBoundingBox(); 
if (!box.valid()) ssPrintf("Bounding box is not valid!\n");
_distanceToGround = osg::absolute(box.zMin());
}

What is wrong here? 
Thanks in advance, 

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


Re: [osg-users] ComputeBoundsVisitor problem

2009-02-11 Thread Engvall Åsa
Yes, but I was expecting that the visitor should traverse the graph an find the 
geometry that is below the GroundObject. If I do the same thing on an 
osg::Node, it works. Both the Node and the GroundObject are created using 
readNodeFile. 

Åsa

-Ursprungligt meddelande-
Från: osg-users-boun...@lists.openscenegraph.org 
[mailto:osg-users-boun...@lists.openscenegraph.org] För Simon Hammett
Skickat: den 11 februari 2009 12:51
Till: OpenSceneGraph Users
Ämne: Re: [osg-users] ComputeBoundsVisitor problem

ComputeBoundsVisitor only computes bounds for drawables. ie geometry.

2009/2/11 Engvall Åsa :
> Hi osg-users!
>
> I want to use a ComputeBoundsVisitor for finding the bounds of an object.
> The object belongs to the class GroundObject, which is derived from 
> osg::Node.
>
> Please have a look at this short function. The visitor is probably not 
> executed, and the resulting bounding box is not valid.
>
> void GroundObject::calculateDistanceToGround(void)
> {
> // Calculate distance from local origin to ground.
> osg::ComputeBoundsVisitor cbv;
> accept(cbv);
> osg::BoundingBox box = cbv.getBoundingBox();
> if (!box.valid()) ssPrintf("Bounding box is not valid!\n");
> _distanceToGround = osg::absolute(box.zMin()); }
>
> What is wrong here?
> Thanks in advance,
>
> Åsa Engvall
>
> ___
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.
> org
>
>



--
The truth is out there. Usually in header files.
___
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