Jump to content
  • Advertisement
Sign in to follow this  
Shaarigan

OpenGL Shader engine generel questions

This topic is 2571 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

while were developing our graphics engine on OpenGL were at the point where it is important to use shaders to our
scenes. I looked at the unreal engine shaders and were confused about there system of different parts of shaders onnected
to the scene.

My Question now is, if i have one lightsource i use one shader for my scene but what is if i have several different lightsources and
something else like water-shader, sky-shader and a particle-shader for fire in one scene?

Are they connected to one shader and whats going on with eah of these shaders main-function? or are they differently loaded and rendered but
how is this done in rendering process and then dropped to scene? Edited by Shaarigan

Share this post


Link to post
Share on other sites
Advertisement
You should have many different shaders. Each material type you use should use the fixed function pipeline or have a custom shader. The number of shaders and what they do is entirely up to you.

You should look into GLSL. I would also recommend the OpenGL Orange Book. This is a very broad topic and is going to require some time before making some of the advanced effects seen in games.

But, in a netshell this is what needs to happen.

-Load and compile the shaders you are going to use.
-For every object drawn in the scene. use a shader using glUseProgram and draw the object. The object will be drawn with that shader. you may also pass a 0 to glUseProgram and openGL will use the fixed rendering pipeline.

Hope this helps

Share this post


Link to post
Share on other sites
I already know and implemented shaders in my engine.

I dont understand eg i have a scene with a character and that character has a torch on it. How could that done when i use
a shader to iluminate my scene by the torch, a second one that lets the character glow magicaly blue and a third one thats
illuminating the scene (the moon or a bigger fire) also effects my character. This ment i had to render my character three times
with different shaders or should i compile my shaders to one shader during runtime or how?
I already read that there is no #include in GlSl implemented at the moment so i had to merge my shaders by myselfe?

And as is sayed,i dont know how big engines like Unreal do that when using hundrets of different shaders to a scene.

Share this post


Link to post
Share on other sites
Hi,
Lighting is difficult subject and there are lots of information around the internet about different implementations.

First to answer your question:

- you may go down the path that for each object you calculate which are the affecting lights and then render the object to light accumulation buffer as many times as there are lights. This is rather slow of course.

- To optimize the case, you may make a long shader which handles multiple light sources of different types in one pass. you may make a shader with lots of #ifdef's to create an optimized shader for each required lighting/material case. This will result tons of different kind of shaders to manage. Also, you may choose to limit the amount of lights affecting each object by choosing the strongest/nearest light sources. This is better of course. However, it still takes lots of efforts to see which light affects which object. Also, drawing lots of objects in same time (instancing) is difficult.

To over come the problems presented in the cases above, many people choose to use deferred shading/lighting approach which basically allows lots of lights to affect single object / pixel. Of course deferred shading comes with it's down sides too.

Cheers!

Share this post


Link to post
Share on other sites
So to let me come forward, i should manage my shaders in different files but to use them i should
merge them together to one file and then make differences to each situation?

Share this post


Link to post
Share on other sites
For your torch example you pass the light position and properties to each shader. Your world shader will get those properties and then your animation shader for the character will get a 2nd copy of those properties. They will have partially the same code with the lighting, but the character will have animated bones and/or other computations. So you will be doing a lot of copy/paste type stuff inside of several shaders.

Each shader is separate, there is no 1 file. You use whatever shader you want at any time.

Share this post


Link to post
Share on other sites
There are different techniques to handle shader management.

- You may create few so-called über-shaders with lots of #defines ands #ifdefs to handle different lighting / material permutations.

- You may also use something called dynamic shader linkage (I'm not totally familiar with this) which is AFAIK practically about having small pieces of shader functionaly and linking them together to form a complete shader for each situation.

- Or you may take a different route and implement deferred shading. Of course you'll need to look what you really need to accomplish and what are the limitations of each technique.

Cheers!

Share this post


Link to post
Share on other sites
So i make something that manages #include tags, copys shader files together that were included and merge the main functions to get
one File that contains functions on different situations for my models.

Share this post


Link to post
Share on other sites

So i make something that manages #include tags, copys shader files together that were included and merge the main functions to get
one File that contains functions on different situations for my models.


This doesn't really make sense. There shouldn't be any reason to "manage #include tags or copy shader files together". It is more like compiling a shader with certain set of flags (the übershader case) or compiling shader parts and joining them together with the opengl api (the dynamic linkage case).

Well, now I notice that you are using opengl and I'm not the person to respond to opengl specific questions.

Perhaps you should present a real world problem you are facing with your shaders so that a more precise piece of advice may be given.

Cheers!

Share this post


Link to post
Share on other sites

This doesn't really make sense. There shouldn't be any reason to "manage #include tags or copy shader files together". It is more like compiling a shader with certain set of flags (the übershader case) or compiling shader parts and joining them together with the opengl api (the dynamic linkage case).


There isnt any way to combining compiled shaders in opengl because you can link only one shader of each type to a program. Also there isnt any #include-statement in GLSL.
In generating a shader i push my shader file as a set of strings to the api and ink al shaders (fragment, vertex) to a program. So i dont know any dynamic linking mechanic.

The example i've given above is what it is pointing on !!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!