DirectX11 and using more than 1 shader

Started by
3 comments, last by J.K 7 years, 8 months ago

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.

Advertisement

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)

current project: Roa

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?

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.

current project: Roa

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 :).

This topic is closed to new replies.

Advertisement