The best way to simulate fixed function via shaders lazarus / 39-Graphics ---------------------------------------------------------------------- Mr.Madguy · 2022-03-12 07:32 Please note, that I don't talk about specific 3D library here, as shaders are quite similar in all of them. I talk about universal methods. I see two possible methods here. Both have their pros and cons. 1) Universal shader. Easier to use. Doesn't require code changes. But has to use branching and/or loops, that can cause performance penalties, especially on older hardware. 2) Specific shader for every configuration (number of lights, light types, etc.). More flexible method, that can be extended later. But requires shader management and implementation of special "shader state" objects, that change whole code logic, in order to avoid performance penalties due to searching for proper state and higher memory usage to store these states. What is better? ---------------------------------------------------------------------- circular · 2022-03-12 14:28 I suppose one could do something intermediate, like allocated slots for different types of lights. Then you would have to recompile the shaders only when you need to add/remove slots. For example you could change slots 4 by 4, so that you don't recompile all the time. ---------------------------------------------------------------------- Seenkao · 2022-03-12 15:22 Если речь идёт об OpenGL. Не обязательно что-то имитировать. Все устаревшие функции (фиксированные) на данный момент эмулируются если у вас видеокарта поддерживает OpenGL 3+. Устаревшие функции удалены полностью, и заменены их эмулируемым аналогом. Возможно вы об этом не знали?! Вы можете просто их использовать, а видеокарта сама за вас всё сделает. Но конечно же потери в производительности будут. Но если браться и правильно переводить работу устаревших функций, то тут надо много усилий приложить. Это достаточно тяжелый и не благодарный труд. Мало кто будет этим заниматься. google translate: When it comes to OpenGL. You don't have to imitate anything. All deprecated functions (fixed) are currently emulated if your graphics card supports OpenGL 3+. Deprecated functions have been removed completely and replaced with their emulated counterpart. Perhaps you didn't know about it? You can just use them, and the video card will do everything for you. But of course there will be performance losses. But if you take and correctly translate the work of obsolete functions, then you need to make a lot of effort. This is quite hard and not rewarding work. Few will do it. ---------------------------------------------------------------------- Mr.Madguy · 2022-03-12 19:00 My current idea - is to have "shader state" objects, that would include all needed data instead of allowing user to change pieces of this data separately, as it was done back in fixed function era. In this case shaders would be managed by user. It's compromise between recompiling shader every time and having complex state manager, that would store all states in a tree form, so searching for proper state would be required, that would possibly kill all performance benefits. But such solution would complicate things anyway. May be there is better way to do it? As I know, modern hardware doesn't have any major problems with branches and loops. But I still want to make my solution as optimal, as possible. It would be pointless to switch to shader model, if it wouldn't have better performance, than fixed function. My current tests show, that fixed function in OpenGL 1.0 with all possible extensions (obviously) = OpenGL 2.0 and ~2x slower, than Direct3D 8, 9, 9Ex. ---------------------------------------------------------------------- Seenkao · 2022-03-12 22:50 Подобное сделать можно, но как я и писал работы очень много. Больше даже не от шейдеров будет зависеть, а от передачи массивов вершин, цвета, текстуры и прочего. Если всё делать для 3D то это ещё больше работы. Честно говоря, расписывать весь процесс очень долго. А делать ещё дольше. И, можно спокойно на устаревшем OpenGL догнать и даже (где-то) перегнать DirectX. Но всё от умений зависит. Andru сумел ускорить процесс работы с 2D (на устаревшем OpenGL) в 2 и более раза (не везде, но зная как это работает, можно создать достаточно быстро работающую программу). Если интересно как он это сделал, то можете заглянуть в ZenGL. Используя batch2d_Begin, batch2d_End. google translate: This can be done, but as I wrote a lot of work. It will no longer even depend on shaders, but on the transfer of arrays of vertices, colors, textures and other things. If everything is done for 3D, then this is even more work. To be honest, it takes a very long time to describe the whole process. And do it even longer. And, you can easily catch up with outdated OpenGL and even (somewhere) overtake DirectX. But it all depends on skill. Andru managed to speed up the process of working with 2D (on outdated OpenGL) by 2 or more times (not everywhere, but knowing how it works, you can create a fairly fast program). If you are interested in how he did it, you can look into ZenGL. Using batch2d_Begin, batch2d_End. video where I did the tests. 4:24 - 13th demo.   OpenGL, GLES, OpenGL+batch2d, GLES+batch2d. 12:52(batch2d - on), 13:26 (batch2d - off) - 6th demo - the difference is obvious. ---------------------------------------------------------------------- Seenkao · 2022-03-12 22:59 https://www.gamedev.net/tutorials/programming/graphics/opengl-batch- rendering-r3900/ - you may be interested.