Codea bindings not showing up in shader lab [SOLVED]

Hello,
I’m trying to alter a shader to use in Codea, but the bindings aren’t showing up. If someone could help, what would be great. Here is the code for the fragment shader:


/////////////////////////////////////////////////////////
// Alpha Threshold effect

precision highp float;

uniform lowp sampler2D samplerFront;

uniform float threshold;
uniform float smoothness;
uniform float unpremultiply;

varying vec2 vTex;

void main()
{
    lowp vec4 color = texture2D( samplerFront, vTex ) ;
    if( unpremultiply > 0.0 ) { color.rgb /= color.a ; }
        
    float range = ( color.a - (1.0 - threshold) - (smoothness * 0.05) ) / (0.0001 + smoothness * 0.1) ;
    color.a = smoothstep( 0.0, 1.0, range ) ;
    color.rgb *= color.a ;
        
    gl_FragColor = color ;
}

Hmm, so you do. I missed the ref to threshold, and assumed that was the binding that wasn’t showing up. Sorry, don’t know what the issue is in your case :confused:

The other reason I find bindings failing is if the shader doesn’t compile. Load the whole shader in shader lab and check for errors

@spacemonkey, @toadkick - No luck. After duplicating it, rebooting Codea, etc, I had no luck. @Simeon, could you help please?

Ran into this the other day. The binding won’t show up until your shader code actually uses the bound variable.

@toadkick - What do you mean by that? I reference all the variables in the code.

@Zoyt, can you post a bit more code, ie the vertex shader, and how you are trying creating and trying to bind it? My experience is that it’s normally some minor detail I’ve overlooked when these things don’t work.

I don’t have my ipad with me today, but if you post something I’ll check it out tonight.

@spacemonkey - I use the default vertex shader.

I just threw it together and had no binding problems. Standard vertex shader and you fragment. Then I did a little sample code to check. One thing I then did change, in your shader varrying vTex won’t link up to the standard vertex shader so I changed it to vTexCoord.

Code below, shader is in my shader lab, but I put the fragment shader in a comment.



--# Main
-- x4

-- Use this function to perform your initial setup
function setup()
    print("Hello World!")
    m = mesh()
    m.shader = shader("Documents:alpha")
    m.shader.unpremultiply = 0.5
    m.shader.smoothness = 0.5
    m.shader.threshold = 0.5
    m.shader.samplerFront = readImage("Planet Cute:Selector")
    m:addRect(-50,-50,100,100)
end

-- This function gets called once every frame
function draw()
    -- This sets a dark background color 
    background(40, 40, 50)
    translate(100,100)
    m:draw()
    translate(20,20)
    m:draw()
    -- This sets the line thickness
    strokeWidth(5)

    -- Do your drawing here
    
end

--[[fragment shader

/////////////////////////////////////////////////////////
// Alpha Threshold effect

precision highp float;

uniform lowp sampler2D samplerFront;

uniform float threshold;
uniform float smoothness;
uniform float unpremultiply;

varying vec2 vTexCoord;

void main()
{
    lowp vec4 color = texture2D( samplerFront, vTexCoord ) ;
    if( unpremultiply > 0.0 ) { color.rgb /= color.a ; }
        
    float range = ( color.a - (1.0 - threshold) - (smoothness * 0.05) ) / (0.0001 + smoothness * 0.1) ;
    color.a = smoothstep( 0.0, 1.0, range ) ;
    color.rgb *= color.a ;
        
    gl_FragColor = color ;
}
]]

@spacemonkey - Thank you so much! That also fixed the issue with my shader.