Skip to main content
gamedev.net
🔒 Locked

Same codes in shader program

Started by Hybrid3D 4 replies 1k views
Original Post
Hybrid3D
Hybrid3D
1. I wanna use shader for changing the only few features of pipeline. (other people may want to) But, in using shader, do I have to implement all the features of those (vertex or pixel of both) shaders? I think it is a wasteful that I make common same code for all shader programs, such like, lighting or texturing which are all implemented by default opengl pipeline that I don't want to change. Is there any other way? Do I have to paste same codes all the shader files? 2. I know '#include' is not permitted in shader code. So, Is there any other way?
_______Imagination is more important than knowledge - Albert Einstein
christian h
christian h
You can give the GLSL interface multiple source buffers, which is sorta like using #include directive. This way you can declare source with common functions and "link" that with specific shaders.

void ShaderSourceARB(handleARB shaderObj, sizei count, const charARB **string,
const int *length)

You just make a list of sources:

std::vector<charARB*> sources;for ( files )    sources.push_back ( read_file( file ) );glShaderSourceARB( handle, sources.size(), &sources[0], 0 );


ch.
jpetrie
jpetrie
Quote:

I think it is a wasteful that I make common same code for all shader programs,
such like, lighting or texturing which are all implemented by default opengl pipeline that I don't want to change.


Once you use a shader, you've replaced the entire portion of the pipeline where the shader would go, even if your shader doesn't implement portions of that pipeline. You can't use a vertex shader for, say, transformation but still use the default fixed-function lighting.

You'll have to implement a mimicry of the fixed-function aspects you'd like to keep (I believe GLSL has an ftransform() that will aid in this), and include those into your composite shader program somehow (perhaps in the manner suggested by the above poster).
Hybrid3D
Hybrid3D
thank you for your advice :)

[Edited by - ilys4 on September 24, 2006 3:14:09 AM]
_______Imagination is more important than knowledge - Albert Einstein
jfdegbo
jfdegbo
As shaders are just strings before to be uploaded into the card, keep in mind that YOU can manually implement an #include macro. Scan the string, once found "#include", read the next string and subsitute the two by the content of the file... that can sound stupid, but in fact that is not so many work...
_____My little engine : I.E.
Hybrid3D
Hybrid3D
Quote:
Original post by jfdegbo
As shaders are just strings before to be uploaded into the card, keep in mind that YOU can manually implement an #include macro. Scan the string, once found "#include", read the next string and subsitute the two by the content of the file... that can sound stupid, but in fact that is not so many work...

Wow, It doesn't sounds stupid at all, but It sounds pertectly fitting method in this problem. Thank you :)
_______Imagination is more important than knowledge - Albert Einstein

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.