Re: [osg-users] Tearing hair out over simple GLSL instancing

2016-12-30 Thread Andrew Cunningham
Yup that's what I found I had to do . I created a fragment shader and did the basic lighting. I assume I could do that in the vertex shader as well. Thanks for confirming. -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=69809#69809

Re: [osg-users] Tearing hair out over simple GLSL instancing

2016-12-30 Thread Christian Buchner
Does your vertex shader code perform any lighting calculations? I remember that in my instancing vertex shader code I had to explicitly perform required lighting calculations for ambient, diffuse, specular components (the usual Blinn-Phong lighting equations) and set the vertex colors

Re: [osg-users] Tearing hair out over simple GLSL instancing

2016-12-29 Thread Andrew Cunningham
Hi guys, Can you help me out with this one more time:) As I said, I am now able to draw my geometry ( a simple square) using hardware instancing. It works perfectly with excellent performance for millions of squares- except for one thing. Now I want to light the squares. I have turned on

Re: [osg-users] Tearing hair out over simple GLSL instancing

2016-12-22 Thread Andrew Cunningham
Thanks for the help I got it working by adding this to the StateSet osg::VertexAttribDivisor *divisor = new osg::VertexAttribDivisor(1, 1); ss->setAttribute(divisor); And changing my loop to add one offset per primitive to my vertexArray And thanks again!! I would never have

Re: [osg-users] Tearing hair out over simple GLSL instancing

2016-12-22 Thread Glenn Waldron
You can use osg::VertexAttribDivisor (set to 1) to tell the shader to use one attribute index per instance. Glenn Waldron On Thu, Dec 22, 2016 at 12:35 PM, Andrew Cunningham wrote: > On thinking about this issue, I see the problem. I really only have 4 > vertices, so the

Re: [osg-users] Tearing hair out over simple GLSL instancing

2016-12-22 Thread Gedalia Pasternak
you might want to look into glVertexAttribDivisor https://www.opengl.org/sdk/docs/man4/html/glVertexAttribDivisor.xhtml That would let you make a vbo with 100 offsets in it and then each instanced draw call would get a different offset. you can even send down a 4x3 transform matrix by using more

Re: [osg-users] Tearing hair out over simple GLSL instancing

2016-12-22 Thread Andrew Cunningham
On thinking about this issue, I see the problem. I really only have 4 vertices, so the value d in my vertex shader just is always pulled from locations 0-3 in my array. What I really need to do is access an array of offsets in my shader indexed by glInstanceID -- Read this

[osg-users] Tearing hair out over simple GLSL instancing

2016-12-22 Thread Andrew Cunningham
OSG 3.4.0 I am trying to use "instancing" (starting from the example osgdrawinstanced) to draw simple square geometry at multiple locations. I am getting all of my instances sitting on top of each other at (0,0,0). That is they are not offset to their expected locations. I know my shader is