Regarding GLSL

Started by
3 comments, last by RoyChen204 15 years, 9 months ago
Hi, I am new to this forum and am in a course of game programming. I was given an assignment which I wanted to attempt implementing shaders but I have some theory-based problems. Thus far, I know how to compile and link a shader, but otherwise I am still relatively weak. My question is as follows, for example, I have a polygon depicting the ground. There are various effects I wish to implement unto it, but when I have another polygon, I only want part of the effect that was implemented onto the first polygon. How is that achieved? I am under the impression that shaders affect everything in the display when in execution, hence I feel confused about proceeding. Thanks.
Advertisement
Shaders don't affect things that have already been drawn, only those things which are drawn thereafter.

You'd probably want two shaders, one more complex than the other, the rendering sequence would then be something like this:

1) Bind complex shader
2) Render first polygon
3) Bind less-complex shader
4) Render second polygon
I see, but is there no way for the functionities of the different shaders to merge? does that mean I have to

for example

polygon 1 takes 2 effects

then if I follow your method

I ll have to type another shader file with one of the effects and add another effect?
With GLSL you can divide code up into functions. You can also divide the functions up into individual files creating a library.

So as kind of a general example to get what you could potentially do. Note that I'm leaving out whether your effect is being done in the vertex or fragment shader since this is more about how the linker can be used with GLSL so you don't have to create a monolithic shader.

// foo.glslvoid foo(){  // Create the foo effect}


// bar.glslvoid bar(){  // Create the foo effect}


// barEffect.glslvoid bar(); // Forward declaration of barvoid main(){  bar();}


// foobarEffect.glslvoid foo(); // Forward declaration of foovoid bar(); // Forward declaration of barvoid main(){  foo();  bar();}


So as a kind of quick pseudocode as how to setup the program objects.

void initializeFooBarShaders(){  // Compile shader code     // Compile foo.glsl     // Compile bar.glsl     // Compile barEffect.glsl     // Compile foobarEffect.glsl  // Create program objects     // Create barEffectObject        // Add compiled bar.glsl        // Add compiled barEffect.glsl        // Call the linker     // Create foobarEffectObject        // Add compiled foo.glsl        // Add compiled bar.glsl        // Add compiled foobarEffect.glsl        // Call the linker}


From there you'd do like dmatter suggested in terms of the drawing.

If you want more concrete examples of how to create a shader library check out my gamedev article <http://www.gamedev.net/reference/programming/features/glsllib/>
Okay, I see

Thanks a lot for answering.

This topic is closed to new replies.

Advertisement