🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Can shaders have same constant buffer?

Started by
2 comments, last by eu5 2 years, 10 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?

Advertisement

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.

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

This topic is closed to new replies.

Advertisement