Sign in to follow this  

Apply two or more shaders...

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

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

This topic is 3287 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this