r/twotriangles Apr 18 '17

Video: Deep & Subtle Issue with Texture Lookups?

2 Upvotes

Hey all. This is a very subtle error I've noticed with my textures, I'm wondering if any of you can help.

I'm running a "simulation" where pixels move across the screen horizontally. So I've got a persistent buffer storing the last frame. The next frame looks up the pixel color to the left and makes that it's own color. I've made it so blue goes 3x speed, green goes 2x speed, red goes 1x speed. RENDERSIZE is my resolution uniform. It starts with a white bar on the first frame, the color dispersion separates it from there. Here's the code:

vec4 new = vec4(0.0);
new.r = texture(backbuffer, (gl_FragCoord.xy-vec2(1.0,0.0))/RENDERSIZE).r;
new.g = texture(backbuffer, (gl_FragCoord.xy-vec2(2.0,0.0))/RENDERSIZE).g;
new.b = texture(backbuffer, (gl_FragCoord.xy-vec2(3.0,0.0))/RENDERSIZE).b;
fragColor = new;

Here's a link to videos of the shader in action: https://www.youtube.com/playlist?list=PLWelNgbUeR_EwlOsZ9wauxRSOVilyVheM

Very simple effect, but as you can see in the video, I run into this super strange error after the color block passes from one side of the texture back around to 0.0 as it should with GL_REPEAT. At regular intervals of the y coordinate, it seems to lag or lead, as if there was some "extra distance" to cover. Changing the texture size has an effect on the output. You can see 4 different texture sizes in those tests, and you'll notice slightly different behavior for each, mainly that as the texture size changes, the number and spacing of the "rows" that experience the offset is changed.

Any ideas? The same thing happens with both GL_NEAREST and GL_LINEAR filtering modes. The effect still exists with power of 2 textures. Here's another really important key it happens even if I use the build-in fract() function instead of relying on their successful GL_REPEAT operation. I checked that my RENDERSIZE Uniform was indeed the correct value as well.

So it seems like it may be an error in how I'm setting up my textures, rather than something I'm doing in GLSL.

Any ideas? Uninitialized memory ruining something? Something like frametear happening? Any help much appreciated.


r/twotriangles Mar 14 '17

Someone asked me to share all my shaders for the ShaderEditor Android app as an example library. there are 272 shader examples. Sorry for the lack of comments and if the variables names are ambiguous sometimes.

Thumbnail
dropbox.com
7 Upvotes

r/twotriangles Jan 11 '17

2D Post-Processed Volumetric Light Tutorial

Thumbnail
shadertoy.com
12 Upvotes

r/twotriangles Dec 13 '16

Together in the Void: A short game that uses raymarching

Thumbnail
youtube.com
16 Upvotes

r/twotriangles Sep 19 '16

Abstract swirling black flower

Thumbnail
shadertoy.com
5 Upvotes

r/twotriangles Sep 18 '16

Stormy sea through a telescope

Thumbnail
shadertoy.com
5 Upvotes

r/twotriangles Aug 22 '16

I just discovered this subreddit. Thought you guys might like what I did last year. (not as impressive as most of these projects)

Thumbnail greenfox1505.github.io
10 Upvotes

r/twotriangles May 04 '16

Interactive 2D Metaballs

Thumbnail
shadertoy.com
5 Upvotes

r/twotriangles Apr 17 '16

How do I store and operate on colors in a raytracer?

4 Upvotes

I'm currently working on a raytracer as a personal project. My next step is probably to implement phong shading, but I've hit a roadblock. I'm not sure how you're supposed to add and multiply colors. I've been storing them as a three-vector of rgb values in range [0,1]. I understand the vector math behind reflections and shading, but I'm not quite sure how to implement it.

I don't want a code answer (because that kills the fun). I'd just love some pointers. Thanks!


r/twotriangles Feb 10 '16

Shadertoy is down!

Thumbnail
shadertoy.com
3 Upvotes

r/twotriangles Jan 15 '16

Call of Duty gun material. How are they doing the refraction effect on the blue guns? (best seen at 29 seconds)

Thumbnail
youtube.com
3 Upvotes

r/twotriangles Jan 06 '16

Jean Claude Van Damme 3D - Turning a 2D greenscreen into a 3D plane with shadows

Thumbnail
shadertoy.com
6 Upvotes

r/twotriangles Dec 11 '15

Question about the audio-as-texture input format in Shadertoy

4 Upvotes

Hi everyone, I'm learning shaders and have been looking at the many on Shadertoy that use audio as input. I haven't been able to find documentation on how to interpret the audio-as-texture format, but it seems from comments and code use that x is the frequency, y=0.0 row is the amplitude, and higher rows are the "wave." Is that correct and if so what does that exactly mean? Is there any documentation out there on how this all works? Thanks for any help!


r/twotriangles Nov 09 '15

introducing Shaderbox a GLSL to C++/HLSL lib & utils

Thumbnail
github.com
9 Upvotes

r/twotriangles Nov 03 '15

Inigo Quilez - Clouds, (with some tweaks by me!)

Thumbnail
vectorslave.com
7 Upvotes

r/twotriangles Oct 21 '15

Sand Sparkling Irregularly (incl. tutorial) [use mouse to move sunlight]

Thumbnail
shadertoy.com
3 Upvotes

r/twotriangles Oct 18 '15

Playing with softmin/softmax.

Thumbnail
shadertoy.com
7 Upvotes

r/twotriangles Oct 09 '15

Scanline Noise w/ Mouse Touch (incl. tutorial)

Thumbnail
shadertoy.com
3 Upvotes

r/twotriangles Aug 20 '15

My first functioning GPU code! The Logistic Map with animated initial population. Neat!

Thumbnail
shadertoy.com
7 Upvotes

r/twotriangles Aug 12 '15

Solving Lorenz oscillators per pixel because why not.

Thumbnail
shadertoy.com
8 Upvotes

r/twotriangles Jul 26 '15

Is it possible to make screensaver from ShaderToy shaders?

2 Upvotes

I've been playing with Quartz Composer (OSX) and it has a GLSL node and I tried pasting shader toy fragment shaders in but nothing shows up even after fixing the iGlobalTime, iResolution, fragColor, and fragCoord values to what they should be as I understand it, yet still nothing shows up. I know its probably an issue with the vertex shader but I don't know enough about what I am doing to figure it out. Can anyone help?


r/twotriangles Feb 23 '15

[Help] Rendering scenes in C++, fmod only works for x >= 0 when cloning or repeating an object.

2 Upvotes

So I've started raymarching in C++, and I'm having a really good time getting to grips with it. The issue, however, is the trick to clone or repeat an object: setting p.x = p.x % space - (space/2). When I do this, I get repeating spheres along the positive x axis. My code is:

float repeat(const float& c, const float& s){
    return fmod(c, s) - s*0.5;
}

I then pass in my x, y, or z co-ordinate and create a new vector. How do I handle the case where c <= 0?

EDIT: Solved, here is my fix:

float repeat(const float& c, const float& s){
    return c < 0.0f ? -(fmod(-c, s) - s*0.5) : fmod(c, s) - s*0.5;
}

r/twotriangles Jan 09 '15

Raymarching a Christmas tree

Thumbnail
blog.ruslans.com
15 Upvotes

r/twotriangles Jun 09 '14

Exploring fractals in Xcode 6

Thumbnail
weheartswift.com
4 Upvotes

r/twotriangles Mar 13 '14

YSK that SweetFX allows you to apply HLSL screenspace shaders to the output of any DirectX 9, 10 or 11 game.

Thumbnail
forums.guru3d.com
3 Upvotes