Original Post
Hello, I have a beautiful OpenGL library which just needs a few touches. It supports tons of great features, from particle effects and shadowmapping to subsurface scattering and post-processing. It is fully documented, with tutorials and everything. Recently, I have gotten it to partially work with ATI cards by fixing a stupid syntactical error that seems to affect them only. Now, some of the example programs work, and some don't. The architecture of the shader section of the library is set up in pieces--the "render equation" is set up very simply and is designed to be intuitive to the programmer using it. For example, this would be an example of a Phong shader:the fragment color is set to "color". "ambient_color", "diffuse_color", and "specular_color" represent the material colors. The functions calculate the ambient, diffuse, and Phong specular components. The functions, however, pose a problem for ATI. The functions, naturally, do some operations behind the scenes, keeping the interface simple. As long as the operations in the functions are simple enough, the functions work. "light_ambient(0)", for instance, just returns GL_LIGHT0's ambient factor. When the functions are more involved, however, such as in "light_diffuse(0)" and "light_specular_ph(0)", the functions fail. Replacing the lines in the interface that call the functions with the contents of the functions themselves causes the shader to work as expected. For example: I know that some cards can give failures when many instructions are placed on one line. This line, for example:Must be broken down into the code above to work with ATI. I'm wondering if my problem--complex functions failing--is related to the "many operations on one line problem", but more importantly, I want to know how to fix it. I really want to keep some of the complex functions I have as abstractions to the programmer, but I don't want to alienate all ATI cards either. How should I fix the problem? Thanks, Geometrian
color.rgb += ambient_color.rgb*light_ambient(0).rgb;
color.rgb += diffuse_color.rgb*light_diffuse(0).rgb;
color.rgb += specular_color.rgb*light_specular_ph(0).rgb;
//replacing this line, which doesn't work
color.rgb += light_diffuse(0).rgb;
//with these lines:
vec3 l = normalize(gl_LightSource[0].position.xyz-vVertex);
float coeff = max(dot(normal,l),0.0);
color.rgb += gl_LightSource[0].diffuse.rgb*coeff;
//makes it work--and yet this is exactly what light_diffuse(...) does!
color.rgb += gl_LightSource[0].diffuse.rgb*max(dot(normal,normalize(gl_LightSource[0].position.xyz-vVertex)),0.0);