how to access functions from other shader objects?

Started by
3 comments, last by Achilleos 16 years, 10 months ago
Hi, i want to split my shader sources into seperate files. I got the main function of my vertex shader (containing the calculation i am currently working on) in one file and want to "include" another file where the lighting calculations are made. So the second file has no main function. But the linking could not be reached because the main shader file throughs an error when its compiled. The fundtion i call from the other file is unknown. How do i declare the function for the first file? Here is error message (nvidia opengl 2.1.1): error C1008: undefined variable "ApplyLighting" error C1105: cannot call a non-function Previously i worked with a single vertex and a single fragment shader, but i guess it's kind of dowdy to copy and paste source code extracts to similar shaders... Greetz, Achilleos.
Advertisement
If you look exactly at the glShaderSource function you will notice that it gets an 2d array of chars. So a array of strings. Now if you wan't to get multiple files into one vertex shader you have to load all of them and place them in right order into such an array. OpenGL will then handle this source as if it's one big file. AFAIK this is the only way doing what you want.
http://3d.benjamin-thaut.de
thanks alot.
i will try that later.

greetz.
on second thoughts i dont think its how it should be done. the opengl shader compiler tells me, if i made mistakes, in which line the error has been made. this information will be false if the preprocessor copies the source into one big source block.

apart from that it should be possible to work with seperate shader objects, because it has been made possible to attach multiple shader of one type to a shader program. but you can only have one main function, so why the possibility to attach multiple shader objects if you could not use functions defined elsewhere.
there must be some "include" qualifier i am missing.

but randi rosts opengl shading language the second edition does not say something about it. they always use a simple pair of shader. one shader object for one shader program...

the reason why i want to use multiple files is, that i am implementing graphical features for a simulator platform. therefore everything done whitin the code has to provide a highly customizable interface to the outside. there are multiple different scenes with varying number of lights and objects with multiple and no textures applied to them. to get a slim performance boost i want not only to seperate the lighting but also "include" constants per scene instead of supplying the needed information per uniforms...

if there are any further guesses... it would be great.

thanks in advance,
Achilleos.
hi,

i solved the problem. i've found a thread from 2004, which encounters the same error message. but there it was a driver issue and my fault was to add the function definition of the lighting function in the main file. therefore adding the the functions head solved the problem.

#version 110void ApplyLighting(in vec3 ecPosition3,                   in vec3 normal,                   in bool LocalViewer,                   in int NumEnabledLights,                   in bool SeperateSpecular,                   out vec4 color);void main(void){  // calculate position  gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;    // calculate eye coordinate position  vec4 ecPosition = gl_ModelViewMatrix * gl_Vertex;  vec3 ecPosition3 = vec3(ecPosition) / ecPosition.w;    // calculate normal  vec3 normal = gl_NormalMatrix * gl_Normal;    // apply the lighting (fixed function)  vec4 color;  ApplyLighting(ecPosition3, normal, true, 2, true, color);    // write back the color information  gl_FrontColor = color;}


and here is the thread:
http://www.gamedev.net/community/forums/topic.asp?topic_id=273012

good night everybody! ;)

This topic is closed to new replies.

Advertisement