Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Odd shader glitch-shader rendering no pixels

edited October 2014 in Shaders Posts: 342

This is the fragment shader, it uses a default vertex shader. Use the camera as the texture, it's quite odd. It switches parts of the image to negative, the rest is normal

precision highp float;
uniform lowp sampler2D texture;
varying lowp vec4 vColor;
varying highp vec2 vTexCoord;
void main()
{
    lowp vec4 col = texture2D( texture, vTexCoord ) * vColor;
    lowp vec3 collor;
    lowp vec3 joeeb;
    gl_FragColor = vec4( col.rgb * col.rgb * collor * joeeb / + - joeeb + collor/joeeb* col.rgb,col.a);
}

EDIT: to save forum space, I posted a shader question below

Comments

  • IgnatzIgnatz Mod
    Posts: 5,396

    @Monkeyman32123 - you define variables collor and joeeb, but you don't give them any values before using them in a formula. That's probably why you get strange results.

    If you want to insert values for them from Codea, then you need to define them before the main function like this (and assign them values in your Codea code)

    uniform float collor;
    uniform float joeeb;
    
  • edited October 2014 Posts: 342

    Oh, I'm sorry, I think my intentions were misunderstood. I was trying to make a different effect but this is what came out; I know why, I just liked the effect :) but thank you very much for the help! (The effect I was trying to make is that fun glitchy thing that happens when you wiggle an NES cartridge or, as a better [more modern] example: the faux glitchiness at the beginning of the game FEZ by the immaculate Phil Phish).

    As a side note, however, this fragment shader I made does not work (at all) and yet all it does is some computation then leave the pixel unchanged.

        precision highp float;
        uniform highp sampler2D texture;
        uniform highp sampler2D depthmap;
        uniform highp vec2 strips_info;
        uniform highp float depth_factor;
        varying lowp vec4 vColor;
        varying highp vec2 vTexCoord;
    void main() {
        highp vec2 uv = vTexCoord.xy;
        uv.x = (vTexCoord.x/strips_info.y - 1.0) * strips_info.x;
        highp vec4 tex = texture2D(depthmap,uv);
        if (depth_factor < 0.0) {
        tex.x = 1.0 - tex.x;
        }
        highp float displace = tex.x * abs(depth_factor) * strips_info.y;
        uv.x = vTexCoord.x - strips_info.y + displace;
        highp vec4 col = texture2D(texture, vTexCoord);
        gl_FragColor = col;
    }
    
  • IgnatzIgnatz Mod
    Posts: 5,396

    What I do in a case like that is comment lines out until it works, which tells me where the problem is

  • I commented lines out until all that was left was:

        precision highp float;
        uniform highp sampler2D texture;
        varying lowp vec4 vColor;
        varying highp vec2 vTexCoord;
    void main() {
        highp vec4 col = texture2D(texture, vTexCoord);
        gl_FragColor = col;
    }
    

    And it still wouldn't update in the lab (perhaps a shader lab glitch). But really I don't see the issue with any of the other lines as they didn't affect the ones above, and there were no other state settings of gl_FragColor. It just seemed to not like the code, I guess. The code is supposed to be a porting of a stereoscopic 3D image generator from a different shading language, but the port didn't work, then I found that even the normal parts didn't work.

  • IgnatzIgnatz Mod
    Posts: 5,396

    That code looks ok, but it is possible there is a hidden unprintable character that came along for the ride. To check this, copy the code into a plain text editor, and then copy it back out and paste back into Codea.

    Alternately, I would do it the other way round and start with the standard fragment shader code, and add lines from your image generator, just a couple at a time

  • Nope, no hidden characters, unfortunately. Just a stubborn refusal to cooperate

  • IgnatzIgnatz Mod
    Posts: 5,396

    There is something wrong somewhere, and I'll bet it's not a bug in Codea.

    Are you absolutely sure the vertex shader is standard? Have you looked at the inputs on the Bindings tab to make sure they are valid?

  • I've left the bindings as "Cargo Bot: Codea Icon". I erased everything in the white space and redid the tabs and spaces. I pasted the fragment into a new blank shader (to be sure the vertex was unaffected, and still nothing. I cannot figure it out for the life of me.

  • IgnatzIgnatz Mod
    Posts: 5,396

    Well, I pasted your last two versions above into the standard fragment shader and they seem to work fine
    :-?

  • edited October 2014 Posts: 342

    Weird. But after realizing I had problems in other apps as well, I restarted my iPad entirely and it suddenly worked. Well, I say worked but that's a lie, it was horribly dysfunctional. So then I decided to try porting one that was in a more similar shader language, and the effect came out being much closer to working, but not producing the second part of the image that turns it 3D when viewed correctly. That version is here (I'm not asking for help, but figured id post it for if anyone else is interested, as I would really like to get it working).

    precision highp float;
    
    uniform highp sampler2D bgl_DepthTexture;
    uniform highp float bgl_RenderedTextureWidth;
    uniform highp float bgl_RenderedTextureHeight;
    uniform highp float ast_EyeSeparation;
    uniform highp float ast_FocalLength;
    uniform highp float ast_NoiseTime;
    uniform int ast_ShowGuides;
    varying highp vec2 vTexCoord;
    
    highp float normalization_factor = 2.0 / pow(ast_EyeSeparation, 0.3);
    
    float getDepth(float x)
    {
        float col = texture2D(bgl_DepthTexture, vec2(x, vTexCoord.y)).r;
        return (1.0 - col) * normalization_factor;
    }
    
    float noise(float x)
    {
        float y = vTexCoord.y;
        int a = int(mod(x, ast_EyeSeparation) * bgl_RenderedTextureWidth);
        int b = int(y * bgl_RenderedTextureHeight);
        vec2 tc = vec2(a, b);
        return mod(sin(dot(tc, vec2(12.9898,78.233+ast_NoiseTime))) *           43758.5453, 1.0);
        float c = texture2D(bgl_DepthTexture, vTexCoord).r;
        return 1.0-abs(0.50/c-1.0);
    }
    
    float noise2(float x)
    {
        float y = vTexCoord.y;
        float pix = bgl_RenderedTextureWidth;
        vec2 tc = floor(vec2(mod(x, ast_EyeSeparation), y)*pix)/pix;
        return mod(sin(dot(tc, vec2(12.9898,78.233+ast_NoiseTime))) * 43758.5453, 1.0);
    }
    
    
    void main()
    {
        float x = vTexCoord.x;
        float y = vTexCoord.y;
        float s_size = 20.0;
        if ((ast_ShowGuides!=0) && (pow((vTexCoord.x-0.5+ast_EyeSeparation/2.0)*bgl_RenderedTextureWidth, 2.) +pow((vTexCoord.y-0.07)*bgl_RenderedTextureHeight, 2.) < s_size || pow((vTexCoord.x-0.5-ast_EyeSeparation/2.0)*bgl_RenderedTextureWidth, 2.) +pow((vTexCoord.y-0.07)*bgl_RenderedTextureHeight, 2.) < s_size))
        {
            gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
        } else {
            float k = 0.0;
            float t = x-ast_EyeSeparation/2.0;
            float d;
            int steps = int(1.0/ast_EyeSeparation); //*2
            while (t > ast_EyeSeparation/2.0-0.05 && steps > 0) {
                d = getDepth(t);
                k += d;
                t -= ast_EyeSeparation - d;
                steps--;
            }
            gl_FragColor = vec4(noise(mod(x+ k, ast_EyeSeparation)));
            gl_FragColor.a = 1.0;
        }
    }
    
Sign In or Register to comment.