Jump to content
  • Advertisement
Sign in to follow this  
Max_Payne

Multiple Pixel/Vertex Shaders At Once?

This topic is 4855 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

I am in the process of programming a renderer, and this is something I have been wondering about for some time: Is it possible to run multiple vertex or pixel shaders at once? For example. Say I have a water surface, and I use a vertex shader to make it look like its waving. Then someone throws a grenade, and I run an "explosion distortion" shader, which distorts the scene. How would I go about that? Can the input from the water waving shader be passed to the distortion effect shader? Another problem: Suppose I use a different pixel shader for each surface. Some metal surfaces would use a bump mapping/specular mapping shader, but a grass surface might have its own shader to make it look like there are grass fibers sticking out. Is there a way to have a separate point lighting shader? Or am I forced to implement the lighting shader(s) as a part of both of these shaders? If its possible to do it separately, how do you go about doing that?

Share this post


Link to post
Share on other sites
Advertisement
in short, no.
You can have one vertex and/or one fragment shader active at any one time, if you want to combine effects you'll need to combine the shaders together in some way

Share this post


Link to post
Share on other sites
You can have only one Vertex Shader on at any one time, that receives data from you engine, does some computing, and passes it on to the Pixel Shader.

You can also have only one PS at any one time, receiving data from both the VS and the engine.

You can none the less turn off those and turn on new ones, to render another mesh, you can even have a VS/PS pair per mesh on your scene.

You can also make use of multiple passes. What you see onscreen is usually a combination of multiple tricks, and you have to get yourself away of the concept that it all get's done at once...

Share this post


Link to post
Share on other sites
Quote:
Original post by Prozak
You can also make use of multiple passes. What you see onscreen is usually a combination of multiple tricks, and you have to get yourself away of the concept that it all get's done at once...


Its obviously faster if its all done at once. But assuming it wasn't, is there an easy way to combine vertex effects using multiple passes?

Share this post


Link to post
Share on other sites
Since you saidthat you want todistort the scene in your example. You could render the scene to a texture, and then render a series of quads with the "scene" texture and distort those with a vertex shader and/or pixel shader.

As for the second example, if your using glsl, I think you can make seperate functions (in glsl) and link them with your vertex/shader programs. That may be enough to get what you want.

Share this post


Link to post
Share on other sites
Quote:
Original post by Cocalus
Since you saidthat you want todistort the scene in your example. You could render the scene to a texture, and then render a series of quads with the "scene" texture and distort those with a vertex shader and/or pixel shader.


Thats kind of inefficient still. I am thinking of actually distorting vertices in the same way that it's done in Doom 3 when you throw a grenade.

Quote:
As for the second example, if your using glsl, I think you can make seperate functions (in glsl) and link them with your vertex/shader programs. That may be enough to get what you want.


I suppose it would at least make things easier if I can have a function for lighting, which I can copy over or import into all my shaders if I'm going to need to integrate lighting into all effect shaders.

Its just going to be slightly annoying if I need multiple shaders for each material, like:

metal_sunlight (shader for outdoor rendering sun/moon light)
metal_2lights (shader for indoor lighting with max 2 lights)
metal_4lights (shader for indoor lighting with max 4 lights)
metal_8lights (shader for indoor lighting with max 8 lights)

grass_sunlight
grass_2lights
grass_4lights
grass_8lights
...

I guess its certainly doable, since once we've figured out how to do it, its easy, but its going to be alot of cut and paste work.

Share this post


Link to post
Share on other sites
you dont need to cut and paste.
A shader can be built up from multiple source files, the compiler and linker sort out all the details.
So you could have a series of source files with your code in and then load them into each shader as needed with a main function to pull it all together, just like when you make a normal program in C++.

Yes, you'll have to have multiple shaders because currently cards dont handle UberShaders all that well, so breaking them up into multiple shaders and multiple passes is infact better than trying todo it all in one.

You could also use procedually generated GLSL code, use some basic rules and have the program build the shaders for you, which would save you typing them all out yourself in the first place, just build them up from code snippets.

Share this post


Link to post
Share on other sites
Quote:
Original post by Max_Payne
Quote:
Original post by Prozak
You can also make use of multiple passes. What you see onscreen is usually a combination of multiple tricks, and you have to get yourself away of the concept that it all get's done at once...


Its obviously faster if its all done at once. But assuming it wasn't, is there an easy way to combine vertex effects using multiple passes?


Well, I was refering more to the psycology of people that look at the screen and think it all gets generated all at once... it doesn't. We know that.

Of course you can combine VS/PS effects using multiple passes. You can for example draw the pass off to a texture, and use it as input for guidance on the next pass, for some effect...

Share this post


Link to post
Share on other sites
so, for example, can I do something like this? Or I must make multipass?


void render(){

Set_Shader(Sunlight);
Set_Shader(Lighting);
Draw_ALL();
Set_Shader(Water);
Draw_WATER();
Set_Shader(Glass);
Draw_GLASS();
Disable_Shader(Sunlight);
Disable_Shader(Lighting);
Disable_Shader(Water);
Disable_Shader(Glass);

Set_Shader(Grass);
Draw_GRASS();
Disable_Shader(Grass);

Set_Shader(Post_Effect);
Disable_Shader(Grass);

}

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!