Apply two or more shaders...

Started by
4 comments, last by Pulsar79 15 years, 4 months ago
It is a basic question of shaders: If I have a shader that does "Specular" and have another shader that produces "Bump", if I want to apply these two shaders to a mesh, since I can do it? The exit of a shader can gather the following shader, or on the contrary, the code of the two shaders has to be integrated an alone shader, or it will have to do a shader with several steps or passes?. He would be grateful much someone could solve this doubt. Thank you very much.
Advertisement
Quote:Original post by Pulsar79
It is a basic question of shaders:
If I have a shader that does "Specular" and have another shader that produces "Bump", if I want to apply these two shaders to a mesh, since I can do it?

The exit of a shader can gather the following shader, or on the contrary, the code of the two shaders has to be integrated an alone shader, or it will have to do a shader with several steps or passes?.

He would be grateful much someone could solve this doubt. Thank you very much.
You'd have to do two passes, or combine the two shaders into one (Which would be much more efficient). The Fragment Linker can be used to do this I believe, although I've never used it myself.
Thank you Steve. I already was thinking that more or less I would have to do something like that. Thank you for extracting myself of doubts.
Quote:Original post by Evil Steve
The Fragment Linker can be used to do this I believe, although I've never used it myself.
It can indeed help with this, but as a word of warning this technology did disappear in D3D 10 and 10.1 and returned in a different form for 11.0. Depending on who you speak to the whole concept of shader linking is a bad idea and/or shouldn't be done [rolleyes]...

For the most part a multi-pass or straight up combination of the HLSL should do the job.


hth
Jack

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

Are you afraid to the shader's count is too large in your engine?

In direct3d9's HLSL.

I think that there is some simple method to solve it.

1. Use pre-defined macro to compile a shader with some different route. For example:
/*
* float4 ps_main(...) : COLOR0
* {
* float4 result_color = 0; // This line will be skip by compiler, don't worry about it.
*
* #if USE_SPECULAR
* result_color += ...;
* #endif
*
* #if USE_NORMALMAP
* result_color += vertex_normal_lighting_result;
* #else
* result_color += pixel_normal_lighting_result;
* #endif
*
* return result_color;
* }
*/

Reference to D3DXCompileShader/D3DXCompileShaderFromFile's parameter "CONST D3DXMACRO* pDefines",
The macro can be defined in C++ program dynamic.

2. If your shader's count increase's reason is the large count of the material shading.
you can use tools for generate pixel shader automatic. The follow tool can complete these work.

[1]. Mental mill (TM) Artist Edition.

Thanks everybody. I believe that with these solutions I can do a good shader. Thanks. I don't have any doubt.

This topic is closed to new replies.

Advertisement