Shader Coding: Truchet Tiling Explained!

Поделиться
HTML-код
  • Опубликовано: 11 окт 2024

Комментарии • 198

  • @badjano
    @badjano 5 лет назад +56

    Best shader dev youtube channel ever! :D

  • @TheSwaroopB
    @TheSwaroopB 5 лет назад +6

    Despite working in the computer graphics industry for more than a few years, I could never motivate myself enough to write my own shaders on shadertoy! I would always look at others and only admire the work (or tweak a little bit). This is the first time I feel I should actually do something. You explained SO MANY tiny things merely in half an hour. You're a legend, sir! Thank you! Definitely need more of this...
    Btw, with those little achievements during the video, I'd have jumped on my chair and ran across the neighborhood yelling what I just did. You, on the other hand, were like "that's cool 😐"; found that a bit funny!

  • @superscatboy
    @superscatboy 5 лет назад +15

    This video just popped up on my recommendations and I'm seriously impressed - you get straight down to business and explain everything as you go. Love it, dude.

  • @sendark001
    @sendark001 5 лет назад +7

    somewhere between Bob ross and Deadmau5 - jokes aside, best glsl teacher i've found.

  • @monocore
    @monocore Год назад

    Your videos are so good. I mainly do things in VEX but stuff like this in similar languages are awesome to watch.

  • @shiinondogewalker2809
    @shiinondogewalker2809 5 лет назад +59

    I think there's a way to flip y for the uv coordinates without knowing neighbours.
    I'll express it by 2 bool values
    a = checker pattern, true for every other tile
    b = hash pattern, true for every tile that you flipped the orientation of
    then flip the uv y coordinate if a xor b

    • @SellusionStar
      @SellusionStar 5 лет назад +2

      That might work! Good idea

    • @TheArtofCodeIsCool
      @TheArtofCodeIsCool  5 лет назад +14

      Turns out you are right. :)

    • @DOOMDUDEMX
      @DOOMDUDEMX 5 лет назад +1

      I was thinking just the same thing!
      Turns out that i wasn't alone! :)

    • @Woodledude
      @Woodledude 5 лет назад +1

      A lot of this is way over my head, and I thought that was a really obvious solution XD You get a like, fellow interwebber

    • @yonjuunininjin
      @yonjuunininjin 5 лет назад

      Also don't forget to swap out smoothstep with a simple ceil and 1 - result. Basically: 1 - ceil((abs(d - 0.5) - width))).

  • @leifm.6759
    @leifm.6759 5 лет назад +28

    36:31 "More like 1700!!". According to Wolfram Alpha this is roughly 3.9365477946605944047872263433231095841463037044815290173387739901217075103664754606769104726079377942607302 × 10^2378.

  • @AlexGomes09
    @AlexGomes09 2 года назад

    I am going to call you "SHADER MASTER" impressed!!

  • @directrix1
    @directrix1 5 лет назад

    Dude, I love your videos. You don't explain the backing math in overly tangential ways. It's just right to the point. Awesome as always.

  • @Goloso333
    @Goloso333 2 года назад

    Oh! man. You are a genius. Amazing stuff. I use illustrator and was wondering about this patter, but you actually program it and make it full of motion... wow!... I am so impressed by this stuff. Thank you.

  • @azagwen
    @azagwen 5 лет назад +2

    That's so amazing to see what you can do with simple maths !
    I managed to reproduce this shader in Blender using the node based material editor, aside from important glitches on 3D objects it looks the exact same on planes and UV unwrapped objects !

    • @TheArtofCodeIsCool
      @TheArtofCodeIsCool  5 лет назад +4

      Cool! I have to dive into blender 2.8 some day. A lot of people are doing cool stuff with it.

    • @azagwen
      @azagwen 5 лет назад +2

      @@TheArtofCodeIsCool I'm sure you'll like it !
      I heard the shader nodes are based off of GLSL, it shouldn't be too hard for you to do crazy stuff with them too !
      I'm also trying to reproduce tiled Hexagons watching the video you made about them, but I am struggling to translate the two last steps into nodes as I don't know how to translate a "if".

  • @dj_e8
    @dj_e8 4 года назад +1

    Thanks! This effect I've seen on one particular dnb music channel. Always wondered how to actually do it. Tried to do it in Touchdesigner with its components, but I now realize the importance of resource control especially in larger projects. That's where shaders come into the picture. Kudos Martijn!

  • @yavalang
    @yavalang 3 года назад

    I'm so happy finding this channel. There are so many tips and tricks hidden in this tutorial.Thanks a lot.

  • @adamnejm
    @adamnejm 5 лет назад +1

    This is the first time I look into shader coding, seems super fun!

  • @alialavib
    @alialavib 5 лет назад +1

    I just discovered your channel! It's so underrated. It's a wonder that I haven't heard of it prior to this. Keep up the good work and please upload more frequently.

  • @EdBoucher
    @EdBoucher 5 лет назад

    This is fantastic! I've only really used shaders for rendering things with vertices but I love that you can do so much just with a fragment shader- and this is the most wonderful explanation of how that I've ever come across.
    Many, many props. Write a book already! I'll buy it!

  • @GglSux
    @GglSux 5 лет назад +1

    Thanks a million for taking the effort of making these great videos.
    It's channels like this that makes RUclips worth while !!
    Best regards.

  • @clairearan505
    @clairearan505 2 года назад +1

    Every time I watch your videos I see a new optical illusion.

  • @bosmervor
    @bosmervor 5 лет назад +1

    So glad to find this channel, always wanted to learn shaders!

  • @herp_derpingson
    @herp_derpingson 5 лет назад +2

    This is good, there are very few people knowledgeable in graphic shaders.

  • @jackninja1
    @jackninja1 5 лет назад +1

    Stumbled upon this video and I am totally amazed! I love this type of content. Keep up the good work!

  • @kallamamran
    @kallamamran 5 лет назад +1

    There are soooooo many things I'd love to have as a screensaver here!

  • @100drips
    @100drips 5 лет назад +1

    I love this channel! Impressive that it seems like you do this all spontaneous and in one take too!

  • @4.0.4
    @4.0.4 5 лет назад +1

    You went to the Amazon? Nice! Cheers from Brazil and thank you for squeezing this video into your schedule :)

  • @idontevenknow3707
    @idontevenknow3707 3 года назад

    Thank you so much for this, things are slowly but surely clicking!

  • @NBsTube
    @NBsTube 5 лет назад

    the long wait is over, another shader tutorial from Martijn, I hope this channel keeps growing and you get the attention these videos deserve!

  • @bejoscha
    @bejoscha 5 лет назад

    I think I've just randomly stumbled into a new "favorite channel" for me. Subscribed.

  • @DylanBurke
    @DylanBurke 5 лет назад

    If I haven't said it already, I love your videos. I would like to say thank you very much for fixing the mic issue; SO SO exciting to be able to follow your videos without the thumping. :D
    Also, thank you so much for explaining the randomness function you use a lot. I'd been wondering about it, but very satisfying to now know it doesn't necessarily rely on any specific mathematical trick, it's just a serious of math operations to create more digits, slice a few off, make more digits, slice, etc.
    Will definitely support when I can. Thank you!!!

    • @DylanBurke
      @DylanBurke 5 лет назад

      Also, just a suggestion. Would be really cool to get small shader challenges from you. Not sure exactly what your goals are with the channel or Patreon, but something I struggle with when it comes to shaders is coming up with ideas that are actually within my grasp or that don't grow too much while I'm writing it. Would be nice to have someone experienced, like yourself, help guide my shader studies with challenges without spreading you too thin.
      Anyway, thank you yet again!

    • @DylanBurke
      @DylanBurke 5 лет назад

      Erm, just realized that your Patreon is $1 per video at the lowest tier. I can definitely afford that...... and done!

    • @TheArtofCodeIsCool
      @TheArtofCodeIsCool  5 лет назад

      @@DylanBurke I gotta think about how I would do this exactly but that sounds like a great idea!

  • @jemsophia
    @jemsophia 4 года назад

    this (and all of your videos) was soooo good - thank you.

  • @TheNewton
    @TheNewton 5 лет назад

    Thanks, Subscribed! Great explanation and step through style, so many programming videos make assumptions and completely gloss over fundamental blocks here you even take a moment to clarify absolute(5:15) and I'd never considered applying that for reflected gradients.

  • @anmaral-sharif1381
    @anmaral-sharif1381 5 лет назад +5

    Thank you bro, as usual "QUALITY CONTENT"

  • @ivankramarenko
    @ivankramarenko 5 лет назад +5

    Спасибо за ваш труд

  • @СергейФёдоров-щ8ш
    @СергейФёдоров-щ8ш 5 лет назад

    Nice explain, with visual samples per change, and detailed description! Thank You, please continue in the same vein )

  • @bleeptrack
    @bleeptrack 5 лет назад +1

    11:07 beautiful 10 PRINT 😍
    Great video, as always! Thanks a lot!

  • @Ikogn
    @Ikogn 5 лет назад +6

    19:28 In order not to have those white lines and not to add the epsilon what you could do is something like :
    mix(-0.5, 0.5, step(0., gv.x+gv.y));

  • @Tony-vl1tv
    @Tony-vl1tv 5 лет назад

    I waited a long time for the shadertoy content. Thanks

  • @PhilippeGauthier
    @PhilippeGauthier 5 лет назад +2

    Amazing content and pedagogy, as usual ! Thanks !

  • @CCV334
    @CCV334 5 лет назад +2

    I'd love to see a tutorial on metaballs, possibly taking what we've been learning from the Voronoi tutorial!

  • @nofacee94
    @nofacee94 5 лет назад +2

    phenomenal. thank you.

  • @neur303
    @neur303 5 лет назад +1

    Very cool and succinct, while still everything explained well! Thank you so much! I'll have fun with it soon! Also I subscribed ❤️

  • @sacredbanana
    @sacredbanana 5 лет назад +1

    Wooooooooooooooooooooooooo. Sorry I just had to comment before actually watching the video. We are long overdue for a catchup dude. I've been swamped by illnesses, work and former clients from my freelancer days. Keen for another session soon?

  • @FOSS365
    @FOSS365 5 лет назад

    You explain shaders so well. Thank you for your videos!

  • @JustYesntMan
    @JustYesntMan 5 лет назад +1

    Yes ! finally ! a new video

  • @lifetheoryoptimal3297
    @lifetheoryoptimal3297 5 лет назад +1

    I watched your mandlebrot video too. This is like Bob Ross 2.0

  • @user-kw9cu
    @user-kw9cu 5 лет назад +2

    Спасибо за видео. Интересный эффект

  • @AliAkbarDev
    @AliAkbarDev 5 лет назад

    Love your videos

  • @meerminman
    @meerminman 5 лет назад

    Quality content as always

  • @Napriiihm
    @Napriiihm Год назад

    Incredible thank's !

  • @SellusionStar
    @SellusionStar 5 лет назад +3

    That is fun

  • @krejcivaclav
    @krejcivaclav 5 лет назад

    Great as always!

  • @pendergastj
    @pendergastj 5 лет назад

    Awesome work! I love your channel!

  • @realcygnus
    @realcygnus 5 лет назад

    Nice man ! ......Priceless Content imo....as usual

  • @DopeShaders
    @DopeShaders 5 лет назад

    Thank for great guides!

  • @HarhaMedia
    @HarhaMedia 5 лет назад

    Lovely video!

  • @trinosan
    @trinosan 5 лет назад

    Awesome as always 👌

  • @CCV334
    @CCV334 5 лет назад +1

    Wooooo thanks for the tutorial!

  • @sergejivanoff2789
    @sergejivanoff2789 5 лет назад

    Great work! Thank you for sharing!

  • @ReinkeDK
    @ReinkeDK 5 лет назад

    As always a very good video!

  • @StefanReich
    @StefanReich 5 лет назад

    Your "shift to the side" (13:51) where you have 2 lines inside each square is quite a surprise. Doesn't that change the maze algorithm by introducing all these parallel lines? Or does it not? Amazing. There should be a mathematical proof about this (whichever it is).

    • @TheArtofCodeIsCool
      @TheArtofCodeIsCool  5 лет назад

      When I made the original one, with just the diagonal line, I didn't like the notches and played a bit to get rid of them. I haven't really thought about wether it actually changes the maze.

  • @askhento
    @askhento 5 лет назад

    Wow it looks like you do it live!

  • @geoffpedder
    @geoffpedder 5 лет назад

    Great video, thanks

  • @rendermanpro
    @rendermanpro 4 года назад

    Nice!

  • @rochbouchayer9120
    @rochbouchayer9120 5 лет назад +3

    19:45 you could use a step function on zero, multiply by 2 and substract by 1 and you get negative and positive value.
    From: `sign(gv.x + gv.y)`
    to: `2.0 * step(0.0, gv.x + gv.y) - 1.0`.
    I'm not sure this is nicer fix because it's involve more computation and maybe harder to read than `sign` function.

    • @TheArtofCodeIsCool
      @TheArtofCodeIsCool  5 лет назад

      Yeah that works too :)

    • @cameronfoale8270
      @cameronfoale8270 5 лет назад

      How about float((gv.x + gv.y) > 0.0) * 2.0 - 1.0; ?

    • @rochbouchayer9120
      @rochbouchayer9120 5 лет назад

      @@cameronfoale8270 Condition is not really optimize in shaders cause your shader need to recompile if the condition change. It's kind of a micro optimization however I personally prefer to avoid condition when I can.
      But the point is, yes it works. ^^

    • @bradennelson2436
      @bradennelson2436 5 лет назад

      @@rochbouchayer9120 Shaders do not need recompiled for conditionals. The actual issue is that shaders operate on many values at once (I.e. AMD's recent Navi cards operate on groups of 32 values), and conditional code on a vector can be very expensive.

    • @rochbouchayer9120
      @rochbouchayer9120 5 лет назад

      @@bradennelson2436 Sorry for the mistake, I'm not an expert in shader at "hardware" level. A friend tried to explain to me GPU branching but I didn't understand all the subtleties. Thanks for the correction.

  • @noosetime9423
    @noosetime9423 5 лет назад

    to remove the lines without adding random numbers in this case you could multiply color youre adding by the abs of sign. This would make it black in cases of 0 and do nothing for everything else. you could also replace one abs (somewhere) with the multiplication by the sign value (this would effectively just be abs, and 0 for when it's not needed anyway)

    float s = sign(gv.x+gv.y);
    line 48: col += texture(iChannel0, tUv).rgb*mask * abs(s);
    ^ this would work

  • @frankeke8541
    @frankeke8541 5 лет назад

    my man is baack

  • @ReverseDFatE
    @ReverseDFatE 5 лет назад

    Quality content, very interesting.

  • @may007ank
    @may007ank 4 года назад

    A possible better solution for that offset thing:
    You can wrap the y coordinate of the sign function into a max function like;
    sign(gv.x, max(gv.y, 0.001));

  • @whythosenames
    @whythosenames 5 лет назад

    30:18 you can know about the other tiles if you do for example Hash21(id-vec2(1,0)), this would be the tile above

    • @TheArtofCodeIsCool
      @TheArtofCodeIsCool  5 лет назад

      Yeah but that's just the neighbor. In order to get consistency each tile would have to follow the entire path and come to a consensus with all other tiles sharing the same path on how to flip its coordinate ;)

  • @GWConspiracy
    @GWConspiracy 5 лет назад

    This was awesome!

  • @MrSmotrelkin
    @MrSmotrelkin 5 лет назад

    Very neat

  • @im-pk
    @im-pk 5 лет назад

    This is awesome.

  • @jackhurley3626
    @jackhurley3626 5 лет назад

    You are a godsend sir, thank you!

  • @WindBendsSteel
    @WindBendsSteel Год назад

    Is there a way to smooth out the result? Producing more straight lines where adjacent tiles are not flipped, and curve only where it's necessary.

  • @henrmota
    @henrmota 4 года назад

    This should be the way math should be reached in a computer science course.

  • @neoxblackgold
    @neoxblackgold 5 лет назад +2

    for the flow, instead of checker, I think you can use just the n variable (hash21) and substract 0.5 which will give you a value between -0.5 and +0.5, and only check wheather it's positive or negative without its magnitude, which would force all the boxes to spin in one direction (in this cas it's counterclockwise)
    this should work because only flipped boxed are spinning in the wrong direction, which are controlled by the n variable

    • @shiinondogewalker2809
      @shiinondogewalker2809 5 лет назад +1

      flipped or not makes no difference on their spin direction, look again!

  • @pqnet84
    @pqnet84 5 лет назад

    19:40 you can use 0.5 - step(0, gv.x+gv.y) instead of -sign(...)*0.5

  • @CapnSlipp
    @CapnSlipp 5 лет назад

    30:44 _“Unfortunately, there's no easy way to remedy that and make it completely uniform, because you would have to know… one tile would have to know how all the other tiles are oriented in order to know which way to flip, and so that's not feasible.”_
    But you _do_ know which way a tile's flipped- that's your hashed `n` variable (or rather, the `n

    • @TheArtofCodeIsCool
      @TheArtofCodeIsCool  5 лет назад

      You are right. It IS possible. I stand corrected :)
      www.shadertoy.com/view/td33D4

  • @DanielXDotNet
    @DanielXDotNet 2 года назад

    I like this

  • @boggo3848
    @boggo3848 5 лет назад

    I really wish Shadertoy made shaders more easily embeddable outside the site, for example if they could just run as embeds on twitter.

    • @TheArtofCodeIsCool
      @TheArtofCodeIsCool  5 лет назад

      I think you can embed shaders, dunno about twitter though. If not, you could post it on the facebook group and perhaps it'll be picked up. Twitter integration would be awesome.

  • @dropblue9962
    @dropblue9962 5 лет назад

    I really enjoy your video😍

  • @thepixelatedcactus7152
    @thepixelatedcactus7152 5 лет назад +1

    13:57 Towards the right of the render, you can see a spooked ghost.

  • @icaroamorim3123
    @icaroamorim3123 5 лет назад

    Good job keep it up.

  • @易水-w8s
    @易水-w8s 5 лет назад

    allways good~

  • @pantov
    @pantov 5 лет назад

    please do a tutorial about importing geometry from other programs into glsl!!

  • @AV-br3bm
    @AV-br3bm 4 года назад

    Math is like real world magic : )

  • @SimonK91
    @SimonK91 5 лет назад

    There's a minor problem with your solution at 19:33: You only shift the "bug" to another location. Using some hyperparameters you'll be able to get gv.x+gv.y = -0.001, adding 0.001 to this would give you the value 0.
    I think you could fix the problem by multiplying d by sign(abs(gv.x+gv.y)), which basically zeroes d if you're on the diagonal.

    • @TheArtofCodeIsCool
      @TheArtofCodeIsCool  5 лет назад

      Yeah you are right. I was trying to find a solution without a conditional but the sign function is conditional anyways. So in this case a simple (gv.x+gv.y>0)?1:-1 would have sufficed.

    • @SimonK91
      @SimonK91 5 лет назад

      @@TheArtofCodeIsCool I think (gv.x+gv.y>0)?1:-1 would've been worse (for the reason you mentioned -- avoiding conditionals). The GPU should have logic to handle _sign(abs(xx))_ better than _cond?true:false_
      I also don't think my suggestion would be usable for most implementations, adding a minor shift to avoid zero behaves as expected in most of the cases, with no overhead.
      Great video all in all.

  • @gaborfekete3777
    @gaborfekete3777 5 лет назад +1

    Instead of the sign function I would use something like this:
    #define stepsign(x) (step(0.,(x))*2.-1.)
    It shifts the step function result from [0,1] to [-1,1] range.

  • @paxdriver
    @paxdriver 5 лет назад

    Thumbs up! Subbed

  • @erslippers3805
    @erslippers3805 5 лет назад +1

    I think you could fix the y continuity by flipping it if it is around the bottom corner.

    • @TheArtofCodeIsCool
      @TheArtofCodeIsCool  5 лет назад +1

      You could try doing it and post the link if you succeed. I'd be very interested in this.

    • @erslippers3805
      @erslippers3805 5 лет назад +1

      @@TheArtofCodeIsCool I tried doing it. I don't think that anymore.

    • @milestincknell8889
      @milestincknell8889 4 года назад

      @@erslippers3805 this tickled me. Hats off for trying!

  • @tonyalexander22
    @tonyalexander22 5 лет назад

    awsome

  • @ConstantDupuis
    @ConstantDupuis 5 лет назад

    Yeah ! Great tank's

  • @MdImrulHassan
    @MdImrulHassan 3 года назад

    I have a very pedantic question. How did you come up with the names uv and gv? Is it a shorthand for "uniform vector" and "grid vector"?

    • @TheArtofCodeIsCool
      @TheArtofCodeIsCool  3 года назад +1

      The concept 'uv coordinate' is widely used in computer graphics and probably comes from mathematics which generally uses letters at the end of the alphabet for varying variables (as opposed to letters at the start of the alphabet for constants). Common letters used are x,y, z,w, s, t, u and v.
      I just came up with 'gv' to stand for 'grid uv'. But I like your guess!

  • @20270813978095210
    @20270813978095210 5 лет назад

    nice vid, clearly explained.
    do you use a blue screen? your eyes looks freaky sometimes : p

  • @icaroamorim3123
    @icaroamorim3123 5 лет назад +5

    Do some cloud shaders or Water maybe...

  • @FalkBay
    @FalkBay 5 лет назад

    At 30:41 could you use the checker board information and the Hash21 output to decide if you flip the texture?

    • @TheArtofCodeIsCool
      @TheArtofCodeIsCool  5 лет назад +1

      Yes, there is a solution o this.Check the tea-time segment on my latest video (KIFS fractals).

  • @TheSwissGuy1
    @TheSwissGuy1 5 лет назад

    I think an easy way to fix the discontinuity at 30:35 would be to multiply y by checker and sign(n-.5) like: y=(d-(.5-width))/(2.*width)*checker*sign(n-.5)
    Or am I missing something there?

    • @TheArtofCodeIsCool
      @TheArtofCodeIsCool  5 лет назад

      You are right. It IS possible. www.shadertoy.com/view/td33D4

  • @WeirdSide
    @WeirdSide 5 лет назад

    what language is this?

  • @TheNewton
    @TheNewton 5 лет назад

    There's a good video here on youtube showing artistic uses of Truchet tiling for hidden messages by David Reimann's method.
    *Play Truchet: Using the Truchet Tiling to Engage the Public with Mathematics - Cindy Lawrence
    *

    • @TheArtofCodeIsCool
      @TheArtofCodeIsCool  5 лет назад

      Very cool. Thanks for the tip. Perhaps I'll play with that some time.

  • @matka5130
    @matka5130 5 лет назад

    Epic! Insta-subed :)

  • @pendergastj
    @pendergastj 5 лет назад +3

    5:25 an optical illusion.