how do I use more than one shader?

Started by
11 comments, last by JohnnyCode 13 years, 4 months ago
Hi peoples,
how do I use more than one shader?
example: I have shader (many HLSL) shadow, light, blur effect, normal mapping etc.
and how can i use all in one model?
Advertisement
anyone?! :(
http://mateusvitali.wordpress.com/
1/ It depends on how you've organised your shaders.

Is it 1 shader .fx file with many HLSL techniques or is it many fx files with 1 tech in each?

2/ Once you know what organisation you want, then you have to decide what shader to use on your model and when.

Things to look for:
- is it an opaque model or does it have alpha?
- are you rendering front-to-back or the opposite?
- is model made of composite material or singular ones?
- are you permanently shading your model with all these techniques or is just to react to a game state (bullet hit or else)?
- etc...

3/ are you using dx9,dx10,dx11,ogl,sdl or what?

4/ also, are you rendering from a vertex cache manager or not? (which you should have)

G'luck.


Hi G'luck, i have many fx shaders HLSL (1 light.fx, 2 blur.fx, 3 bump mapping.fx )
my models is opaque,
i'm using DX9 and C++
vertex cache manager ? no
It doesn't matter how much shader you have. The graphics pipeline have a fix amount of stages and each programmable stage can have only one shader attach to it at a time. Make perfect sense seeing that having two vertex shaders for the same vertex make no sense. As such, for each pass you can have only 1 vertex shade active, 1 fragment shader active and one shader for each of the additional programmable pipeline stages.
Excuse me guys, but I want to know:
i have the models: ground, house and a tree
i want render it with shader.
Example:

configAllEfect(); //config all effect (texture, matrix, etc..)
BlurEffect->begin();
LightEffect->begin();
BMEffect->begin();
groundMeshX->drawSubSet(0);
houseMeshX->drawSubSet(0);
treeMeshX->drawSubSet(0);
BlurEffect->end();
LightEffect->end();
BMEffect->end();

how ?
As cgrant said, you can only have one vertex/pixel shader at one time.
Since you're using effects, you can only use one effect at a time.

If you want multiple effects, you have to combine them yourself into one shader.


BTW, what does your BlurEffect do? Blur is normally an effect that needs post-processing. That means, you cannot use that shader to render a blurred image in one pass. You first have to render to a rendertarget (a special type of texture), then you can take that image and render it to the screen, using your blur shader.
Quote:Original post by Tubos
BTW, what does your BlurEffect do?


nothing, i just quoted as an example :D.
Quote:Original post by Tubos
If you want multiple effects, you have to combine them yourself into one shader.

how ?
Quote:
how ?

By authoring them as composed effects. If you used to have EffectA and EffectB, you instead write one EffectC that does what EffectA and EffectB both did.
Quote:Original post by jpetrie
Quote:
how ?

By authoring them as composed effects. If you used to have EffectA and EffectB, you instead write one EffectC that does what EffectA and EffectB both did.


sorry, i dont understand, have a example code ?

This topic is closed to new replies.

Advertisement