What happens when you forgot BindDefaults


#1

guys, I was playing around with ofShader and ofFbo

but I noticed things were not exactly behaving as they should when I was trying to create the shader with setupShaderFromSource

by using R"(

I don’t think it’s R 's fault because I tried the same by using string +=" …"

still the same weird behavior

so just to be sure it’s not something I was doing wrong I tried to recreate the problem on another example.

at first I tried to transfer something really simple: 01_simpleColorQuad but it worked fine

the program behaved normal both when loaded with ofBuffer from path and when loaded with

setupShaderFromSource

I then tried to transfer something more verbose so I tried the ofxGpuParticles example

Get it from here:

Here is the CODE YOU NEED TO ADD TO VERIFY THIS WEIRD ISSUE:

void GpuParticles::createProgram(){
    string Frag ="#version 330\n\n";
    string Vert = "#version 330\n\n";
    
    Frag += R"(
    uniform sampler2DRect particless0;
    uniform sampler2DRect particless1;
    
    uniform vec3 mouse;
    uniform float radiusSquared;
    uniform float elapsed;
    
    in vec2 texCoordVarying;
    
    layout(location = 0) out vec4 posOut;
    layout(location = 1) out vec4 velOut;
    
    void main()
    {
        vec3 pos = texture(particless0, texCoordVarying.st).xyz;
        vec3 vel = texture(particless1, texCoordVarying.st).xyz;
        
        vec3 direction = mouse - pos.xyz;
        float distSquared = dot(direction, direction);
        float magnitude = 500.0 * (1.0 - distSquared / radiusSquared);
        vec3 force = step(distSquared, radiusSquared) * magnitude * normalize(direction);
        
        force += vec3(0.0, -0.5, 0.0);
        
        vel += elapsed * force;
        
        vel.x *= step(abs(pos.x), 512.0) * 2.0 - 1.0;
        vel.y *= step(abs(pos.y), 384.0) * 2.0 - 1.0;
        
        vel *= 0.995;
        
        pos += elapsed * vel;
        
        posOut = vec4(pos, 1.0);
        velOut = vec4(vel, 0.0);
    }
    )";
    
    Vert += R"(
    in vec4  position;
    in vec2  texcoord;
    
    out vec2 texCoordVarying;
    
    void main()
    {
        texCoordVarying = texcoord;
        gl_Position = position;
    }
    )";
    updateShader.setupShaderFromSource(GL_VERTEX_SHADER,Vert);
    updateShader.setupShaderFromSource(GL_FRAGMENT_SHADER,Frag);
    updateShader.linkProgram();

    
    
    
    Vert = "#version 330\n\n";
    Frag = "#version 330\n\n";
    
    Frag += R"(
    
    out vec4 fragColor;
    
    void main()
    {
        fragColor = vec4(1.0, 1.0, 1.0, 0.1);
    }

    
    )";
    
    Vert += R"(
   
    uniform mat4 modelViewProjectionMatrix;
    uniform sampler2DRect particless0;
    uniform sampler2DRect particless1;
    
    in vec4  position;
    in vec2  texcoord;
    
    out vec2 texCoordVarying;
    
    void main()
    {
        texCoordVarying = texcoord;
        gl_Position = modelViewProjectionMatrix * vec4(texture(particless0, texCoordVarying).xyz, 1.0);
    }
     )";
    
    drawShader.setupShaderFromSource(GL_VERTEX_SHADER,Vert);
    drawShader.setupShaderFromSource(GL_FRAGMENT_SHADER,Frag);
    drawShader.linkProgram();
    
    
}

add this function in the GpuParticles class and call it instead of loadShaders in the example

you will see a tiny WHITE rect flashing really fast

DANGER! do not leave it for a long time, it might create a temporary artifact on your graphics card in the place of the rectangle

I am @ of_v0.9.6_osx_release OSX imac (Retina 5K, 27-inch, Late 2015)

try it at your own risk…

I will proceed to cout the text that is loaded from of Buffer vs the text that is loaded from R and compare it very carefully to see if something is parsed differently… (like a comma missing or smthng) (i doubt it because the GLSL program compiled without errors)


#2

I forgot bindDefaults() :blush: