Hi,
I need tangent and binormal in my GLSL shaders, and they are not passed. The change to add them is quite simple, here is the diff:
Index: glShaderContext_src.cxx
===================================================================
RCS file: /cvsroot/panda3d/panda/src/glstuff/glShaderContext_src.cxx,v
retrieving revision 1.72
diff -u -r1.72 glShaderContext_src.cxx
--- glShaderContext_src.cxx 17 Nov 2011 19:42:51 -0000 1.72
+++ glShaderContext_src.cxx 25 Nov 2011 15:11:17 -0000
@@ -20,6 +20,7 @@
#include "Cg/cgGL.h"
#endif
#include "pStatTimer.h"
+#include <algorithm>
#define DEBUG_GL_SHADER 0
@@ -381,12 +382,30 @@
}
if (noprefix.substr(0, 13) == "MultiTexCoord") {
bind._name = InternalName::get_texcoord();
- bind._append_uv = atoi(inputname->get_name().substr(13).c_str());
+ bind._append_uv = atoi(noprefix.substr(13).c_str());
s->_var_spec.push_back(bind);
gsg->_glBindAttribLocation(_glsl_program, i, param_name);
continue;
}
- GLCAT.error() << "Unrecognized vertex attrib '" << param_name << "'!\n";
+ if (noprefix.substr(0, 7) == "Tangent") {
+ bind._name = InternalName::get_tangent();
+ bind._append_uv = atoi(noprefix.substr(7).c_str());
+ s->_var_spec.push_back(bind);
+ gsg->_glBindAttribLocation(_glsl_program, i, param_name);
+ continue;
+ }
+ if (noprefix.substr(0, 8) == "Binormal") {
+ bind._name = InternalName::get_binormal();
+ bind._append_uv = atoi(noprefix.substr(8).c_str());
+ s->_var_spec.push_back(bind);
+ gsg->_glBindAttribLocation(_glsl_program, i, param_name);
+ continue;
+ }
+ bind._name = InternalName::get_root();
+ std::replace(noprefix.begin(), noprefix.end(), '_', '.');
+ bind._name = bind._name->append(noprefix);
+ s->_var_spec.push_back(bind);
+ gsg->_glBindAttribLocation(_glsl_program, i, param_name);
continue;
}
}
It also adds possibility of custom vertex attributes from .egg files as in this thread.
But it doesn’t work, because data from vertex arrays is not passed to OpenGL. This is because update_shader_vertex_arrays() (in glShaderContext_src.cxx) is not called when shader language is not Cg. See the 2503 line in glGraphicsStateGuardian_src.cxx.
if (_current_shader_context == 0 || !_current_shader_context->uses_custom_vertex_arrays()) {
// No shader, or a non-Cg shader.
Everything works after deleting ‘|| !_current_shader_context->uses_custom_vertex_arrays()’ part. ‘uses_custom_vertex_arrays()’ simply checks if shader is Cg. So is it ok to delete this?
Can someone look at this and commit these changes please?
Another strange behavior is that uniform matrices (like gl_ModelViewMatrix) are working with ‘gl_’ but do not with ‘p3d_’ prefix (glsl 3.3). I don’t know why. They seem to be passed to OpenGL in both cases. But this is less important, one can use ‘gl_’ in shaders.