Re: [osg-users] If I set a vertex color using floats and access the vertex color in a shader, is there a loss of precision?
Jason, it looks like something went wrong with your last post since it's awaiting approval. There was a file attached but it was identical to the last file. Was there something important in that message that I missed? Thanks again. -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=46211#46211 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] If I set a vertex color using floats and access the vertex color in a shader, is there a loss of precision?
I typically just use the mailing list instead of the forum. I guess the Mail2Forum gateway doesn't handle attachments very well. Here it is... -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=46206#46206 Attachments: http://forum.openscenegraph.org//files/human_125.osg ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] If I set a vertex color using floats and access the vertex color in a shader, is there a loss of precision?
On 03/13/2012 07:14 AM, Ethan Fahy wrote: Jason, it looks like something went wrong with your last post since it's awaiting approval. There was a file attached but it was identical to the last file. Was there something important in that message that I missed? Thanks again. No, it's fine. It looked to me like my attachment from the mailing list didn't make it through the gateway to the forum properly, so I went ahead and logged onto the forum to post it directly there. Of course, by the time I got through with that, the original attachment had shown up just fine. But then, of course, my post was flagged for approval because I'm a new user on the forum :-) --J ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] If I set a vertex color using floats and access the vertex color in a shader, is there a loss of precision?
Oh OK gotcha. Thanks again, I did end up implementing everything correctly for a different model that needed to be indexed per vertex instead of per primitive. I also changed my shaders so that the lookup table logic went into the vertex shader instead of the frag shader. If I did the lookup in the frag shader then the vertex values were interpolated which is not what I wanted. For the models that must be bound per primitive, I'll probably just revert to encoding the index numbers in the vertex colors instead of generic vertex attributes. However I am debating whether I should create a separate forum thread about using generic vertex attributes that are BIND_PER_PRIMITIVE with GLSL; both of us were unable to get it working but since I can't find any documentation online for why it wouldn't work it might be worth asking to a larger audience since this thread has veered off from its original title somewhat. -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=46219#46219 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] If I set a vertex color using floats and access the vertex color in a shader, is there a loss of precision?
Attention, almost anything that is BIND_PER_PRIMITIVE will force osg into a slow render path that does make use of immediate draw calls. Christian ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] If I set a vertex color using floats and access the vertex color in a shader, is there a loss of precision?
Thanks Christian, To clarify, if I have a scene with lots of objects that are bound per vertex and just one, relatively simply object that is bound per primitive, will that one object that is bound per primitive harm the rendering speed of the entire scene or just of that one object? I have a physical model that outputs temperature for each facet of the model so if I want to color the model I can't use bind per vertex and still have a perfect representation of the physical model. Christian Buchner wrote: Attention, almost anything that is BIND_PER_PRIMITIVE will force osg into a slow render path that does make use of immediate draw calls. Christian ___ osg-users mailing list http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org -- Post generated by Mail2Forum -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=46222#46222 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] If I set a vertex color using floats and access the vertex color in a shader, is there a loss of precision?
My guess is that it affects the drawable only. But I am not really qualified to answer that. Christian Am 13. März 2012 17:57 schrieb Ethan Fahy ethanf...@gmail.com: Thanks Christian, To clarify, if I have a scene with lots of objects that are bound per vertex and just one, relatively simply object that is bound per primitive, will that one object that is bound per primitive harm the rendering speed of the entire scene or just of that one object? ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] If I set a vertex color using floats and access the vertex color in a shader, is there a loss of precision?
On 03/13/2012 12:52 PM, Christian Buchner wrote: Attention, almost anything that is BIND_PER_PRIMITIVE will force osg into a slow render path that does make use of immediate draw calls. I mentioned this up a bit higher in the thread. The question of whether or not it will be slow is different than whether or not it will (or should) work properly at all. As far as I can tell, OSG implements the necessary glVertexAttrib() calls that you'd need for this to work, so I don't know why the attributes fail to make it to the vertex shader. Sure, it's generally not a good idea to rely on PER_PRIMITIVE bindings at all, but for a particular use case where, say, scientific data is being visualized, the visualization lends itself to per-primitive attributes, and there are few enough primitives that performance isn't a problem, is there a reason why OSG wouldn't handle this? --J ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] If I set a vertex color using floats and access the vertex color in a shader, is there a loss of precision?
Thanks Jason, I understand about the interpolation. I have been operating under the assumption that if I use a node visitor to loop over each primitive in my object, create a floatArray of index numbers of size=size(primitive array), and then bind_per_primitive, then I shouldn't have to worry about interpolation of those index numbers within the shader. Is that correct? I noticed that in Christian's code snippet that the osg::Program that he created was not attached to the geometry's stateset. Without attaching it, you will still have a floatArray stored in the 6 position, but it will not have a name and therefore I don't think you can access it from the shader. In either case, when i try to add my floatArray to the 6th vertex attribute, my shaders stop working. I don't get any glsl errors printed to screen, but even if I try to do something simple like assign all color values to black, the shader just spits out the underlying object colors and ignores my shader commands. If I don't attach the osg::Program to my object's stateset, the shader commands do work again but I can't access my 6th vertex attribute because it wasn't named. Here is the stateset that was added to my object.obj's geometry: StateSet { rendering_hint DEFAULT_BIN renderBinMode INHERIT Program { name targetIndices GeometryVerticesOut 1 GeometryInputType TRIANGLES GeometryOutputType TRIANGLE_STRIP AttribBindingLocation indices 6 num_shaders 0 } } I'm assuming most of these things are default values since I never specified GeometryVerticesOut, GeometryInputType, GeometryOutputType, or num_shaders when I created my osg::Program. Are these defaults the cause of my problems? I know that this post is a bit scatter-brained but I tried my best to represent my problem. -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=46183#46183 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] If I set a vertex color using floats and access the vertex color in a shader, is there a loss of precision?
So I tried writing my osg Node object to an osg file at various points during my code to compare the differences. What I noticed was that if I attach the program to the geometry stateset while in my nodevisitor, that the properties of the geometry stateset will replace those of the geode stateset. I was putting all of my shader program stuff in the geode stateset. Since my geometry stateset where I attached my program had a default num_shader of 0, I think the shaders were being ignored even though they were in the geode's stateset. So, I tried attaching the program from my nodevisitor to the geode instead of the geometry, but then when i go to add my shader program to the geode stateset, the nodevisitor program and stateset get overwritten. I need to somehow make sure that my generic vertex attribute program does not get overwritten when I attach my shader program. I think it's probably time for me to revisit some osg documentation at this point... -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=46190#46190 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] If I set a vertex color using floats and access the vertex color in a shader, is there a loss of precision?
On 03/12/2012 10:04 AM, Ethan Fahy wrote: Thanks Jason, I understand about the interpolation. I have been operating under the assumption that if I use a node visitor to loop over each primitive in my object, create a floatArray of index numbers of size=size(primitive array), and then bind_per_primitive, then I shouldn't have to worry about interpolation of those index numbers within the shader. Is that correct? If you're trying to get the same value for all fragments on a primitive, then yes, this will work. Be aware, though, that rendering geometry with per-primitive binding is going to be quite slow compared to overall or per-vertex binding. As an alternative, you could specify your floatArray at size=size(primitive array) * 3 (assuming you're rendering triangles) and just specify the same index for all three vertices of each triangle. Then, you could use per-vertex binding and not fall off the fast path. I noticed that in Christian's code snippet that the osg::Program that he created was not attached to the geometry's stateset. Without attaching it, you will still have a floatArray stored in the 6 position, but it will not have a name and therefore I don't think you can access it from the shader. In either case, when i try to add my floatArray to the 6th vertex attribute, my shaders stop working. I don't get any glsl errors printed to screen, but even if I try to do something simple like assign all color values to black, the shader just spits out the underlying object colors and ignores my shader commands. If I don't attach the osg::Program to my object's stateset, the shader commands do work again but I can't access my 6th vertex attribute because it wasn't named. Here is the stateset that was added to my object.obj's geometry: StateSet { rendering_hint DEFAULT_BIN renderBinMode INHERIT Program { name targetIndices GeometryVerticesOut 1 GeometryInputType TRIANGLES GeometryOutputType TRIANGLE_STRIP AttribBindingLocation indices 6 num_shaders 0 } } I'm assuming most of these things are default values since I never specified GeometryVerticesOut, GeometryInputType, GeometryOutputType, or num_shaders when I created my osg::Program. Are these defaults the cause of my problems? The defaults are probably fine (they apply to geometry shaders, which I don't think you're using). The attribute binding for indices at attribute 6 looks good as well. However, it looks as if there are not any shaders attached to your Program (num_shaders 0), which isn't going to work at all. You need to create an osg::Shader (specifying the type of shader, vertex, geometry, or fragment), add the shader's source to it, and then add the shader to the Program. Then, you can attach the program to the StateSet and everything should work: shader = new osg::Shader(osg::Shader::FRAGMENT); shader-setShaderSource(source); program-addShader(shader); --J ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] If I set a vertex color using floats and access the vertex color in a shader, is there a loss of precision?
Does that mean that an osg::StateSet can only have one osg::Program? I have one application that uses a nodeVisitor to assign my generic vertex attribute and sets a program with the generic vertex names. After saving the result as an ive file I have another application that reads in that ive file and attaches a shader program and renders the node. Is it possible to either have multiple osg::Programs per stateset or to combine osg::Programs? -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=46197#46197 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] If I set a vertex color using floats and access the vertex color in a shader, is there a loss of precision?
On 03/12/2012 01:15 PM, Ethan Fahy wrote: Does that mean that an osg::StateSet can only have one osg::Program? I have one application that uses a nodeVisitor to assign my generic vertex attribute and sets a program with the generic vertex names. After saving the result as an ive file I have another application that reads in that ive file and attaches a shader program and renders the node. Is it possible to either have multiple osg::Programs per stateset or to combine osg::Programs? Yes, there can be only one GLSL program active at any time (this is an OpenGL rule), hence there is only one osg::Program allowed per StateSet. Currently, there is no provision in OSG for combining Shaders or Programs (though I believe this is on the to-do list). For now, though, you'll have to do the combining yourself. There are several tricks you can use to get different code to execute from the same shader. One simple method is to define an if/else block and switch code paths based on the value of a Uniform. You can also define a function in one shader, and have it called from another shader. This way, you can switch behavior by using different implementations of the same function. Shader A implements the shader's main() function and defines the prototype for function foo(), which is called in main(). Function foo() is implemented in both shader A and shader B, using the prototype defined in shader A, but each having different code. In one case, you attach shaders A and C to the program, and in the other case, you attach shaders B and C. --J ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] If I set a vertex color using floats and access the vertex color in a shader, is there a loss of precision?
Thanks Jason, So, since I can't combine programs (I didn't necessarily mean multiple shaders, I just meant multiple programs), I decided to take this line of code: program-addBindAttribLocation(indices, 6); and move it to where I assemble my shader program and attach it to the node's stateset. This way my nodeVisitor can still set my generic vertex array in position 6 and my osg::Program's shader can access those index values by including the following line in the frag shader: in float indices; I looked at the osg file that I wrote to disk and verified that my stateset's program contained this line: AttribBindingLocation indices 6 However, when I use indices in my shader, the resulting value is always equal to 0.0, even though my VertexAttributeArray values range from 0.0 to 124.0. I don't want to impose on you too much since you've already helped me out a great deal, but I'm going to go ahead and attach an osg file that demonstrates this behavior. The file is a simple human shape with 125 primitives. I created a generic vertex array with index values sequential from 0-124. I also attached a simple shader that paints everything green if the indices = 0 and red otherwise. As you can see by opening this file in osgviewer, all values are green. If you have time to look at it that would be fantastic but I completely understand if you don't. Thanks again, -Ethan -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=46200#46200 human.osg Description: Binary data ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] If I set a vertex color using floats and access the vertex color in a shader, is there a loss of precision?
On 03/12/2012 02:21 PM, Ethan Fahy wrote: Thanks Jason, So, since I can't combine programs (I didn't necessarily mean multiple shaders, I just meant multiple programs), I decided to take this line of code: program-addBindAttribLocation(indices, 6); and move it to where I assemble my shader program and attach it to the node's stateset. This way my nodeVisitor can still set my generic vertex array in position 6 and my osg::Program's shader can access those index values by including the following line in the frag shader: in float indices; I looked at the osg file that I wrote to disk and verified that my stateset's program contained this line: AttribBindingLocation indices 6 However, when I use indices in my shader, the resulting value is always equal to 0.0, even though my VertexAttributeArray values range from 0.0 to 124.0. I don't want to impose on you too much since you've already helped me out a great deal, but I'm going to go ahead and attach an osg file that demonstrates this behavior. The file is a simple human shape with 125 primitives. I created a generic vertex array with index values sequential from 0-124. I also attached a simple shader that paints everything green if the indices = 0 and red otherwise. As you can see by opening this file in osgviewer, all values are green. If you have time to look at it that would be fantastic but I completely understand if you don't. Thanks again, Yeah, it's green for me, too. One problem appears to be that while your VertexAttribArray on attribute 6 looks fine, you have a vertex shader defined that isn't passing the value down to the fragment shader. The fragment shader will never receive your attribute data this way. I did a quick try to get the vertex shader to pass the data down, but I couldn't get it working in the five minutes I spent. I attached my attempt to hopefully inspire you to get to the real solution :-) Note that I went back to the GLSL 1.2-style of attribute and varying instead of the in and out qualifiers that were introduced in OpenGL 3. If I get some time, I'll try to play with it some more. --J Geode { nodeMask 0x cullingActive TRUE StateSet { rendering_hint DEFAULT_BIN renderBinMode USE binNumber 6 binName RenderBin GL_LIGHTING OFF Program { name Environment GeometryVerticesOut 1 GeometryInputType TRIANGLES GeometryOutputType TRIANGLE_STRIP AttribBindingLocation indices 6 num_shaders 2 Shader { type FRAGMENT code { varying float fIndices; void main(void) { vec4 color = gl_Color; if( fIndices == 0.0 ){ color.r = 0.0; color.g = 1.0; color.b = 0.0; }else{ color.r = 1.0; color.g = 0.0; color.b = 0.0; } gl_FragColor = color; } } } Shader { type VERTEX code { attribute float indices; varying float fIndices; void main(void) { gl_FrontColor = gl_Color; gl_Position = ftransform(); fIndices = indices; } } } } textureUnit 0 { } textureUnit 1 { GL_TEXTURE_2D ON Texture2D { UniqueID Texture2D_0 wrap_s CLAMP_TO_EDGE wrap_t CLAMP_TO_EDGE wrap_r CLAMP_TO_EDGE min_filter NEAREST mag_filter NEAREST maxAnisotropy 1 borderColor 0 0 0 0 borderWidth 0 useHardwareMipMapGeneration TRUE unRefImageDataAfterApply FALSE internalFormatMode USE_IMAGE_DATA_FORMAT resizeNonPowerOfTwo FALSE shadowComparison FALSE shadowCompareFunc GL_LEQUAL shadowTextureMode GL_LUMINANCE } } } num_drawables 1 Geometry { useDisplayList TRUE useVertexBufferObjects FALSE PrimitiveSets 125 { DrawElementsUInt QUADS 4 { 0 1 2 3 } DrawElementsUInt QUADS 4 { 3 4 5 0 } DrawElementsUInt QUADS 4 { 1 6 7 2 } DrawElementsUInt QUADS 4 { 5 4 7 6 } DrawElementsUInt QUADS 4 { 8 9 10 11 } DrawElementsUInt QUADS 4 { 9 12 13 10 } DrawElementsUInt QUADS 4 { 10 16 17 11 } DrawElementsUInt QUADS 4 { 10 13 18 16 } DrawElementsUInt QUADS 4 { 13 14 19 18 } DrawElementsUInt QUADS 4 { 17 20 22 11 } DrawElementsUInt QUADS 4 { 22 20 21 23 } DrawElementsUInt QUADS 4 { 23 21 19 14 } DrawElementsUInt
Re: [osg-users] If I set a vertex color using floats and access the vertex color in a shader, is there a loss of precision?
Thanks Jason, I didn't even realize that in and out were OpenGL 3 things. My GPU does have OpenGL 3 capability. Thanks for looking at that code but I don't think it attached to the site properly? -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=46204#46204 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] If I set a vertex color using floats and access the vertex color in a shader, is there a loss of precision?
So I decided to go again and try to use a generic vertex attribute to store my index numbers. I noticed from another osg forum thread that there is currently a problem using int values for vertex attributes but that floats are working and can be converted to ints in the shader. With that in mind, I implemented Christian's code snippet up to the part where I've already added a vec2 float vertex attribute to the 6th position. I have a couple of questions though: 1. in osg there is no Vec1Array (which makes sense), but then if I only wanted to store 1 float value for each vertex, what would I use? osg::array ? 2. I need to access the vertex values from a frag shader instead of the vertex shader as seen in Christian's code snippet. If I have a generic vertex shader like this: Code: void main(void) { gl_FrontColor = gl_Color; gl_Position = ftransform(); } then can I access the vertex attribute in the frag shader like this? Code: in vec2 indices; void main(void) { //get index from vertex attribute 6 vec2 index = indices; } [/code] -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=46137#46137 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] If I set a vertex color using floats and access the vertex color in a shader, is there a loss of precision?
On 03/09/2012 02:08 PM, Ethan Fahy wrote: So I decided to go again and try to use a generic vertex attribute to store my index numbers. I noticed from another osg forum thread that there is currently a problem using int values for vertex attributes but that floats are working and can be converted to ints in the shader. With that in mind, I implemented Christian's code snippet up to the part where I've already added a vec2 float vertex attribute to the 6th position. I have a couple of questions though: 1. in osg there is no Vec1Array (which makes sense), but then if I only wanted to store 1 float value for each vertex, what would I use? osg::array ? Close, osg::FloatArray :-) 2. I need to access the vertex values from a frag shader instead of the vertex shader as seen in Christian's code snippet. If I have a generic vertex shader like this: Code: void main(void) { gl_FrontColor = gl_Color; gl_Position = ftransform(); } then can I access the vertex attribute in the frag shader like this? Code: in vec2 indices; void main(void) { //get index from vertex attribute 6 vec2 index = indices; } Depends on what you're after, but I'm guessing not. The fragment values will be interpolated between the vertices, so if you have a value of 6.0 on one vertex and 8.0 on another, the value for the fragment halfway between those vertices will be 7.0. If you're drawing triangles, and you want all of the fragments on a particular triangle to have the same value, you can specify flat shading in the fragment shader: flat in vec2 indices; which might give you what you're looking for (without knowing how your geometry is laid out and how you're using the indices, I can only guess). --J ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] If I set a vertex color using floats and access the vertex color in a shader, is there a loss of precision?
Thanks for the advice, much obliged. Jason Daly wrote: On 03/06/2012 11:58 AM, Ethan Fahy wrote: Thanks for the info guys. I'll have to think about the best way forward a bit. I'm still hesitant to add generic vertex attributes just because it seems like it would add to a given node's memory usage and since I don't use the node's color values for anything other than lookup table purposes I might as well store stuff in those colors since everything I draw is going to have to have memory allocated for colors no matter what. I would also like to think that the code I'm writing will always be used on newer GeForce cards, I don't think that I can know that for certain as it would ultimately be distributed to some not-so-powerful computers to run on. I understand your hesitance. Most of the tutorials are written with the more traditional vertex attributes, and when you're just starting out, it can be simpler to think in those terms. If it works for you, then by all means, go with it. As you continue to learn, though, I'd just encourage you to keep in mind that modern cards don't have any distinction between different kinds of vertex attributes anymore. Every attribute, whether it's labeled normals, colors, texture coordinates, or whatever, is simply a per-vertex value that is used by the vertex shader (there's always a vertex shader running under the hood, even if you don't specify your own). --J ___ osg-users mailing list http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org -- Post generated by Mail2Forum |-) |-) -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=46086#46086 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] If I set a vertex color using floats and access the vertex color in a shader, is there a loss of precision?
I'm using colors just because it seemed like a simple approach and because all the colors of everything in my scene are replaced wholesale by lookup tables so there's no need to keep any color data once it's been swapped in the shaders. I was also wary of using generic attributes after reading the bottom of this page: http://www.opengl.org/sdk/docs/tutorials/ClockworkCoders/attributes.php Just seemed like more trouble than it was worth. But I'm really just learning OpenGL and osg so it could be that using a generic vertex attribute is the way to go. -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=46057#46057 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] If I set a vertex color using floats and access the vertex color in a shader, is there a loss of precision?
For using generic vertex attributes, you could refer to these (partial) code snippets. I pass some custom texture coordinates as a float2 attribute with each vertex. Can be easily changed to float4, if needed. osg::Geometry *meshGeom; // so we use a float attribute array instead osg::Vec2Array* xypositions = new osg::Vec2Array(); xypositions-setName(xypos); // for loop over all vertices, adds texture coordinates for (...) xypositions-push_back(osg::Vec2(xcoord, ycoord)); // only use binding to attribute index 6 or 7 as these are not used by OSG. meshGeom-setVertexAttribArray(6, xypositions); meshGeom-setVertexAttribNormalize(6, false); meshGeom-setVertexAttribBinding(6, osg::Geometry::BIND_PER_VERTEX); osg::Program* program = new osg::Program; program-setName( mesh ); program-addBindAttribLocation(xypos, 6); // and here is how I access the custom attribute in a vertex shader. // I perform a gaussian interpolation over sample values contained in a 2D texture, // and use that to displace a 3D mesh vertically. static const char *VertexShader = { #version 120\n uniform float K;\n uniform float N;\n uniform sampler2D datatex;\n in vec2 xypos;\n void main(void)\n {\n // gaussian 3x3 filter kernel;\n float foo = 41.0 * texture2D(datatex, xypos).x\n + 26.0 * texture2D(datatex, xypos+vec2(+K , 0 )).x\n + 26.0 * texture2D(datatex, xypos+vec2(-K , 0 )).x\n + 26.0 * texture2D(datatex, xypos+vec2( 0 ,+N )).x\n + 26.0 * texture2D(datatex, xypos+vec2( 0 ,-N )).x\n + 16.0 * texture2D(datatex, xypos+vec2(-K ,+N )).x\n + 16.0 * texture2D(datatex, xypos+vec2(-K ,-N )).x\n + 16.0 * texture2D(datatex, xypos+vec2(+K ,+N )).x\n + 16.0 * texture2D(datatex, xypos+vec2(+K ,-N )).x;\n ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] If I set a vertex color using floats and access the vertex color in a shader, is there a loss of precision?
On 03/06/2012 07:39 AM, Ethan Fahy wrote: I was also wary of using generic attributes after reading the bottom of this page: http://www.opengl.org/sdk/docs/tutorials/ClockworkCoders/attributes.php Just seemed like more trouble than it was worth. But I'm really just learning OpenGL and osg so it could be that using a generic vertex attribute is the way to go. That information is outdated. Nvidia cards since the GeForce 8 series, I believe, have not had the aliasing issue. Indeed, the traditional vertex attributes (normal, color, texture coordinates) are even deprecated in OpenGL since version 3. There shouldn't be any reason to worry about using generic vertex attributes. --J ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] If I set a vertex color using floats and access the vertex color in a shader, is there a loss of precision?
Thanks for the info guys. I'll have to think about the best way forward a bit. I'm still hesitant to add generic vertex attributes just because it seems like it would add to a given node's memory usage and since I don't use the node's color values for anything other than lookup table purposes I might as well store stuff in those colors since everything I draw is going to have to have memory allocated for colors no matter what. I would also like to think that the code I'm writing will always be used on newer GeForce cards, I don't think that I can know that for certain as it would ultimately be distributed to some not-so-powerful computers to run on. -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=46071#46071 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] If I set a vertex color using floats and access the vertex color in a shader, is there a loss of precision?
On 03/06/2012 11:58 AM, Ethan Fahy wrote: Thanks for the info guys. I'll have to think about the best way forward a bit. I'm still hesitant to add generic vertex attributes just because it seems like it would add to a given node's memory usage and since I don't use the node's color values for anything other than lookup table purposes I might as well store stuff in those colors since everything I draw is going to have to have memory allocated for colors no matter what. I would also like to think that the code I'm writing will always be used on newer GeForce cards, I don't think that I can know that for certain as it would ultimately be distributed to some not-so-powerful computers to run on. I understand your hesitance. Most of the tutorials are written with the more traditional vertex attributes, and when you're just starting out, it can be simpler to think in those terms. If it works for you, then by all means, go with it. As you continue to learn, though, I'd just encourage you to keep in mind that modern cards don't have any distinction between different kinds of vertex attributes anymore. Every attribute, whether it's labeled normals, colors, texture coordinates, or whatever, is simply a per-vertex value that is used by the vertex shader (there's always a vertex shader running under the hood, even if you don't specify your own). --J ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] If I set a vertex color using floats and access the vertex color in a shader, is there a loss of precision?
Hello all, If I were to set the color of a vertex of an osg::Node using floats between 0-1 and then accessed the color of that same vertex in a GLSL shader, would I get back the exact same floating point value? I am worried that at some point in the pipeline that float would be scaled to an 8 bit unsigned int between 0-255 and then rescaled back to a 0-1 float when accessed using GLSL. The reason I ask is that I am hoping to use the floating point value to carry a scaled index number for a lookup table in the shader instead of a color, so precision would be important. I know this is an OpenGL pipeline question and I am actively reading OpenGL documentation to get my head around this stuff in general but a quick answer to this particular question would be very much appreciated, especially since I can't do any debugging on the shader to verify this one way or another. Thanks, -Ethan -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=46035#46035 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] If I set a vertex color using floats and access the vertex color in a shader, is there a loss of precision?
On 03/05/2012 10:54 AM, Ethan Fahy wrote: If I were to set the color of a vertex of an osg::Node using floats between 0-1 and then accessed the color of that same vertex in a GLSL shader, would I get back the exact same floating point value? I am worried that at some point in the pipeline that float would be scaled to an 8 bit unsigned int between 0-255 and then rescaled back to a 0-1 float when accessed using GLSL. The reason I ask is that I am hoping to use the floating point value to carry a scaled index number for a lookup table in the shader instead of a color, so precision would be important. Hi, Ethan, If you're talking about vertex attribute data, you're likely get the same value back that you originally specified. The vertex attributes will remain in float form until you actually rasterize the vertices. Only at that point will they need to be converted to fit the data format of the framebuffer. That said, it's generally not a good idea to rely on floating point values to be exactly the same from one call to the next. I'd recommend trying to come up with a different way to do what you're attempting, or at least use an epsilon value in your comparison. --J ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] If I set a vertex color using floats and access the vertex color in a shader, is there a loss of precision?
Thanks Jason, I may do some testing with floats to see if they work out, but most likely I'll play it safe and use unsigned ints for r,g,and b and come up with an indexing scheme that can theoretically host up to 16.7 million discrete values. Jason Daly wrote: On 03/05/2012 10:54 AM, Ethan Fahy wrote: If I were to set the color of a vertex of an osg::Node using floats between 0-1 and then accessed the color of that same vertex in a GLSL shader, would I get back the exact same floating point value? I am worried that at some point in the pipeline that float would be scaled to an 8 bit unsigned int between 0-255 and then rescaled back to a 0-1 float when accessed using GLSL. The reason I ask is that I am hoping to use the floating point value to carry a scaled index number for a lookup table in the shader instead of a color, so precision would be important. Hi, Ethan, If you're talking about vertex attribute data, you're likely get the same value back that you originally specified. The vertex attributes will remain in float form until you actually rasterize the vertices. Only at that point will they need to be converted to fit the data format of the framebuffer. That said, it's generally not a good idea to rely on floating point values to be exactly the same from one call to the next. I'd recommend trying to come up with a different way to do what you're attempting, or at least use an epsilon value in your comparison. --J ___ osg-users mailing list http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org -- Post generated by Mail2Forum -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=46039#46039 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] If I set a vertex color using floats and access the vertex color in a shader, is there a loss of precision?
On 03/05/2012 03:17 PM, Ethan Fahy wrote: Thanks Jason, I may do some testing with floats to see if they work out, but most likely I'll play it safe and use unsigned ints for r,g,and b and come up with an indexing scheme that can theoretically host up to 16.7 million discrete values. Just curious, Is there some reason you're specifying a scaled index for a look-up table as a color? Any reason you can't just pass your scaled index to your shader as a 32 bit generic integer vertex attribute? --J ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org