rate up
0
rate down
Lights in DirectX12
Hi, I wanna add some lights into my engine but cannot find any good tutorial about it, modyfying Dx11 to 12 made me headache. Can you give some hints or make a exception and post a tutorial how to achive this in Dx12? Regards :)
rate up
0
rate down
Hi maxiorek82, This could really turn out to be a pretty big topic, but the short answer is you can basically do the same thing as you did with dx11. Lighting is usually baked into the graphics or done in the shaders. You will have a couple different types of constant buffers, depending on how often they will be updated. Static lighting is usually only updated once per frame (lights that don't move or change, such as a street light), other lighting like headlights of a moving car will be updated once per frame. This update frequency is different than the constant buffer that holds per object data, like world/view/projection matrix. This constant buffer is updated per object, rather than per frame or per scene I think it's worth mentioning, renderers are moving to binding resources at "list" granularity, rather than individual resource binding. Might be something you want to keep in mind for your engine, especially if your going with dx12. Look at hodgman's reply here (first reply), where he kind of explains what his own engine is doing when it comes to resource binding: .[https://www.gamedev.net/topic/676777-d3d12-what-is-the-benefit-of-descriptor-table-ranges/?hl=%2Bdescriptor+%2Btable+%2Bhodgman#entry5279773][https://www.gamedev.net/topic/676777-d3d12-what-is-the-benefit-of-descriptor-table-ranges/?hl=%2Bdescriptor+%2Btable+%2Bhodgman#entry5279773] Basically, your application (game) will put together a list (or multiple lists) of things that the draw call will need, then that list of resources is bound. What this means is that you will build the lists, then during runtime you will simply tell the renderer to bind that list of resources for your draw call. This is where the descriptor table ranges come in to play at the beginning of your frame, you would get a list of all the lights that are in your scene (or the ones that are visible, where you might check against their bounding box and the view frustum, bounding box being the are the light covers). You would then send that list of lights to your renderer, which would grab each light resource and bind them to the pipeline. Every draw call after that which uses the light data would then use the bound light resources (light resources would be like a constant buffer for each light containing things like light position, color, direction, etc) Look at my directx 11 lighting tutorials to see how they do it, lighting works the same way in dx12, no difference since the lighting is all done in the shaders
Comments
Thanks for your tips, they are helpful, will try to solve some tomorrow. Thanks to your tutorials I've made scene loader, 3ds importer with uv textures, UI and many more ;) To bad that many of DX11 tutorials need big modifications but made them quite easy and the biggest problem is with lighting :) hope to solve it soon :)
on Apr 17 `17
maxiorek82
Sign in to answer!