Ridiculously Easy 3D in C (Color Quantization)

Поділитися
Вставка

КОМЕНТАРІ • 93

  • @Je3f0o
    @Je3f0o 7 місяців тому +345

    I'm a graphics developer. I developed a Game Engine in C. I know only 200 spheres are nothing for your graphics card. Reason why your FPS dropping is, because raylib maybe 200 draw calls behind the scene. If you optimize ur draw calls u can only 1 draw call and draw more than 10000 spheres without any problem. Graphics card and CPU is actually like server client architecture. Imagine u send 200 sync requests to server for each sphere, instead 1 request for 200 spheres...

    • @judahmatende3769
      @judahmatende3769 7 місяців тому +27

      makes sense

    • @sournois90
      @sournois90 7 місяців тому +14

      damn makes sense

    • @matthias916
      @matthias916 7 місяців тому +4

      doesnt raylib already buffer everything with the begin and end drawing methods?

    • @balisticemerald8512
      @balisticemerald8512 7 місяців тому +19

      I feel the problem is also that Raylib generates a new sphere each time you do a DrawSphere() call. Like I did some messing around and you can get a lot of performance if you load a sphere model before the loop and then draw that model instead of doing DrawSphere(); You can get a simple sphere with LoadModelFromMesh(GenMeshSphere(radius,slices,rings)); so thats also pretty neat
      Like in the DrawSphere() case I draw 1,000 spheres at like 15fps but when drawing the pre-loaded sphere model I get like 40fps when doing 10,000 spheres. Both using -O3 as the flag if that matters for graphic stuff, and I loaded a model with 16 slices and rings which is the same number DrawSphere() uses.
      It's by no means a professional test, but you can notice it running better

    • @Je3f0o
      @Je3f0o 7 місяців тому +13

      @@matthias916 I don't know how raylib implemented under the hood. But I'm damn sure it's not about how many triangles, vertices and fragments. Specially fragment shader doesn't compute lighting, shading etc... expensive calculations. On the screen only few fragments with simple flat colors. There is no way only 200 spheres that much lag. I'm just guessing maybe too many OpenGL calls. Copy data to GPU and draw etc... Each OpenGL calls are blocking. Maybe beginMode3D and endMode3D just switching shader programs. Not buffering for batch rendering.

  • @rubyciide5542
    @rubyciide5542 7 місяців тому +18

    TSoding
    Turing Soding ❌
    Terry daviS OverDosING ✅

  • @aaronspeedy7780
    @aaronspeedy7780 7 місяців тому +48

    I've been loving these streams on raylib! Raylib is such a wonderful library. By the way, raylib has an rcamera module which makes a lot of the math you did redundant with one super easy function, namely UpdateCamera, for moving the camera with usual controls under a variety of modes, and a couple of lower-level functions, namely CameraMoveForward, CameraMoveRight, CameraMoveUp, CameraYaw, and CameraPitch, for managing the camera yourself, and some even lower-level functions that I won't name.

  • @bonekazz-8441
    @bonekazz-8441 7 місяців тому +11

    "the source code is the best documentation" this will stick in my mind forever, thanks

  • @EricT43
    @EricT43 7 місяців тому +3

    This was so cool to watch, starting from the algorithm and all the way to applying it to color quantization and image compression. You've inspired me to build some image processing projects of my own.

  • @stephaneduhamel7706
    @stephaneduhamel7706 7 місяців тому +11

    I think using only the unique colors is a good idea for optimisation, but maybe it would make sense to keep track of the number of times each unique color appears in the image, to give more weight to these colors depending on the amount of pixels they correspond to (unless you're already doing that and I missed it).
    (Also default sRGB is a terrible color space to do quantization in, but it doesn't matter too much)

  • @OlivierDALET
    @OlivierDALET 7 місяців тому +5

    It makes very much sense for an api to expose degrees as it allows the user to, most of the time, input exact values: 30, 45 or 90 are nicer to type and read than fractions of pi. It's even more true if you read your values from some config file and feed the api directly.

    • @unnamed1479
      @unnamed1479 7 місяців тому

      degrees also have higher precision than radians which is nice when working with floats

    • @OlivierDALET
      @OlivierDALET 7 місяців тому +1

      @@unnamed1479 sure, however they usually get converted into radians at some point and then you loose precision...

    • @unnamed1479
      @unnamed1479 7 місяців тому

      @@OlivierDALET heh yeah good point

  • @DelgardAlven
    @DelgardAlven 7 місяців тому +1

    Another amazing one stream, Merry Christmas

  • @carvas18
    @carvas18 7 місяців тому +1

    Degrees are usually used because it is a more intuitive unit than multiples of pi, in mathematics you rarely ever see a degree tbh.

  • @SeishukuS12
    @SeishukuS12 7 місяців тому

    That's pretty freaking cool, a simple dither mask pre-applied before quantizing would make an even bigger difference at the low color counts I bet.
    I've always wondered how to do this kind of thing, but never really looked into over the years, it's so stupid simple!

  • @luicecifer
    @luicecifer 6 місяців тому +2

    And that is why programmers and computer scientists get paid so much. Because we're the only ones that are stubborn and stupid enough to put up with that crap every single day.

  • @littlecurrybread
    @littlecurrybread 7 місяців тому +4

    God I love C, keep it up!

    • @shivashankar28
      @shivashankar28 7 місяців тому +2

      same here, C is love, C is life! HAHAH

  • @ecosta
    @ecosta 6 місяців тому

    Also, classical end-of-stream comment: after years trying complex dithering algorithms, I loved how such a simple and elegant solution exists. I'll definitely try that approach if I need it. Or try that visualisation in Vulkan (just because I can 😄).

  • @JonnyDeRico
    @JonnyDeRico 7 місяців тому +5

    In germany we have a "Doppelhaushälfte" 😂

  • @lMoonHawk
    @lMoonHawk 7 місяців тому +2

    Would have been cool to see the image render in real time on screen as the means approach their local minimum

  • @apppples
    @apppples 7 місяців тому +2

    hold all fingers together, index finger pointing towards positive x, curl your fingers into a thumbs up, they curl towards positive y, positive z is the direction of your thumb.

  • @apppples
    @apppples 7 місяців тому +2

    now use CIEDE2000 for the distance metric instead of euclidean distance

  • @____r72
    @____r72 7 місяців тому

    hey look man, i quick and easy mercy evaporation is in both of our best interests, i go poof and escape mad man next door, you continue reclaiming a throne that always belonged to you - its a win win

  • @slavpetrovich32
    @slavpetrovich32 7 місяців тому

    - How much watches?
    - Ten clocks.
    - Such much?
    - For whom how…
    - MFTI finished?
    - A-a-a-ask!..

  • @lievenpetersen
    @lievenpetersen 7 місяців тому +2

    36:28 check out the position name 4 lines below :D

  • @kunalsanjaybutiya5944
    @kunalsanjaybutiya5944 7 місяців тому +18

    Can you please make a series on system programming with C language pls.

    • @Zipperheaddttl
      @Zipperheaddttl 7 місяців тому +2

      look up handmade hero. That will give you what you need.

    • @neshkeev
      @neshkeev 7 місяців тому +17

      He can't do system programming, only computer graphics

    • @michelalwan8410
      @michelalwan8410 7 місяців тому +1

      ​@@neshkeevhow do you know?

    • @SENTRY456123
      @SENTRY456123 7 місяців тому +2

      ​@@neshkeev are you trying to Dani him?

    • @4445hassan
      @4445hassan 7 місяців тому +1

      @@neshkeev Huh? This implemened multiple programming languages and just A LOT of interesting stuff. Just scorll a bit through the videos and you find many many many things that don't have anything to do with any graphical thing what so ever.

  • @RandomGeometryDashStuff
    @RandomGeometryDashStuff 7 місяців тому +1

    28:26 why changing Z sign made camera see cube? isn't that just looking at cube from different direction?

    • @classawarrior
      @classawarrior 5 місяців тому +1

      Was wondering the same thing!

  • @desertfish74
    @desertfish74 7 місяців тому +1

    Zozing need a new PC, on mine , Krita loads up in under 3 seconds.

  • @2dapoint424
    @2dapoint424 7 місяців тому +1

    2:10:22 ! Dumy dum dum!! Ofcourse!!! lol

  • @matthewexline6589
    @matthewexline6589 7 місяців тому +3

    OpenGL isn't utterly insane to learn. Why people don't just write their own OpenGL code themselves and take responsibility for their apps' performance is beyond me.

  • @thatstupiddoll
    @thatstupiddoll 7 місяців тому

    Twice of the half of the cube

  • @anon_y_mousse
    @anon_y_mousse 7 місяців тому +1

    Interesting that they use degrees, because I thought radians were standard. Maybe that's just for the things I've been doing and not graphics programming? I wish I could get you a new computer because your potato is more highly starched than mine. I would just use GIMP to specify an image size, but it might be too much for your computer to handle. Of course I should probably use my image library to do such simple things more like you use STB. And your statement about spending too much time on rotation really hits hard, but not in the way you meant it. Too much time on rotation can really give you PTSD. Although I doubt anyone else watching you will understand what I'm talking about.

  • @sisqobmx
    @sisqobmx 2 місяці тому

    This only works on linux?

  • @RandomGeometryDashStuff
    @RandomGeometryDashStuff 7 місяців тому

    22:23 doesn't which way z goes depend on which way camera is looking?

    • @unnamed1479
      @unnamed1479 7 місяців тому +1

      pretty sure in raylib the x,y,z axes are fixed, but your unit vector for forwards and backwards would be affected by your camera direction

    • @RandomGeometryDashStuff
      @RandomGeometryDashStuff 7 місяців тому

      ​@@unnamed1479> unit vactor for forwards and backwards
      are you talking about `position` or `target` or `up`?

    • @unnamed1479
      @unnamed1479 7 місяців тому +1

      @@RandomGeometryDashStuff (target - position) / mag(target - position)

  • @jjonojj
    @jjonojj 7 місяців тому +1

    great video, but pls expand your german wortschatz

  • @ecosta
    @ecosta 6 місяців тому

    Too bad Raylib uses raw GL vertex primitives behind the scenes. So each sphere/cube pumps one draw call per vertex. 200 spheres isn't much, but it shows how OpenGL sucks unless you use array objects, instances, etc.

  • @abdo01386
    @abdo01386 7 місяців тому

    Why you dont publish your code make it easier

    • @fiona9891
      @fiona9891 4 місяці тому

      the source is usually in the description

  • @blocksrey
    @blocksrey 7 місяців тому

    Is your Emacs evil?

  • @rev_krakken70
    @rev_krakken70 7 місяців тому

    Can you share with me the discord link?

  • @ess4591
    @ess4591 7 місяців тому +2

    it was so easy

  • @slazil
    @slazil 7 місяців тому

    27:30 Здорово! 😃

  • @goseaaesog
    @goseaaesog 7 місяців тому

    HOW CAN I JOIN UR DISCORD?

  • @onaecO
    @onaecO 7 місяців тому

    Bro u so smart!

  • @sdrogo0364
    @sdrogo0364 7 місяців тому

    1:28:33 How about that

  • @switchzzz6285
    @switchzzz6285 7 місяців тому

    SHAYSER

  • @divingeveryday
    @divingeveryday 7 місяців тому +1

    What? No 4D visualizations? Unsubscribe! 😂

  • @paca3107
    @paca3107 7 місяців тому +2

    please show me how to do this in serious language like javascript or react.

    • @SomeRandomPiggo
      @SomeRandomPiggo 7 місяців тому +2

      C isn't serious? XDDDD

    • @paca3107
      @paca3107 7 місяців тому

      @@SomeRandomPiggo is not, in real life people use js.... xDd

    • @SomeRandomPiggo
      @SomeRandomPiggo 7 місяців тому

      @@paca3107 On the web they do, but the browser you use is written in C or C++ and so is the OS below it. JS would be a weird choice for a desktop music player unless you want to use Electron which is really slow

    • @caio757
      @caio757 5 місяців тому +1

      ”0" ==- null
      >>true
      serious language moment.

    • @niggacockball7995
      @niggacockball7995 3 місяці тому

      javascript
      serious
      ha...

  • @Person1873
    @Person1873 7 місяців тому

    First!!!

  • @zizzyballuba4373
    @zizzyballuba4373 7 місяців тому +4

    im indian sir please help im indian

    • @ekshalibur
      @ekshalibur 7 місяців тому +24

      sorry, you cant be helped ... good luck

  • @aeonian8687
    @aeonian8687 7 місяців тому

    how can ı in discord channel ?

    • @JkaBG
      @JkaBG 7 місяців тому +24

      you dropped this .