1. Post #1
    uitham's Avatar
    March 2010
    1,759 Posts


    GLSL Sandbox is an online playground for all of your GLSL fragment shaders.
    You can make one from scratch, or you can go to the gallery and fuck around with other peoples code.
    It automatically compiles after each change.

    Reference made by me: (I had to get the functions from the source code since they are not explained elsewhere)
    Code:
    uniform float time: Ever-incrementing value
    uniform vec2 resolution: The resolution of the window
    uniform vec2 mouse: The x,y of the position of your mouse
    
    radians
    degrees
    sin
    cos
    tan
    asin
    acos
    atan
    pow
    exp
    log
    exp2
    log2
    sqrt
    inversesqrt
    abs
    sign
    floor
    ceil
    fract
    mod
    min
    max
    clamp
    mix
    step
    smoothstep
    length
    distance
    dot
    cross
    normalize
    faceforward
    reflect
    refract
    matrixCompMult
    lessThan
    lessThanEqual
    greaterThan
    greaterThanEqual
    equal
    notEqual
    any
    all
    not
    dFdx
    dFdy
    fwidth
    texture2D
    texture2DProj
    texture2DLod
    texture2DProjLod
    textureCube
    textureCubeLod
    
    To write to the screen:
    gl_FragColor = vec4(r ,g ,b ,1.0);
    Examples:

    Parallax Perlin Noise shader, by me

    http://glsl.heroku.com/e#1000.2


    I will add examples made by facepunchers over time here
    Challenge: recreate the facepunch logo!

    I would appreciate if anyone could create a banner for me since I suck at making them

    Link:
    http://glsl.heroku.com/
    Reply With Quote Edit / Delete Reply Windows 7 Netherlands Show Events Programming King Programming King x 4Winner Winner x 3 (list)

  2. Post #2
    RUBY OVERLORD
    swift and shift's Avatar
    November 2011
    2,117 Posts
    holy fuck that's insane

  3. Post #3
    Gold Member
    Catdaemon's Avatar
    February 2005
    2,818 Posts
    http://glsl.heroku.com/e#951.2

    this one is the best
    Reply With Quote Edit / Delete Reply Windows 7 Show Events Agree Agree x 3 (list)

  4. Post #4
    uitham's Avatar
    March 2010
    1,759 Posts
    Yeah, I like that one too.
    Especially the normal mapping and the shine
    Reply With Quote Edit / Delete Reply Windows 7 Netherlands Show Events Agree Agree x 1 (list)

  5. Post #5
    open.gl
    Overv's Avatar
    February 2007
    7,431 Posts
    Here's how to implement an implicit expression grapher with a fragment shader:

    http://glsl.heroku.com/e#1007.0
    Reply With Quote Edit / Delete Reply Windows 7 Netherlands Show Events Winner Winner x 1 (list)

  6. Post #6
    Gold Member
    Darwin226's Avatar
    January 2009
    3,457 Posts
    Here's how to implement an implicit expression grapher with a fragment shader:

    http://glsl.heroku.com/e#1007.0
    I thought about using the fragment shader for a grapher myself.
    You could even just slap the input formulas in a string along with the rest of the code and recompile when you want to draw a different graph.
    Reply With Quote Edit / Delete Reply Windows 7 Croatia Show Events Agree Agree x 1 (list)

  7. Post #7
    uitham's Avatar
    March 2010
    1,759 Posts
    Could you guys put your facepunch username in a comment in the code of your creations
    I'd like to know who made what

    Also overv your grapher is copied 3 times now, that means it is successful!
    Reply With Quote Edit / Delete Reply Windows 7 Netherlands Show Events Winner Winner x 1 (list)

  8. Post #8
    Gold Member
    kukiric's Avatar
    July 2006
    2,969 Posts
    Ah, the wonders of webGL, is it?
    Reply With Quote Edit / Delete Reply Windows 7 Brazil Show Events Agree Agree x 1 (list)

  9. Post #9
    RUBY OVERLORD
    swift and shift's Avatar
    November 2011
    2,117 Posts
    this runs at about 20% cpu for me.

    compared to garry's snowflakes at 100%
    Reply With Quote Edit / Delete Reply Mac Australia Show Events Funny Funny x 7 (list)

  10. Post #10
    Gold Member
    synthiac's Avatar
    June 2007
    815 Posts
    http://glsl.heroku.com/e#871.0

    draw ur animes w/ glsl
    Reply With Quote Edit / Delete Reply Windows 7 United States Show Events Funny Funny x 6Artistic Artistic x 1Winner Winner x 1Programming King Programming King x 1 (list)

  11. Post #11
    Gold Member
    Chris220's Avatar
    May 2008
    5,322 Posts
    How did I do?
    Make sure you run it at 1x scaling (the dropdown next to "hide code" should be set to '1')
    http://glsl.heroku.com/e#1041.1
    Reply With Quote Edit / Delete Reply Windows 7 United Kingdom Show Events Winner Winner x 7 (list)

  12. Post #12
    Gold Member
    a203xi's Avatar
    January 2005
    283 Posts
    How did I do?
    Make sure you run it at 1x scaling (the dropdown next to "hide code" should be set to '1')
    http://glsl.heroku.com/e#1041.1
    What is it?
    Reply With Quote Edit / Delete Reply Windows 7 Show Events Dumb Dumb x 3 (list)

  13. Post #13
    Gold Member
    Chris220's Avatar
    May 2008
    5,322 Posts
    What is it?
    Forgive me for being very tired and silly but, are you serious?

  14. Post #14
    Gold Member
    Darwin226's Avatar
    January 2009
    3,457 Posts
    I like how, if you want to draw something in a shader, you have to think differently than you're used to.
    Instead of saying paint the circle at 50,50 radius 10 in blue, you have to check if the pixel is inside the circle you want to draw and then color it.
    Reply With Quote Edit / Delete Reply Windows 7 Croatia Show Events Agree Agree x 3 (list)

  15. Post #15
    Gold Member
    Chris220's Avatar
    May 2008
    5,322 Posts
    I like how, if you want to draw something in a shader, you have to think differently than you're used to.
    Instead of saying paint the circle at 50,50 radius 10 in blue, you have to check if the pixel is inside the circle you want to draw and then color it.
    Interestingly, making that facepunch logo taught me how to check for point->triangle and point->OBB intersections! :P

  16. Post #16
    www.bff-hab.de
    DrLuke's Avatar
    February 2009
    7,832 Posts
    Reply With Quote Edit / Delete Reply Windows 7 Germany Show Events Friendly Friendly x 1Winner Winner x 1 (list)

  17. Post #17
    uitham's Avatar
    March 2010
    1,759 Posts
    Thanks, I put it in the OP


    I like how, if you want to draw something in a shader, you have to think differently than you're used to.
    Instead of saying paint the circle at 50,50 radius 10 in blue, you have to check if the pixel is inside the circle you want to draw and then color it.
    So basically drawing stuff without libraries
    Reply With Quote Edit / Delete Reply Windows 7 Netherlands Show Events Disagree Disagree x 1 (list)

  18. Post #18
    Gold Member
    Darwin226's Avatar
    January 2009
    3,457 Posts
    Thanks, I put it in the OP




    So basically drawing stuff without libraries
    No that's not even remotely similar.
    Even if your canvas was a simple 2D array of ints you have the ability to say
    Code:
    for (int i = 0; i < 10; ++i) for (int j = 0; j < 10; ++j) canvas[i][j] = color;
    Which paints a 10 by 10 square in your color. How you put it on screen is unimportant.

    In GLSL you don't have that flexibility.
    It like you are forced to a loop running through every pixel and running a function on it. You only have that function to work with.
    Reply With Quote Edit / Delete Reply Windows 7 Croatia Show Events Agree Agree x 3 (list)

  19. Post #19
    www.bff-hab.de
    DrLuke's Avatar
    February 2009
    7,832 Posts
    http://glsl.heroku.com/e#1068.1

    My first shader ever
    Reply With Quote Edit / Delete Reply Windows 7 Germany Show Events Programming King Programming King x 4 (list)

  20. Post #20
    Andrew McWatters
    acpm's Avatar
    March 2011
    4,045 Posts
    It like you are forced to a loop running through every pixel and running a function on it. You only have that function to work with.
    For this reason alone, I've always thought the shit pulled off in shaders was always infinitely more impressive than plain logic drawing.
    Reply With Quote Edit / Delete Reply Windows 7 United States Show Events Agree Agree x 4 (list)

  21. Post #21
    Gold Member
    Chris220's Avatar
    May 2008
    5,322 Posts
    Why can't I do bitwise operations with this? It's really limiting what I want to do :(

  22. Post #22
    uitham's Avatar
    March 2010
    1,759 Posts
    Why can't I do bitwise operations with this? It's really limiting what I want to do :(
    This guy does the editor
    https://twitter.com/#!/mrdoob

    You can ask him to add it I guess
    Reply With Quote Edit / Delete Reply Windows 7 Netherlands Show Events Friendly Friendly x 1 (list)

  23. Post #23
    Gold Member
    Darwin226's Avatar
    January 2009
    3,457 Posts
    Reply With Quote Edit / Delete Reply Windows 7 Croatia Show Events Agree Agree x 2 (list)

  24. Post #24
    Gold Member
    Chris220's Avatar
    May 2008
    5,322 Posts
    He replied to my tweet:
    Code:
    Mr.doob @   
    @BackwardSpy I don't think WebGL's GLSL support bitwise operations?
    Is there literally no way at all to get at them? :(

  25. Post #25
    Gold Member
    Darwin226's Avatar
    January 2009
    3,457 Posts
    He replied to my tweet:
    Code:
    Mr.doob @   
    @BackwardSpy I don't think WebGL's GLSL support bitwise operations?
    Is there literally no way at all to get at them? :(
    Well shift to left by one is multiplying with 2. Shift by 2 is multiplying with 4...
    For right shifts just divide.

    As for other operations I don't know.
    Reply With Quote Edit / Delete Reply Windows 7 Croatia Show Events Agree Agree x 2 (list)

  26. Post #26
    Andrew McWatters
    acpm's Avatar
    March 2011
    4,045 Posts
    He replied to my tweet:
    Code:
    Mr.doob @   
    @BackwardSpy I don't think WebGL's GLSL support bitwise operations?
    Is there literally no way at all to get at them? :(
    plain arithmetic

  27. Post #27
    open.gl
    Overv's Avatar
    February 2007
    7,431 Posts
    Unfortunately bitwise operators are only supported in GLSL 1.30 and up and OpenGL ES 2.0 GLSL doesn't allow the #version keyword.

  28. Post #28
    Gold Member
    Chris220's Avatar
    May 2008
    5,322 Posts
    Well shift to left by one is multiplying with 2. Shift by 2 is multiplying with 4...
    For right shifts just divide.

    As for other operations I don't know.
    Yeah, I replaced my shifts with multiplication/division, but I needed an XOR as well

  29. Post #29
    sondre99v's Avatar
    January 2011
    71 Posts
    Yeah, I replaced my shifts with multiplication/division, but I needed an XOR as well
    Sounds like you're making a random-function. In that case, this works fine:
    Code:
    float random(vec4 seed)
    {
    	return fract(sin(dot(seed.xy ,vec2(12.9898,78.233)) + dot(seed.zw ,vec2(15.2472,93.2541))) * 43758.5453);
    }
    Just put in gl_FragCoord or something in seed.

  30. Post #30
    Gold Member
    Chris220's Avatar
    May 2008
    5,322 Posts
    Sounds like you're making a random-function. In that case, this works fine:
    Code:
    float random(vec4 seed)
    {
    	return fract(sin(dot(seed.xy ,vec2(12.9898,78.233)) + dot(seed.zw ,vec2(15.2472,93.2541))) * 43758.5453);
    }
    Just put in gl_FragCoord or something in seed.
    Thank you muchly, I'll try that now...

  31. Post #31
    hOnK :o)
    i300's Avatar
    December 2009
    3,985 Posts
    Reply With Quote Edit / Delete Reply Windows 7 United States Show Events Artistic Artistic x 2 (list)

  32. Post #32
    Gold Member
    ZenX2's Avatar
    February 2009
    3,901 Posts
    Hah, there was something on there that my computer couldn't handle and I think explorer.exe crashed for a bit

  33. Post #33
    Bluefire's Avatar
    August 2007
    302 Posts
    http://glsl.heroku.com/e#1148.0

    Meanwhile on the GLSL sandbox, someone who had time to spare
    Reply With Quote Edit / Delete Reply Windows 7 Canada Show Events Funny Funny x 8Winner Winner x 1Optimistic Optimistic x 1 (list)

  34. Post #34
    uitham's Avatar
    March 2010
    1,759 Posts
    http://glsl.heroku.com/e#1249.6
    Combining random shaders and doing weird stuff with them yeah
    Reply With Quote Edit / Delete Reply Windows 7 Netherlands Show Events Artistic Artistic x 1Friendly Friendly x 1 (list)

  35. Post #35
    open.gl
    Overv's Avatar
    February 2007
    7,431 Posts
    http://glsl.heroku.com/e#1249.6
    Combining random shaders and doing weird stuff with them yeah
    Ladies and gentlemen, this here is what modern art should be all about.
    Reply With Quote Edit / Delete Reply Windows 7 Netherlands Show Events Friendly Friendly x 2Agree Agree x 1 (list)

  36. Post #36
    Gold Member
    ZenX2's Avatar
    February 2009
    3,901 Posts
    Okay, all these WebGL things just crash my graphics card
    As in my screen turns off for a while :C
    Reply With Quote Edit / Delete Reply Windows 7 United States Show Events Funny Funny x 2 (list)

  37. Post #37
    Gold Member
    Deco Da Man's Avatar
    July 2007
    1,005 Posts
    Okay, all these WebGL things just crash my graphics card
    As in my screen turns off for a while :C
    NVIDIA, AMD, Intel.
    Reply With Quote Edit / Delete Reply Windows 7 Australia Show Events Friendly Friendly x 3 (list)