Re: [osg-users] No texture with setUseVertexAttributeAliasing enabled
Hi Daniel, You code is far from compiling and the only thing which is an obvious error is the fact you are not setting up normals for you geometry. Hence there are no normals to be used in the shader and you probably see the texture coordinates. Cheers Sebastian Hi, I tried to fix it with no success, any suggestion? Thanks! -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=60770#60770 ___ 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] No texture with setUseVertexAttributeAliasing enabled
The color of the walls could be texture coordinates as you says, it sounds convincing. But, anyway, I tried adding some normals for testing with following code but it is still not working: Code: osg::Vec3Array *normalArray = new osg::Vec3Array(); normalArray-push_back(osg::Vec3(0.0f,0.0f, 1.0f)); triGeometry1-setNormalArray(normalArray); triGeometry1-setNormalBinding(osg::Geometry::BIND_OVERALL); osg::Vec3Array *normalArray = new osg::Vec3Array(); normalArray-push_back(osg::Vec3(0.0f,0.0f, 1.0f)); triGeometry2-setNormalArray(normalArray); triGeometry2-setNormalBinding(osg::Geometry::BIND_OVERALL); In other hand, I am wondering if I am wrong in the rendering model that I am trying: is it possible for OSG to render a geometry with shaders (e.g.: cow) and another geometry without any shader (e.g.:walls) in the same scene? Or, otherwise I have to render everything with shaders? Best wishes -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=60784#60784 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] No texture with setUseVertexAttributeAliasing enabled
Hi, is it possible for OSG to render a geometry with shaders (e.g.: cow) and another geometry without any shader (e.g.:walls) in the same scene yes. You set your osg::Program with the shaders only for that part of the scene you want to have it in effect, via StateSet, like sceneWIthShaders-getOrCreateStateSet()-setAttribute( myProgram ) Nick On Tue, Aug 26, 2014 at 12:44 PM, Daniel Lobo wolfyl...@gmail.com wrote: The color of the walls could be texture coordinates as you says, it sounds convincing. But, anyway, I tried adding some normals for testing with following code but it is still not working: Code: osg::Vec3Array *normalArray = new osg::Vec3Array(); normalArray-push_back(osg::Vec3(0.0f,0.0f, 1.0f)); triGeometry1-setNormalArray(normalArray); triGeometry1-setNormalBinding(osg::Geometry::BIND_OVERALL); osg::Vec3Array *normalArray = new osg::Vec3Array(); normalArray-push_back(osg::Vec3(0.0f,0.0f, 1.0f)); triGeometry2-setNormalArray(normalArray); triGeometry2-setNormalBinding(osg::Geometry::BIND_OVERALL); In other hand, I am wondering if I am wrong in the rendering model that I am trying: is it possible for OSG to render a geometry with shaders (e.g.: cow) and another geometry without any shader (e.g.:walls) in the same scene? Or, otherwise I have to render everything with shaders? Best wishes -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=60784#60784 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org -- trajce nikolov nick ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] No texture with setUseVertexAttributeAliasing enabled
Thanks Nick for the clarification. In my code I am doing Code: osg::StateSet* shaderState = cowG-getOrCreateStateSet(); ... shaderState-setAttributeAndModes(program, osg::StateAttribute::ON); that seems similar to your suggestion. The weird thing here is that geometries with no shaders seems to stop working fine when calling this method : setUseVertexAttributeAliasing(true); -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=60786#60786 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] No texture with setUseVertexAttributeAliasing enabled
Hi, Thanks Nick for the clarification. In my code I am doing Code: osg::StateSet* shaderState = cowG-getOrCreateStateSet(); ... shaderState-setAttributeAndModes(program, osg::StateAttribute::ON); that seems similar to your suggestion. The weird thing here is that geometries with no shaders seems to stop working fine when calling this method : setUseVertexAttributeAliasing(true); There is nothing weird about this. There is no fixed function pipeline functionality any more at this point. You either use the vertex attribute aliasing skipping fixed function rendering or you use the old way of doing things. I still don't get what you are trying to achieve. Why is the attribute aliasing enabled in the first place? Have you tried loading a osg model and display it with your shader? Cheers Sebastian -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=60786#60786 ___ 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] No texture with setUseVertexAttributeAliasing enabled
Why is the attribute aliasing enabled in the first place? If I am not wrong I have to enable attribute aliasing to use osg_Normals from shaders. Have you tried loading a osg model and display it with your shader? The cow in ScreenShot168.png is rendered with my shader (It is a simple shader just for show normals) I still don't get what you are trying to achieve. I want to draw some walls with textures and a model with shaders. Should I render walls with a shader too? -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=60788#60788 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] No texture with setUseVertexAttributeAliasing enabled
Am 26.08.2014 13:37, schrieb Daniel Lobo: Why is the attribute aliasing enabled in the first place? If I am not wrong I have to enable attribute aliasing to use osg_Normals from shaders. You can use gl_Normals if you use a compatibility profile and no vertex attribute aliasing. You need this only for pure OpenGL 3.0 and beyond. Try to render it with default profile and use a version 120 shader to check with gl_Normals etc. If this works out, you are setting up your geometry correctly. Use debugging and minimal examples to get to the problem and check the examples (in terms of creating geometry, using Core profile and shaders) Have you tried loading a osg model and display it with your shader? The cow in ScreenShot168.png is rendered with my shader (It is a simple shader just for show normals) Looks okay. Still the osg_Normal might default to attribute slot 0, so it I still don't get what you are trying to achieve. I want to draw some walls with textures and a model with shaders. Should I render walls with a shader too? -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=60788#60788 ___ 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] No texture with setUseVertexAttributeAliasing enabled
Looks okay. Still the osg_Normal might default to attribute slot 0, so it I still don't get what you are trying to achieve. I want to draw some walls with textures and a model with shaders. Should I render walls with a shader too? What do you mean with attribute slot 0? -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=60790#60790 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] No texture with setUseVertexAttributeAliasing enabled
Hi, I tried to fix it with no success, any suggestion? Thanks! -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=60770#60770 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] No texture with setUseVertexAttributeAliasing enabled
Hi! I am working with modern Opengl so that I have to use setUseVertexAttributeAliasing(true) to get proper normals in shaders. The problem is that the elements not processed by shaders are not showing their textures. I have found something similar in this topic and it seem pretty much the same problem as mine. viewtopic.php?p=46796#46796 (sorry for this ugly way to link it, but since it is my first post, I cannot include links) I have attached two screenshots to show the effect of setUseVertexAttributeAliasing(true). In this example (both captures), the cow is using a shader to draw raw normals. Thanks! Best wishes, Dani -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=60649#60649 Attachments: http://forum.openscenegraph.org//files/screenshot169_885.png http://forum.openscenegraph.org//files/screenshot168_141.png ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] No texture with setUseVertexAttributeAliasing enabled
Hi Daniel, When using the aliasing, make sure to use osg_Normal etc. instead of gl_ Your post is a bit confusing, as the pictures show normals yet you are talking about textures. A simple minimal example including your shaders might be helpful. Cheers Sebastian Hi! I am working with modern Opengl so that I have to use setUseVertexAttributeAliasing(true) to get proper normals in shaders. The problem is that the elements not processed by shaders are not showing their textures. I have found something similar in this topic and it seem pretty much the same problem as mine. viewtopic.php?p=46796#46796 (sorry for this ugly way to link it, but since it is my first post, I cannot include links) I have attached two screenshots to show the effect of setUseVertexAttributeAliasing(true). In this example (both captures), the cow is using a shader to draw raw normals. Thanks! Best wishes, Dani -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=60649#60649 Attachments: http://forum.openscenegraph.org//files/screenshot169_885.png http://forum.openscenegraph.org//files/screenshot168_141.png ___ 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] No texture with setUseVertexAttributeAliasing enabled
Thanks for your reply! Yes, I am using osg_ suffix instead gl_. The only gl_ variable that I am using is gl_Position, but I think this is OK - correct me if I am wrong. Actually my shader is very simple. I am just trying to draw the raw normals of the cow. The problem with the textures cames with the elements that don't use any shader. In the example, the quads that you can see in the background have a yellow and gray texture respectively don't use any shader. However, If I use setUseVertexAttributeAliasing(true), the quads lose the textures and acquire this weird dark-green-red color. Vertex shader: Code: #version 400 uniform mat4 osg_ModelViewProjectionMatrix; in vec4 osg_Vertex; in vec3 osg_Normal; out vec3 myNormal; void main() { myNormal = osg_Normal; gl_Position = osg_ModelViewProjectionMatrix * osg_Vertex; } Fragment shader: Code: #version 400 in vec3 myNormal; void main() { vec3 nNormal = normalize(myNormal); outColor = vec4(nNormal,1.0); } main code: Code: Geode* drawQuad(osg::Vec3 A, osg::Vec3 B, osg::Vec3 C, osg::Vec3 D, std::string texture_path) { osg::Vec2 tcA(0,0); osg::Vec2 tcB(1,0); osg::Vec2 tcC(1,1); osg::Vec2 tcD(0,1); Geode* geode = new osg::Geode(); //*TRIANGLE 1*// osg::Geometry* triGeometry1 = new osg::Geometry(); //Vertices osg::Vec3Array* triVertices1 = new osg::Vec3Array(); triVertices1-push_back(A); // bottom left triVertices1-push_back(B); // bottom right triVertices1-push_back(D); // top left triGeometry1-setVertexArray( triVertices1 ); //Order osg::DrawElementsUInt* triBase1 = new osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLES, 0); triBase1-push_back(0); triBase1-push_back(1); triBase1-push_back(2); triGeometry1-addPrimitiveSet(triBase1); //Text coord osg::Vec2Array* texcoords1 = new osg::Vec2Array(3); (*texcoords1)[0].set(tcA.x(),tcA.y()); // tex coord for vertex 0 (A) (*texcoords1)[1].set(tcB.x(),tcB.y()); // tex coord for vertex 1 (B) (*texcoords1)[2].set(tcD.x(),tcD.y()); // tex coord for vertex 2 (D) triGeometry1-setTexCoordArray(0,texcoords1); geode-addDrawable(triGeometry1); //*TRIANGLE 2*// osg::Geometry* triGeometry2 = new osg::Geometry(); //Vertices osg::Vec3Array* triVertices2 = new osg::Vec3Array(); triVertices2-push_back(B); // bottom right triVertices2-push_back(C); // top right triVertices2-push_back(D); // top left triGeometry2-setVertexArray( triVertices2 ); //Order osg::DrawElementsUInt* triBase2 = new osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLES, 0); triBase2-push_back(0); triBase2-push_back(1); triBase2-push_back(2); triGeometry2-addPrimitiveSet(triBase2); //Text coord osg::Vec2Array* texcoords2 = new osg::Vec2Array(3); (*texcoords2)[0].set(tcB.x(),tcB.y()); // tex coord for vertex 0 (B) (*texcoords2)[1].set(tcC.x(),tcC.y()); // tex coord for vertex 1 (C) (*texcoords2)[2].set(tcD.x(),tcD.y()); // tex coord for vertex 2 (D) triGeometry2-setTexCoordArray(0,texcoords2); geode-addDrawable(triGeometry2); //TEXTURE// //Load image osg::Image* image = osgDB::readImageFile(texture_path); //Set up texture texture = new osg::Texture2D(image); texture-setDataVariance(osg::Object::DYNAMIC); texture-setInternalFormat(GL_RGBA); texture-setResizeNonPowerOfTwoHint(false); texture-setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR_MIPMAP_LINEAR); texture-setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR); texture-setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_BORDER); texture-setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_BORDER); //Apply texture osg::StateSet* ss = new osg::StateSet(); ss-setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON); geode-setStateSet(ss); return geode; } int main() { osgViewer::Viewer viewer; osg::Group* root = new osg::Group(); root-getOrCreateStateSet()-setMode(GL_LIGHTING, osg::StateAttribute::OFF); root-getOrCreateStateSet()-setMode( GL_CULL_FACE, osg::StateAttribute::ON ); //Set up viewer viewer.setSceneData( root ); osgGA::TrackballManipulator* cm = new osgGA::TrackballManipulator(); viewer.setCameraManipulator(cm); viewer.getCamera()-setClearColor(osg::Vec4(0.0,0.0,0.0,1)); viewer.realize(); //Graphics Context osg::State* state = viewer.getCamera()-getGraphicsContext()-getState(); state-setUseModelViewAndProjectionUniforms(true); state-setUseVertexAttributeAliasing(true); //Build scene /* A,B,C,D are osg::Vec3 */ root-addChild(drawQuad(A,B,C,D,texture1.gif)); root-addChild(drawQuad(E,F,G,Htexture2.gif)); osg::Group* cowG = new osg::Group(); cowG -addChild(osgDB::readNodeFile(cow.osg)); root-addChild(cowG); //Shaders osg::StateSet* shaderState = cowG-getOrCreateStateSet(); osg::Program* program = new osg::Program; osg::Shader* vertexShader = new osg::Shader( osg::Shader::VERTEX ); osg::Shader* fragmentShader = new osg::Shader( osg::Shader::FRAGMENT ); program-addShader( vertexShader ); program-addShader( fragmentShader ); loadShaderSource( vertexShader, Shaders/showNormals.vert ); loadShaderSource(