For some details on the algorithm and implementation, see below ^^
Once upon a time I saw some images generated with basic shapes that tried to approximate some given image. Because I like the style, I made something like that myself. Problem was: There arenโt many good libraries to perform drawing shapes that also handled transparency and per-pixel operations. Coding all of that myself was too much work, so I used the easiest solution: JavaScript. Problem was... JavaScript is slow. Drawing a few hundred triangles and then comparing the resulting image to another given image was a lot of work, even using multiple workers to distribute it. I got maybe 5-10 images per secondย that way. The algorithm I use is pretty simple but slow... so it took hours for at least some reasonable results.
A few days ago I decided to revisit this thing with the help of my trusty GPU. Basically I redid everything so it runs completely on the GPU. I now have about 600 images per second!
Here you can see some of my most liked pokemon :)
Following are some more details on how it works:
The algorithm: Take a set of triangles. Each consisting of three 2D vertices and a color with transparency. Now you draw them all. Now you compare the resulting image with the one you want to approximate. This can be done for example by comparing each pixel and adding the squared differences of each color channel (squaring makes everything positive, which is good, and also is a nice and smooth function). If the result is better than your current best, use this new one as your new best. Now you go over your triangles and with some probability change their vertices or colors. Then repeat from the drawing phase. This is a simple hill climbing algorithm. If you are more precise, this isnโt really a evolutionary/genetic algorithm, as there isnโt a population with stuff like crossover happening. But being a bit more informal here (and for the title to make sense :D) I will still call it evolutionary. Just think of it as having a single individual reproducing. Only the best will survive and live as long as it stays the best, outliving all its children. Each generation mutates slightly and has to adapt to the environment. So I would say the naming is at least a bit justified.
The implementation: If you want to do something like this, here is the general recipe. You generally want to avoid transferring data from your CPU to the GPU and back, as copying stuff needlessly is not good. My implementation uses OpenGL, but you may choose any other API, as long as it provides compute shaders and writeable buffers (you could of course emulate that with textures or other techniques, but that would require some more thinking). You put all your triangle data in a buffer. I use one vec2 buffer for the positions (length = triangles*3) and one vec4 buffer for colors (length = triangles). Those buffers are bound as a shader storage buffer object (SSBO) and can be accessed by all shader stages. One Compute shader updates the triangles. Each work item processes one triangle. The only important thing here is, that you have to implement your own pseudo-random number generator. Probably the best way is to upload some initial random seeds and then use a simple linear-congruental generator (https://en.wikipedia.org/wiki/Linear_congruential_generator). I use a more involved Tau-step generator, which is probably overkill, but I had it l lying around (used it in monte-carlo simulations, where the randomness is a bit more important).
The drawing phase can be very simple. Just bind your SSBOs as vertex buffer objects and draw with triangles mode. Or the more complicated (which I did for some reason, probably because of some other code I used elsewhere...): Draw n=triangles instanced points. Use a geometry shader to generate a triangle for each point from the buffers. Then just render normally. Will probably change that and hope to see some improvements. The result is rendered in a frame buffer object with attached color texture.
The next step is just some screen quad/triangle shader comparing each pixel of the input image with the rendered one and calculating the difference. This is again put in a frame buffer object texture.
The important part is the error calculation. If you use some kind of sum of values, which is probably reasonable, you have the problem of it being more of a sequential algorithm. Luckily there is a parallel sum algorithm (for example here https://developer.nvidia.com/gpugems/GPUGems3/gpugems3_ch39.html). If you render the drawing in a frame buffer object, you can bind the output texture as an image and use it for read/write operations. Thinking about the image being just rows (or columns) layed out sequentially, it is easy to transfer the 2D image sum problem to a 1D one corresponding to the algorithm.
A simple shader with only one dispatch item just copies the result into another SSBO, where the current maximum is also stored.
Next compute shader goes over all triangles. If old error in the SSBO is larger than the current one, this will just copy the contents of the current triangle buffer to the โbestโ buffer.
Only copy to CPU and back operation I do is to download the error and draw the image on the screen and for some error difference output it as a file. Then upload the buffer with the updated current bestย error.
And that was basically all, in short form of course. You can of course do a lot better. Much to optimize, maybe use a real evolutionary algorithm, etc... But this was more or less a short two evening project, so itโs alright for now ^^
Anya is live and ready to show you everything. Watch her strip, dance, and perform exclusive shows just for you. Interact in real-time and make your fantasies come true.
โ Live Streamingโ Interactive Chatโ Private Showsโ HD Quality
Anya is LIVE right now
FREE
Free to watch โข No registration required โข HD streaming
Programming friends: I have a program that I'd like to write which will involve GPU calculations. I'm debating between going all-in with C++ and CUDA, or the high-level approach of WebGL (probably with JS, but maybe compiling something to WASM if the other parts of the code need a boost). I understand that CUDA can be much faster (my GPU is Compute Capability 8.6, fwiw), but my C++ experience is near-zero and what I'm doing is fairy simple (e.g., not NN/AI), so a high-level approach should be fine. Thoughts on these two, or is there a high-level approach which retains the power of CUDA in a friendlier package?
If youโre a gamer, your graphics card is likely to be one of the most expensive components in your entire rigโso you want to be sure youโre getting the most out of your investment. As with other pieces of hardware, the graphics card requires some careful care and attention over the course of its life to make sure itโsโฆ
Read moreโฆ
New Post has been published on https://videogaming.newonline.help/neoseeker-gpu-test-rig-upgrade-featuring-corsair/
Neoseeker GPU Test Rig Upgrade Featuring CORSAIR
Hello Neoseekers and welcome to another article. Today Iโll be upgrading the GPU test system with some of the best components available on the market courtesy of CORSAIR. The current rig needed some tweaking in preparation for the imminent reviews of the new NVIDIA RTX 30 series video cards. With that in mind, I wanted to leverage the CORSAIR iCUE software for my system customization, monitoring, and control. CORSAIR iCUE is a unique ecosystem offering several QoL enhancing features and a streamlined way to keep an eye on compatible hardware. The whole process was made easier with the recent release of the CORSAIR iCUE NEXUS Companion Touch Screen. The nifty little unit puts the power of iCUE software at userโs fingertips and offers a separate display for monitoring.
ย Some of the parts I will be using were already covered in previous reviews including the Dominator Platinum RGB memory, K95 RGB PLATINUM XT gaming keyboard, Dark Core RGB Pro gaming mouse, and iCUE NEXUS Companion Touch Screen. The new components I will be adding to the system are the Crystal Series 680X RGB Smart Case, iCUE H150i RGB PRO XT Liquid CPU cooler, and HX1000i 1000-Watt 80 PLUS Platinum Certified power supply. I will cover these items in greater detail over the next few pages and share my experience working with them during the upgrade process.
Before we dive in, hereโs the full list of components going into the final build:
Case: CORSAIR Crystal Series 680X RGB
CPU Cooler: CORSAIR iCUE H150i RGB PRO XT
CPU: Intel Core i9-9900K
Video Card: NVIDIA GEFORCE RTX 2080 Ti Founders Edition
Motherboard: MSI MEG Z390 ACE
RAM: Corsair Dominator Platinum RGB White 32GB DDR4 4000MHz
SSD: Patriot Burst 480GB SSD
HDD: Seagate FireCuda Gaming SSHD 2TB 7200 RPM
PSU: CORSAIR HX1000i 1000-Watt 80 PLUS Platinum Certified
Mouse: Corsair Dark Core RGB Pro
Keyboard: Corsair K95 RGB PLATINUM XT
As usual, I follow a few basic guidelines when handling PC hardware, such as making sure I have my antistatic bracelet on throughout the setup, and roughly map the build before screwing the parts together. The workspace for this build is a large table, allowing me to have all the components within armโs reach. I tend to use a large mouse pad or cardboard sheet to protect the table surface and components if needed.
Anya is live and ready to show you everything. Watch her strip, dance, and perform exclusive shows just for you. Interact in real-time and make your fantasies come true.
โ Live Streamingโ Interactive Chatโ Private Showsโ HD Quality
Anya is LIVE right now
FREE
Free to watch โข No registration required โข HD streaming
Aitech Going Global, Ready for Next Stage: AI at Battlefield and Space Technologyย
Defense Embedded Systems: AI, Deep Learning, Cyber Security and GPGPU Rugged computer systems for the defense and space industries will be at the center of the coming Defense Embedded Systems Conference organized by Aitech. The companyโs rugged and secure hardware platforms conform to the h
(Image shows a GPU pathtraced tinted glass bunny with some non-reflective patches and some other objects with different materials being illuminated by a box light source)
About two weeks ago I scrapped together some old GPU pathtracing code for a small demo for some school students. It was able to do basic diffuse lighting and perfect reflection and reflection of spheres and boxes.
I like pathtracing, so I spent a few evenings putting some more stuff into it, like bounding volume hierarchies, some more BSDFs, direct light sampling, different importance sampling techniques and texture support for diffuse and specular components. Everything is a bit hacky and not super optimized in shader code, but it runs interactively (though depending on the scene, this is like 1 FPS). Nethertheless, it works and looks decent enough and I had a bit of fun coding.
(Sponza model with area light source, a mirror and a glossy sphere)
(Sponza model with area light source, a mirror and a glossy sphere, this time with higher roughness, making the reflection look more diffuse)
(different translucent objects. The refracted light is focused nicely on the other side of the objects)
(slightly older version with some different parameters)