That particular line of your shader will execute at the same rate regardless of the number of materials in your scene (with the possible exception of cache misses when the materials change abruptly). However, your host code has to set those material values using glMaterial, which is a (relatively) expensive call.
If your performance bottleneck is in your shader, then maybe you can afford the extra expense of calling glMaterial to make those 100 material state changes per frame. But if you're already CPU/app bottlenecked, then those glMaterial calls can only exacerbate the situation. I don't think anyone here can tell you whether your performance will be acceptable or not -- that's up to you. But I think most people would agree that setting 100 materials per frame will take more CPU than 1 material per frame, regardless of whether you're using shaders or the fixed function pipe. Paul Martz Skew Matrix Software LLC http://www.skew-matrix.com 303 859 9466 > -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of > Zach Deedler > Sent: Thursday, January 04, 2007 4:34 PM > To: 'osg users' > Subject: RE: [osg-users] Materials with shaders > > I'm doint this: > gl_FrontColor = gl_FrontLightModelProduct.sceneColor + > ambient * gl_FrontMaterial.ambient + > diffuse * gl_FrontMaterial.diffuse; > > Won't this have the same performance with a scene that has > 100 materials as opposed to one that has 1 material? It is > difficult for me to do that benchmark. I'm just trying to > decide if I have to tell modelers to keep the number of > materials down. > > > Zach > > -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Paul Martz > Sent: Thursday, January 04, 2007 18:17 > To: 'osg users' > Subject: RE: [osg-users] Materials with shaders > > If your shader is picking up the values set by your > glMaterial commands, then you still have the overhead of > calling glMaterial to change the material parameters. > glMaterial is complex, and is more expensive to process than > most other state commands. This is why glColorMaterial was > created, so that apps could change material properties with > the comparatively inexpensive glColor command. > > I advise benchmarking it to see if the cost is so great as to > be prohibitive. > > Paul Martz > Skew Matrix Software LLC > http://www.skew-matrix.com > 303 859 9466 > > > > > -----Original Message----- > > From: [EMAIL PROTECTED] > > [mailto:[EMAIL PROTECTED] On Behalf Of Zach > > Deedler > > Sent: Thursday, January 04, 2007 4:03 PM > > To: 'osg users' > > Subject: RE: [osg-users] Materials with shaders > > > > Hi Robert, > > > > Yes, materials in the contexts of shaders. I'm not > changing uniforms > > or anything. Just one shader shades pretty much everything. The > > shader uses the material properties. For example it uses > the specular > > color and shades appropriately. > > > > Would having 100 materials with different specular colors > perform any > > less than having 1 material when using one shader? I can't > see why it > > would. > > > > > > Zach > > > > -----Original Message----- > > From: [EMAIL PROTECTED] > > [mailto:[EMAIL PROTECTED] On Behalf Of Robert > > Osfield > > Sent: Thursday, January 04, 2007 11:14 > > To: osg users > > Subject: Re: [osg-users] Materials with shaders > > > > Hi Zach, > > > > What do you exactly mean by materials in the contexts of shaders? > > GLSL exposes the glMaterial parameters in the form of built in > > uniforms but doesn't actually implement any lighting for you so the > > parameters are irrelevant unless you directly use them yourself. > > > > If you are using the built in uniforms then you are likely > you should > > ask yourself whether you should be using custom uniforms instead, > > custom uniforms would allow you to pass in just the data you require > > so might be of benefit. Updating uniforms may force a driver > > internal relink of the program and reload of of it to the GPU along > > with associate flush of the GPU pipelines. This means that change > > uniforms can be quite heavy, just like fixed function glMaterial is > > not something you want to change regularly. > > > > Robert. > > > > On 1/4/07, Zach Deedler <[EMAIL PROTECTED]> wrote: > > > QUICK QUESTION > > > Is it bad to have many different materials if you are > using shaders? > > > > > > THOUGHTS > > > I mean with fixed-functionality shading, I was under the > impression > > > that many different materials causes many state changes. > > > > > > With shaders though, it seems as though all my materials > > can be shaded > > > using the same shader, and thus there will be no state > changes. Is > > > this > > true? > > > Will I be able to have a bunch of materials without > > performance decay > > > when using one shader? > > > > > > > > > Zach > > > > > > _______________________________________________ > > > osg-users mailing list > > > [email protected] > > > http://openscenegraph.net/mailman/listinfo/osg-users > > > http://www.openscenegraph.org/ > > > > > _______________________________________________ > > osg-users mailing list > > [email protected] > > http://openscenegraph.net/mailman/listinfo/osg-users > > http://www.openscenegraph.org/ > > > > _______________________________________________ > > osg-users mailing list > > [email protected] > > http://openscenegraph.net/mailman/listinfo/osg-users > > http://www.openscenegraph.org/ > > _______________________________________________ > osg-users mailing list > [email protected] > http://openscenegraph.net/mailman/listinfo/osg-users > http://www.openscenegraph.org/ > > _______________________________________________ > osg-users mailing list > [email protected] > http://openscenegraph.net/mailman/listinfo/osg-users > http://www.openscenegraph.org/ _______________________________________________ osg-users mailing list [email protected] http://openscenegraph.net/mailman/listinfo/osg-users http://www.openscenegraph.org/
