Sign in to follow this  

DirectX11 and using more than 1 shader

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

Hello everyone!

I'm learning DirectX for 2 weeks, and I know how to create primitives, add them to the scene and apply the Shader for the whole scene.

I can't find in any book or sample anything about applying the shader on a single Mesh (not on the every Mesh).

Can you tell me how can I apply a shader to a single Mesh ? I don't want to have just 1 pixel shader for every Mesh.

Edited by J.K

Share this post


Link to post
Share on other sites

Each draw call uses the shaders (and other pipeline state) that were set on the device context previously.

 

Set Vertex Shader V1

Set Pixel Shader P1

Draw Mesh 1 (uses V1 and P1)

 

Set Pixel Shader P2

Draw Mesh 2 (uses V1 and P2)

Share this post


Link to post
Share on other sites

Ok, thanks.

So if I want to change a shader for 1 Mesh 'At runtime' I will have to reinitialize and redraw only this Mesh?

Share this post


Link to post
Share on other sites

Are you using some framework that we're not aware of? I suspect our definitions of the term "mesh" differ somewhat.

 

Each frame does basically the same thing:

- clear the entire screen

- for each "thing" you want to draw

   - set up the pipeline (probably at least a vertex buffer, a vertex shader and a pixel shader)

   - call draw

- repeat

 

If you want to use a different pixel shader for a specific object, you just use that pixel shader when setting up the pipeline for that object.

To start with, I suggest setting up the pipeline from scratch for each object. Optimizing for performance comes later.

Share this post


Link to post
Share on other sites

Ok, thank you very much for your help.
I have found an issue with handling .cmo files in Visual Studio 2015, also with DirectX11 (SharpDX) but this is the subject for another question :).

Share this post


Link to post
Share on other sites

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