Re: [osg-users] Help: wrong ouput from frag shader
Hi, On 18/01/2012 20:24, wang shuiying wrote: Hi, J.P. the camera isn't rendering to a texture. Yes it is. It is just made for you automatically. FBO renders to a texture and the image is read from this texture when you attach it to the camera. I suggest attaching a texture (to the same buffer component as the image), with the exact formats you require to the camera as well. E.g. _OutputTexture = new osg::TextureRectangle; _OutputTexture->setTextureSize(_TextureWidth, _TextureHeight); _OutputTexture->setInternalFormat(GL_RGBA32F_ARB); _OutputTexture->setSourceFormat(GL_RGBA); _OutputTexture->setSourceType(GL_FLOAT); camera->attach(osg::CameraNode::COLOR_BUFFER, _OutputTexture.get()); camera->attach(osg::CameraNode::COLOR_BUFFER, image); rgds jp In my programme, camera is set to be prerender, render target is FRAME_BUFFER_OBJECT, I attach the camera to an image, in order to get the bufferdata via image. the image data type is allocated as GL_FLOAT. Related setup details are listed below. // renderTarget osg::Camera::RenderTargetImplementation renderTargetImplementation; renderTargetImplementation = osg::CameraNode::FRAME_BUFFER_OBJECT; // shader program osg::Program * program = new osg::Program(); program->addShader(osg::Shader::readShaderFile(osg::Shader::FRAGMENT, fragmentShaderPath)); program->addShader(osg::Shader::readShaderFile(osg::Shader::VERTEX, vertexShaderPath)); // image osg::Image * image = new osg::Image(); image->allocateImage((int)XRes, (int)YRes, 1, GL_RGBA, GL_FLOAT); //camera osg::ref_ptr camera(new osg::CameraNode()); camera->setProjectionMatrixAsFrustum(-tan(YawView * math::D2R * 0.5), tan(YawView * math::D2R * 0.5), -tan(PitchView * math::D2R * 0.5), tan(PitchView * math::D2R * 0.5),zNear, zFar); camera->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR); camera->setViewport(0, 0, XRes, YRes); camera->setClearColor(osg::Vec4(1000.0f, 1000.0f, 1000.0f, 1000.0f)); camera->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF); camera->setViewMatrix(osg::Matrix::lookAt(osg::Vec3d(0, 0, 1.0f), osg::Vec3d(-10.0f, 0.0f, 0), osg::Vec3d(0, 0, 1))); camera->setRenderOrder(osg::CameraNode::PRE_RENDER); camera->setRenderTargetImplementation(renderTargetImplementation); camera->attach(osg::CameraNode::COLOR_BUFFER, image); //read out data osg::Vec4f * rgbaData = (osg::Vec4f *) (image->data()); for (int h = 0; h < yRes; h++) { for (int w = 0; w < xRes; w++) { osg::Vec4f cur = rgbaData[xRes * h + w]; cout<<"cur[0]="< To: OpenSceneGraph Users Subject: Re: [osg-users] Help: wrong ouput from frag shader. Message-ID:<4f167093.8090...@csir.co.za> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Hi, what format is the texture you are rendering to? If it is UNSIGNED CHAR then your data would be discretised. e.g. 45/255 = 0.176471 jp On 17/01/2012 21:11, wang shuiying wrote: Hello, when I write gl_FragColor = vec4(0.174977,0,0,1) in Frag shader, then I get through a related image: float Vec4: (0.176471,0,0,1) so why 0.174977 changed into 0.176471? I think there should be no process there after per fragment operations that can change this element in the rendering pipeline. Blend, alphatest and so on are all disenabled. Thank you in advance! Shuiying ___ 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. ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] osgexport for blender?
Hi Cedric, I found on https://github.com/cedricpinson/osgexport/pull/4 a new commit. Is the animation included now and working ? Maia -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=44901#44901 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] osgvolume opacity settings
Change my question. I followed the osgvolume example. I made a bit different to use setImage function. osg::ref_ptr tile = new osgVolume::VolumeTile; osgVolume->addChild(tile.get()); osg::ref_ptr osgImage = new osg::Image; osg::ref_ptr layer = new osgVolume::ImageLayer(osgImage.get()); tile->setLayer(layer.get()); tile->setEventCallback(new osgVolume::PropertyAdjustmentCallback()); osg::ref_ptr ap = new osgVolume::AlphaFuncProperty(0.02f); osg::ref_ptr sd = new osgVolume::SampleDensityProperty(0.05f); osg::ref_ptr tp = new osgVolume::TransparencyProperty(1.0f); osg::ref_ptr cp = new osgVolume::CompositeProperty; cp->addProperty(ap.get()); cp->addProperty(sd.get()); cp->addProperty(tp.get()); layer->addProperty(cp.get()); tile->setVolumeTechnique(new osgVolume::RayTracedTechnique()); tile->setLayer(layer.get()); osgImage->setImage(nx, ny, nz, GL_RGB16F_ARB, GL_RGBA, GL_UNSIGNED_BYTE, (unsigned char*)data, osg::Image::NO_DELETE); My question is about the 4th parameter GL_RGB16F_ARB. It is very difficult to find out how this parameter affect the image. In this method, I am sure rest of other parameters used correctly, so I would like to know more about this parameter. Thanks again for your help. Regards, Clement From: osg-users-boun...@lists.openscenegraph.org [osg-users-boun...@lists.openscenegraph.org] On Behalf Of Robert Osfield [robert.osfi...@gmail.com] Sent: Thursday, 19 January 2012 9:22 AM To: OpenSceneGraph Users Subject: Re: [osg-users] osgvolume opacity settings Hi Clement, I really don't know what is going on at your end, what you are expecting, what you've coded, there is no way I can provide any answers. Robert. On 18 January 2012 17:31, wrote: > HI Robert, > > I replaced the program from coin to osg and I don't know why osg display > the image from the same volume data is different from coin. I think the > problem is on texture format since I changed to use different parameter of > texture format such as GL_RGBA, GL_RGB16F_ARB, GL_RGBA8. The display images > are different. When GL_RGB16F_ARB is used, the colour is closer to I > expected, but I have no idea why the volume body is empty (1st attached > file). When GL_RGBA is used, the body of volume is filled, but the colour is > not sharp enough. I don't know how to set to use the right texture > parameter. Sorry for my worse explanation. Hope this time better. Thanks. > > > Regards, > Clement > > > From: osg-users-boun...@lists.openscenegraph.org > [osg-users-boun...@lists.openscenegraph.org] On Behalf Of Robert Osfield > [robert.osfi...@gmail.com] > Sent: Thursday, 19 January 2012 4:15 AM > To: OpenSceneGraph Users > Subject: Re: [osg-users] osgvolume opacity settings > > Hi Clement, > > I can't work out specifically what you are expecting to happen. What > coin does is something I have no experience with so can't comment on > how you might try to obtain a similar image. > > Robert. > > On 18 January 2012 15:14, wrote: >> Hi Robert, >> >> Thanks for your reply. I found the problem may relate to the texture >> format when called setImage. I attached three images to describe my >> problem. The image texture_GL_RGBA.jpg is used GL_RGBA for the 4th >> parameter in setImage. >> >> eg. osgImage->setImage(nx, ny, nz, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, >> (uint8*)pdisp), osg::Image::NO_DELETE); >> >> >> The image texture_GL_RGB16F_ARB.jpg is used GL_RGB16F_ARB parameter. The >> colour of this image is I expected, but the problem is that this image is no >> body (only surface have colour). If I used GL_RGBA, it can fill in the >> whole volume, but the colour is very light and blur. The last attachment is >> captured from coin3d library and it is my original render library. Now I >> have replaced with osg, so I expect the osg can display the same result as >> coin3d. >> >> From the first two images, do you know which texture format parameter I >> should use? Thanks. >> >> >> Regards, >> Clement >> >> >> From: osg-users-boun...@lists.openscenegraph.org >> [osg-users-boun...@lists.openscenegraph.org] On Behalf Of Robert Osfield >> [robert.osfi...@gmail.com] >> Sent: Monday, 16 January 2012 8:21 PM >> To: OpenSceneGraph Users >> Subject: Re: [osg-users] osgvolume opacity settings >> >> Hi Clement, >> >> On 16 January 2012 06:21, wrote: >>> My application is using osgvolume to display CT data. There is class >>> called CompositeProperty and there are three property classes >>> (AlphaFuncProperty, SampleDensityProperty and TransparencyProperty) as >>> well. I wou
Re: [osg-users] osgvolume opacity settings
Hi Clement, I really don't know what is going on at your end, what you are expecting, what you've coded, there is no way I can provide any answers. Robert. On 18 January 2012 17:31, wrote: > HI Robert, > > I replaced the program from coin to osg and I don't know why osg display > the image from the same volume data is different from coin. I think the > problem is on texture format since I changed to use different parameter of > texture format such as GL_RGBA, GL_RGB16F_ARB, GL_RGBA8. The display images > are different. When GL_RGB16F_ARB is used, the colour is closer to I > expected, but I have no idea why the volume body is empty (1st attached > file). When GL_RGBA is used, the body of volume is filled, but the colour is > not sharp enough. I don't know how to set to use the right texture > parameter. Sorry for my worse explanation. Hope this time better. Thanks. > > > Regards, > Clement > > > From: osg-users-boun...@lists.openscenegraph.org > [osg-users-boun...@lists.openscenegraph.org] On Behalf Of Robert Osfield > [robert.osfi...@gmail.com] > Sent: Thursday, 19 January 2012 4:15 AM > To: OpenSceneGraph Users > Subject: Re: [osg-users] osgvolume opacity settings > > Hi Clement, > > I can't work out specifically what you are expecting to happen. What > coin does is something I have no experience with so can't comment on > how you might try to obtain a similar image. > > Robert. > > On 18 January 2012 15:14, wrote: >> Hi Robert, >> >> Thanks for your reply. I found the problem may relate to the texture >> format when called setImage. I attached three images to describe my >> problem. The image texture_GL_RGBA.jpg is used GL_RGBA for the 4th >> parameter in setImage. >> >> eg. osgImage->setImage(nx, ny, nz, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, >> (uint8*)pdisp), osg::Image::NO_DELETE); >> >> >> The image texture_GL_RGB16F_ARB.jpg is used GL_RGB16F_ARB parameter. The >> colour of this image is I expected, but the problem is that this image is no >> body (only surface have colour). If I used GL_RGBA, it can fill in the >> whole volume, but the colour is very light and blur. The last attachment is >> captured from coin3d library and it is my original render library. Now I >> have replaced with osg, so I expect the osg can display the same result as >> coin3d. >> >> From the first two images, do you know which texture format parameter I >> should use? Thanks. >> >> >> Regards, >> Clement >> >> >> From: osg-users-boun...@lists.openscenegraph.org >> [osg-users-boun...@lists.openscenegraph.org] On Behalf Of Robert Osfield >> [robert.osfi...@gmail.com] >> Sent: Monday, 16 January 2012 8:21 PM >> To: OpenSceneGraph Users >> Subject: Re: [osg-users] osgvolume opacity settings >> >> Hi Clement, >> >> On 16 January 2012 06:21, wrote: >>> My application is using osgvolume to display CT data. There is class >>> called CompositeProperty and there are three property classes >>> (AlphaFuncProperty, SampleDensityProperty and TransparencyProperty) as >>> well. I would like to know more details of those classes and how to apply >>> on osgvolume. I did to follow the example to use those classes, but when I >>> changed the value of SampleDensityProperty from 0.05 to 0.5. Some CT data >>> are disappear, so I would like to know more how to control property values. >>> Many thanks. >> >> AlphaFuncProperty is equivalent to glAlphaFunc and sets the alpha >> value below which fragments will be discarded >> >> TransparencyProperty is an alpha value multiplier that you can use to >> make your volume more transparent. >> >> SampleDensityProperty controls the size of the step during the ray >> tracing through the volume, the lower the value >> the more samples, the higher the value the less the samples. If you >> use a value of 0.5 you'll only get 3 samples which clearly won't be >> enough! >> >> 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 >> > ___ > 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] Help: wrong ouput from frag shader
Hi, J.P. the camera isn't rendering to a texture. In my programme, camera is set to be prerender, render target is FRAME_BUFFER_OBJECT, I attach the camera to an image, in order to get the bufferdata via image. the image data type is allocated as GL_FLOAT. Related setup details are listed below. // renderTarget osg::Camera::RenderTargetImplementation renderTargetImplementation; renderTargetImplementation = osg::CameraNode::FRAME_BUFFER_OBJECT; // shader program osg::Program * program = new osg::Program(); program->addShader(osg::Shader::readShaderFile(osg::Shader::FRAGMENT, fragmentShaderPath)); program->addShader(osg::Shader::readShaderFile(osg::Shader::VERTEX, vertexShaderPath)); // image osg::Image * image = new osg::Image(); image->allocateImage((int)XRes, (int)YRes, 1, GL_RGBA, GL_FLOAT); //camera osg::ref_ptr camera(new osg::CameraNode()); camera->setProjectionMatrixAsFrustum(-tan(YawView * math::D2R * 0.5), tan(YawView * math::D2R * 0.5), -tan(PitchView * math::D2R * 0.5), tan(PitchView * math::D2R *0.5),zNear, zFar); camera->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR); camera->setViewport(0, 0, XRes, YRes); camera->setClearColor(osg::Vec4(1000.0f, 1000.0f, 1000.0f, 1000.0f)); camera->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF); camera->setViewMatrix(osg::Matrix::lookAt(osg::Vec3d(0, 0, 1.0f), osg::Vec3d(-10.0f, 0.0f, 0), osg::Vec3d(0, 0, 1))); camera->setRenderOrder(osg::CameraNode::PRE_RENDER); camera->setRenderTargetImplementation(renderTargetImplementation); camera->attach(osg::CameraNode::COLOR_BUFFER, image); //read out data osg::Vec4f * rgbaData = (osg::Vec4f *) (image->data()); for (int h = 0; h < yRes; h++) { for (int w = 0; w < xRes; w++) { osg::Vec4f cur = rgbaData[xRes * h + w]; cout<<"cur[0]="< } } Thank you for any advice! Shuiying Message: 3 Date: Wed, 18 Jan 2012 09:11:15 +0200 From: "J.P. Delport" To: OpenSceneGraph Users Subject: Re: [osg-users] Help: wrong ouput from frag shader. Message-ID:<4f167093.8090...@csir.co.za> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Hi, what format is the texture you are rendering to? If it is UNSIGNED CHAR then your data would be discretised. e.g. 45/255 = 0.176471 jp On 17/01/2012 21:11, wang shuiying wrote: Hello, when I write gl_FragColor = vec4(0.174977,0,0,1) in Frag shader, then I get through a related image: float Vec4: (0.176471,0,0,1) so why 0.174977 changed into 0.176471? I think there should be no process there after per fragment operations that can change this element in the rendering pipeline. Blend, alphatest and so on are all disenabled. Thank you in advance! Shuiying ___ 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] osgvolume opacity settings
HI Robert, I replaced the program from coin to osg and I don't know why osg display the image from the same volume data is different from coin. I think the problem is on texture format since I changed to use different parameter of texture format such as GL_RGBA, GL_RGB16F_ARB, GL_RGBA8. The display images are different. When GL_RGB16F_ARB is used, the colour is closer to I expected, but I have no idea why the volume body is empty (1st attached file). When GL_RGBA is used, the body of volume is filled, but the colour is not sharp enough. I don't know how to set to use the right texture parameter. Sorry for my worse explanation. Hope this time better. Thanks. Regards, Clement From: osg-users-boun...@lists.openscenegraph.org [osg-users-boun...@lists.openscenegraph.org] On Behalf Of Robert Osfield [robert.osfi...@gmail.com] Sent: Thursday, 19 January 2012 4:15 AM To: OpenSceneGraph Users Subject: Re: [osg-users] osgvolume opacity settings Hi Clement, I can't work out specifically what you are expecting to happen. What coin does is something I have no experience with so can't comment on how you might try to obtain a similar image. Robert. On 18 January 2012 15:14, wrote: > Hi Robert, > > Thanks for your reply. I found the problem may relate to the texture > format when called setImage. I attached three images to describe my problem. > The image texture_GL_RGBA.jpg is used GL_RGBA for the 4th parameter in > setImage. > > eg. osgImage->setImage(nx, ny, nz, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, > (uint8*)pdisp), osg::Image::NO_DELETE); > > > The image texture_GL_RGB16F_ARB.jpg is used GL_RGB16F_ARB parameter. The > colour of this image is I expected, but the problem is that this image is no > body (only surface have colour). If I used GL_RGBA, it can fill in the whole > volume, but the colour is very light and blur. The last attachment is > captured from coin3d library and it is my original render library. Now I > have replaced with osg, so I expect the osg can display the same result as > coin3d. > > From the first two images, do you know which texture format parameter I > should use? Thanks. > > > Regards, > Clement > > > From: osg-users-boun...@lists.openscenegraph.org > [osg-users-boun...@lists.openscenegraph.org] On Behalf Of Robert Osfield > [robert.osfi...@gmail.com] > Sent: Monday, 16 January 2012 8:21 PM > To: OpenSceneGraph Users > Subject: Re: [osg-users] osgvolume opacity settings > > Hi Clement, > > On 16 January 2012 06:21, wrote: >> My application is using osgvolume to display CT data. There is class >> called CompositeProperty and there are three property classes >> (AlphaFuncProperty, SampleDensityProperty and TransparencyProperty) as well. >> I would like to know more details of those classes and how to apply on >> osgvolume. I did to follow the example to use those classes, but when I >> changed the value of SampleDensityProperty from 0.05 to 0.5. Some CT data >> are disappear, so I would like to know more how to control property values. >> Many thanks. > > AlphaFuncProperty is equivalent to glAlphaFunc and sets the alpha > value below which fragments will be discarded > > TransparencyProperty is an alpha value multiplier that you can use to > make your volume more transparent. > > SampleDensityProperty controls the size of the step during the ray > tracing through the volume, the lower the value > the more samples, the higher the value the less the samples. If you > use a value of 0.5 you'll only get 3 samples which clearly won't be > enough! > > 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 > ___ 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] osgvolume opacity settings
Hi Clement, I can't work out specifically what you are expecting to happen. What coin does is something I have no experience with so can't comment on how you might try to obtain a similar image. Robert. On 18 January 2012 15:14, wrote: > Hi Robert, > > Thanks for your reply. I found the problem may relate to the texture > format when called setImage. I attached three images to describe my problem. > The image texture_GL_RGBA.jpg is used GL_RGBA for the 4th parameter in > setImage. > > eg. osgImage->setImage(nx, ny, nz, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, > (uint8*)pdisp), osg::Image::NO_DELETE); > > > The image texture_GL_RGB16F_ARB.jpg is used GL_RGB16F_ARB parameter. The > colour of this image is I expected, but the problem is that this image is no > body (only surface have colour). If I used GL_RGBA, it can fill in the whole > volume, but the colour is very light and blur. The last attachment is > captured from coin3d library and it is my original render library. Now I > have replaced with osg, so I expect the osg can display the same result as > coin3d. > > From the first two images, do you know which texture format parameter I > should use? Thanks. > > > Regards, > Clement > > > From: osg-users-boun...@lists.openscenegraph.org > [osg-users-boun...@lists.openscenegraph.org] On Behalf Of Robert Osfield > [robert.osfi...@gmail.com] > Sent: Monday, 16 January 2012 8:21 PM > To: OpenSceneGraph Users > Subject: Re: [osg-users] osgvolume opacity settings > > Hi Clement, > > On 16 January 2012 06:21, wrote: >> My application is using osgvolume to display CT data. There is class >> called CompositeProperty and there are three property classes >> (AlphaFuncProperty, SampleDensityProperty and TransparencyProperty) as well. >> I would like to know more details of those classes and how to apply on >> osgvolume. I did to follow the example to use those classes, but when I >> changed the value of SampleDensityProperty from 0.05 to 0.5. Some CT data >> are disappear, so I would like to know more how to control property values. >> Many thanks. > > AlphaFuncProperty is equivalent to glAlphaFunc and sets the alpha > value below which fragments will be discarded > > TransparencyProperty is an alpha value multiplier that you can use to > make your volume more transparent. > > SampleDensityProperty controls the size of the step during the ray > tracing through the volume, the lower the value > the more samples, the higher the value the less the samples. If you > use a value of 0.5 you'll only get 3 samples which clearly won't be > enough! > > 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 > ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Help: wrong ouput from frag shader.
tryFrag_Color = vec4(abs(dist2/100.0),0,0,1) instead of Frag_Color = vec4(abs(dist2/100),0,0,1); Hello, Sebastian There is also another strange problem . When Vertex shader is as follows: varying out vec3 pos; varying out float dist2; void main() { vec3 pos1 = (gl_ModelViewMatrix * (gl_Vertex - vec4(0.0,0.0,0.0,0.0))).xyz; dist2= length(pos1) gl_Position = ftransform(); } Frag shader is as follows: varying in vec3 pos; varying in float dist2; out vec4 Frag_Color; void main() { Frag_Color = vec4(abs(dist2/100),0,0,1); } Then when Frag_color is read via Image, the output is: 0,0,0,1 While in my programme, the dist2 should be equal to for some fragments 0.18 , for other fragments 0.56 and for still others not available because no geometry covers those fragments. But when the shader is written like this: vertex shader: varying out vec3 pos; void main() { pos = (gl_ModelViewMatrix * (gl_Vertex - vec4(0.0,0.0,0.0,0.0))).xyz; gl_Position = ftransform(); } Fragment shader: varying in vec3 pos; out vec4 Frag_Color; void main() { float dist2= length(pos); Frag_Color = vec4(abs(dist2/100),0,0,1); } Then when Frag_color is read via Image, the output is: 0.188235,0,0,1 0.560784,0,0,1 so this time it works! I really cannot figure out why this happens! Thank you very much in advance for any advice! Shuiying On 01/18/2012 08:11 AM, Sebastian Messerschmidt wrote: I suppose you are using a normal framebuffer. I this case it is pretty normal, that your original value that is in the image (you unfortunately didn't tell use if the value comes from a texture) doesn't exactly match the value in the framebuffer. Usually the framebuffer has 8bit per color channel, which makes the value of 0.174977 not representable. If you need the "exact" value to be in the framebuffer you'll have to render it to a floating point buffer via RTT. Also you didn't tell us how you got the result value. There is also the possibility that you read an interpolated/filtered value. If you provide a bit more context someone might be able to help you with your problem Hello, when I write gl_FragColor = vec4(0.174977,0,0,1) in Frag shader, then I get through a related image: float Vec4: (0.176471,0,0,1) so why 0.174977 changed into 0.176471? I think there should be no process there after per fragment operations that can change this element in the rendering pipeline. Blend, alphatest and so on are all disenabled. Thank you in advance! Shuiying ___ 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] Help: wrong ouput from frag shader.
Hello, Sebastian There is also another strange problem . When Vertex shader is as follows: varying out vec3 pos; varying out float dist2; void main() { vec3 pos1 = (gl_ModelViewMatrix * (gl_Vertex - vec4(0.0,0.0,0.0,0.0))).xyz; dist2= length(pos1) gl_Position = ftransform(); } Frag shader is as follows: varying in vec3 pos; varying in float dist2; out vec4 Frag_Color; void main() { Frag_Color = vec4(abs(dist2/100),0,0,1); } Then when Frag_color is read via Image, the output is: 0,0,0,1 While in my programme, the dist2 should be equal to for some fragments 0.18 , for other fragments 0.56 and for still others not available because no geometry covers those fragments. But when the shader is written like this: vertex shader: varying out vec3 pos; void main() { pos = (gl_ModelViewMatrix * (gl_Vertex - vec4(0.0,0.0,0.0,0.0))).xyz; gl_Position = ftransform(); } Fragment shader: varying in vec3 pos; out vec4 Frag_Color; void main() { float dist2= length(pos); Frag_Color = vec4(abs(dist2/100),0,0,1); } Then when Frag_color is read via Image, the output is: 0.188235,0,0,1 0.560784,0,0,1 so this time it works! I really cannot figure out why this happens! Thank you very much in advance for any advice! Shuiying On 01/18/2012 08:11 AM, Sebastian Messerschmidt wrote: I suppose you are using a normal framebuffer. I this case it is pretty normal, that your original value that is in the image (you unfortunately didn't tell use if the value comes from a texture) doesn't exactly match the value in the framebuffer. Usually the framebuffer has 8bit per color channel, which makes the value of 0.174977 not representable. If you need the "exact" value to be in the framebuffer you'll have to render it to a floating point buffer via RTT. Also you didn't tell us how you got the result value. There is also the possibility that you read an interpolated/filtered value. If you provide a bit more context someone might be able to help you with your problem Hello, when I write gl_FragColor = vec4(0.174977,0,0,1) in Frag shader, then I get through a related image: float Vec4: (0.176471,0,0,1) so why 0.174977 changed into 0.176471? I think there should be no process there after per fragment operations that can change this element in the rendering pipeline. Blend, alphatest and so on are all disenabled. Thank you in advance! Shuiying ___ 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] Help:what is openGl shader version 140?
Hello Sebastian, You are right. I have other errors in the shader when such warnings happened. After I correct them, it works normal! Thank you very much for the explanation! Shuiying On 01/18/2012 08:04 AM, Sebastian Messerschmidt wrote: Hello shuiying, either your card doesn't support glsl version 1.40 or you might have some other error in the shader. GLSL comes in different versions that are (AFAIK) defined by the GPU Architecture/Driver and Base OpenGL version. I had such warning sometimes if there was another problem in the shader, so maybe post the entire shader here or on opengl.org. cheers Sebastian Hello, my shader compile stage throws out such warnings: 0(8) : warning C7532: global type sampler2DRect requires "#version 140" or later 0(8) : warning C: ... or #extension GL_ARB_texture_rectangle : enable and Then I add #version 140 #extension GL_ARB_texture_rectangle : enable at the very head of the shader file, but the warnings remain. So how can I check whether my programm is able to use #version 140 #extension GL_ARB_texture_rectangle : enable ? Thank you very much in advance. ___ 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] Help: wrong ouput from frag shader.
Hello, Sebastian Thank you for your reply! In my programme, camera is set to be prerender, render target is FRAME_BUFFER_OBJECT, I attach the camera to an image, in order to get the bufferdata via image. (1) the fragment shader is as following: out vec4 Frag_Color; void main() { Frag_Color = vec4(a,b,c,d); } a,b,c,d can be replaced by any number between 0~1 examples of the inaccuracy of data output are as following: set in Frag shader-> data read via image 0.5 ->0.556863 0.174 -> 0.172549 0.17 -> 0.168627 0.99 -> 0.988235 Frag_Color = vec4(0.2,0.3,0.4,0.5) -> cur[0]=0.2,cur[1]=0.298039,cur[2]=0.4,cur[3]=0.498039 Frag_Color = vec4(0.1,0.6,0.7,0.8) -> cur[0]=0.0980392,cur[1]=0.6,cur[2]=0.698039,cur[3]=0.8 Frag_Color = vec4(0.9,0.66,0.77,0.88) -> cur[0]=0.898039,cur[1]=0.658824,cur[2]=0.768627,cur[3]=0.878431 (2)The camera setup details are listed below. // renderTarget osg::Camera::RenderTargetImplementation renderTargetImplementation; renderTargetImplementation = osg::CameraNode::FRAME_BUFFER_OBJECT; // shader program osg::Program * program = new osg::Program(); program->addShader(osg::Shader::readShaderFile(osg::Shader::FRAGMENT, fragmentShaderPath)); program->addShader(osg::Shader::readShaderFile(osg::Shader::VERTEX, vertexShaderPath)); // image osg::Image * image = new osg::Image(); image->allocateImage((int)XRes, (int)YRes, 1, GL_RGBA, GL_FLOAT); //camera osg::ref_ptr camera(new osg::CameraNode()); camera->setProjectionMatrixAsFrustum(-tan(YawView * math::D2R * 0.5), tan(YawView * math::D2R * 0.5), -tan(PitchView * math::D2R * 0.5), tan(PitchView * math::D2R *0.5),zNear, zFar); camera->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR); camera->setViewport(0, 0, XRes, YRes); camera->setClearColor(osg::Vec4(1000.0f, 1000.0f, 1000.0f, 1000.0f)); camera->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF); camera->setViewMatrix(osg::Matrix::lookAt(osg::Vec3d(0, 0, 1.0f), osg::Vec3d(-10.0f, 0.0f, 0), osg::Vec3d(0, 0, 1))); camera->setRenderOrder(osg::CameraNode::PRE_RENDER); camera->setRenderTargetImplementation(renderTargetImplementation); camera->attach(osg::CameraNode::COLOR_BUFFER, image); //read out data osg::Vec4f * rgbaData = (osg::Vec4f *) (image->data()); for (int h = 0; h < yRes; h++) { for (int w = 0; w < xRes; w++) { osg::Vec4f cur = rgbaData[xRes * h + w]; cout<<"cur[0]="< } } Thank you very much for any advice! Shuiying On 01/18/2012 08:11 AM, Sebastian Messerschmidt wrote: I suppose you are using a normal framebuffer. I this case it is pretty normal, that your original value that is in the image (you unfortunately didn't tell use if the value comes from a texture) doesn't exactly match the value in the framebuffer. Usually the framebuffer has 8bit per color channel, which makes the value of 0.174977 not representable. If you need the "exact" value to be in the framebuffer you'll have to render it to a floating point buffer via RTT. Also you didn't tell us how you got the result value. There is also the possibility that you read an interpolated/filtered value. If you provide a bit more context someone might be able to help you with your problem Hello, when I write gl_FragColor = vec4(0.174977,0,0,1) in Frag shader, then I get through a related image: float Vec4: (0.176471,0,0,1) so why 0.174977 changed into 0.176471? I think there should be no process there after per fragment operations that can change this element in the rendering pipeline. Blend, alphatest and so on are all disenabled. Thank you in advance! Shuiying ___ 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] Place axes at corner
Hi Clement, On 18 January 2012 04:21, wrote: > The example is not quite suitable on my case because my application is > running on MFC window, but I still got some idea from the example to locate > the axes on corner. It doesn't matter whether you are using MFC or the OSG's native windows, osghude usage will work fine with both. > I created a camera for axes geometry and then added as slave to view, but > the axes cannot be rotated. Do you know the reason? I want the axes can be > rotated when the volume data is rotated, but I would like to keep its size. > I mean the size of the axes is not changed when using mouse to zoom the > volume data. Is it possible? And any hence to do it . Many thanks. With a axis like you describe you'll need to compute the rotation of the main view's camera and then apply this to axis's camera. Robert. ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org