First of all, hello all! I must say, you have made one heck of a 3D engine here, of completely professional quality but open source and free! An absolute blessing for poor students like me
Anyway, having seen the amazing screenshots on the blog, I have been trying to get hardware instancing working on my machine. Unfortunately, nothing seems to work (ranging from downloaded Python samples to self-made C++ code; always the same āINSTANCEID semantics not recognizedā).
After a bit of hair-pulling, I decided that the mistake must be somewhere else than my code; Iāve downloaded the Panda3D sources and messed around a bit, and found an interesting thing in GLGraphicsStateGuardian::reset()⦠when the cgGLGetLatestProfile(ā¦) functions are called, what they return is always arbvp1/arbfp1 (and a bit later on, āshader model 4ā is also reported by some different function).
Now, I donāt know that much about shaders, but surely that isnāt right? The Radeon HD4890 isnāt the newest card around, but itās pretty new and should support gp4vp, no?
Iāve searched around and came across this; Since am I also using Windows 7, Iād like to ask if this is some sort of unique issue? Or do these things also happen on other OSes?
I have updated my graphics card drivers yesterday, so I donāt think thatās the problem.
(oh, and please ignore the registration date - I initially registered a LONG time ago, while I was still messing about with Python and encountering noobish mistakes; Ones that I fixed before managing to write up a post, hence leaving this account inactive for a LONG time, until recently, when Iāve finally returned to Panda3D, now with knowledge of C++).
Hey! Even though youāve been around for a while, Iāll still welcome you to the forums.
First of all, did you install the latest drivers for your video card?
Secondly, did you make sure that the ābasic-shaders-onlyā Config.prc variable is set to #f or 0? Some developer added it a long time ago to restrict any shader to the arbvp1/arbfp1 profiles, as back then they appeared to be the only profiles that worked properly across graphics cards.
I have indeed updated my drivers and set the ābasic shaders onlyā variable - not only in the PRC file, but also through load_prc_file_data() to make absolutely sure that wasnāt it
Iāve googled around a bit, and found that apparently, ATI cards only support the arbvp1/arbfp1 CG profiles, and no other ones (including the latest gen cards) - sounds incredibly stupid, but the fact that the cgGLGetLatestProfile() function itself seems to confirm it makes me think that really is the case.
Anyway, Iāve managed to translate the official hardware instancing example from the site into GLSL, where I can use gl_InstanceID without issues.
Unfortunately, Iāve ran into another big issue: I canāt seem to be able to pass float4 arrays into the shader. Individual float4ās work perfectly, but elements from an array seem to always give (0,0,0,0) when read [Iām using the standard PTA_LVecBase4f as a shader input].
Is there some special method required for GLSL? Or is this another ATI-related bug?
Hmm, if GLSL does work, then try forcing Panda to use the āglslvā and āglslfā profiles. Although not sure why cgGLGetLatestProfile would not return those.
This way, Cg will automatically translate the shaders into GLSL for you, so you can keep using Cg (and take advantage of the ability to pass arrays).
The CG code was automatically falling-back to glslv profiles (after trying gp4vp), but āunknown semantics āINSTANCEIDāā was the result, unfortunately.
Do you mean to say that GLSL doesnāt support uniform arrays? I was quite confident it did; Then again, my knowledge of GLSL currently comes from a few web tutorials and a single reference sheet, so yeah.
If it really doesnāt though, that would essentially mean that hardware instancing with Panda3D is not going to work on any ATI cards whatsoever⦠Iām seriously hoping Iāve made a noobish mistake somewhere!
Nah, itās just not supported by Panda3D at the moment. A student from CMU added functionality to pass arrays at all, but only added it to the Cg side.
Ah, excellent! Since Iāve already got the Panda3D sources, Iāll look into adding my own implementation then (obviously, Iāll also put it up here once itās relatively bugless, along with my translated GLSL instancing shader).
Ok, it seems to work now. Iāve attached the only file that I think Iāve changed (Iāve actually changed a few other files at first, then changed them right back while debugging / checking how Panda works, so Iām not completely sure this is the only one).
Itās fairly basic, but keeps things simple and doesnāt add any new strange data types or anything, so Iām hoping itās usable. Iām fairly confident I didnāt break anything, but with such a huge codebase one can never be sure.
Iām also attaching my GLSL instancing shaders; Iāve translated them basically line-for-line from the official examples, and they should be useful enough for owners of ATI cards.
Now, for my project, I still need to implement rotation - the obvious solution is to create a rotation matrix based on a vec3 input array (of h,p,r angles), then operate it onto the position vector. However, I fear that might be too slow - any better suggestions?
Hi, I am trying to use your code and shaders in my quest to use geometry instancing that will work on ATI cards.
The source changes compile with no issues, but using the shader gives the following:
0(11) : warning C7532: global variable gl_InstanceID requires "#version 140" or later
0(11) : warning C0000: ... or #extension GL_EXT_gpu_shader4 : enable
Are there maybe some other code changes, or something Iāve forgotten to do?
The basic-shaders-only setting doesnāt seem to make a difference either way.
If itās just a matter of prefixes, then I would consider it a minor annoyance. I donāt know GLSL yet, so Iām not sure how much that changes, but from what rbd wrote here: panda3d.org/forums/viewtopi ⦠8114#88114 I would assume it shouldnāt be a showstopper.
Zhao, would you be so kind to share the instancing code? Or some snippets from it? I have that running in CG, but GLSL is new to me, so taking a look at how itās done in there would help me get up to speed quicker.
My example code is to just generate two smileys instances offsetted from each other.
The only tricks I encountered to get it to work is that 1) the shaderinput had to be set twice in slightly different ways 2) My ATI 5450 didnāt want to be compatible and I had to comment out the GL_ARB compatability extension. But other than that, I had no difficulties getting it to work.
I never got the demo code posted in the messages earlier to work though. (ie., only one ralph showed up.) But the framework used there was complicated while this example hopefully is very simple to execute.
Btw, I have to add that I didnāt find the lack of gl_prefix to be critical. Also I may be mistaken, but it seems that in more modern GLSL versions, (ie., the versions needed for instancing to work), some cards such as my ATI drops backwards compatilibity and a lot of gl_XXX wouldnāt work anyway even if Panda supported them correctly as they are only specified for early GLSL versions.
Again, I maybe wrong, but I kind of remember reading that the reason for dropping some of the gl_XXX in modern GLSL, is that input steams are treated generically so there is no official āvertex positionā to speak of.