Advertisement

Can shaders have same constant buffer?

Started by August 07, 2021 01:33 PM
2 comments, last by eu5 3 years, 6 months ago

Hi.

If I set the constant buffer called “CB_Light” for a VERTEX shader and after set this “CB_Light” for a PIXEL shader,

this constant buffer is valid in both shaders?

like this

	DeviceContext->VSSetConstantBuffers(0, 1, CB_Light.GetAddressOf());
	DeviceContext->PSSetConstantBuffers(0, 1, CB_Light.GetAddressOf());
	DeviceContext->Draw(..);

Is CB_Light valid in both shaders?

Yes you can do that. You just need to make sure the same cbuffer is declared in HLSL for both your vertex shader and pixel shader. If your VS and PS are compiled from different files, one way to share the cbuffer is to declare it in a third HLSL file and #include it from both your VS and PS files.

Advertisement

@MJP Thanks! I didn't know about the including in HLSL.

This topic is closed to new replies.

Advertisement