Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to pass ofxHapPlayer textures to a custom shader #74

Open
sdnorris opened this issue Mar 13, 2022 · 0 comments
Open

Unable to pass ofxHapPlayer textures to a custom shader #74

sdnorris opened this issue Mar 13, 2022 · 0 comments

Comments

@sdnorris
Copy link

sdnorris commented Mar 13, 2022

I've made a post detailing this issue in the openFrameworks forum, but was directed here after we unable to resolve it there. To avoid redundancy, the full post is here, but I'll include the necessary details in this issue.

I have written a custom shader that combines frames of videos from pairs of ofVideoPlayers. It works as expected. However, since switching over to Hap files for this project, I have been unable to get the shader to work in the same way. The shader outputs a combination of the colors in the video textures when dealing with ofVideoPlayers, as detailed in the shader code below, but it outputs black for every pixel when dealing with textures from ofxHapPlayers. The video files are in standard Hap format (not Hap Q or Hap Q Alpha), so I believe that color conversion via the ofxHapPlayer's shader shouldn't be necessary.

I'm relatively new to programming in C++ and GLSL, so it's possible that I'm misunderstanding the way that GLSL uses textures or the way that pointers work, but I can't figure out what I'm doing wrong.

Here is the fragment shader code:

//FRAGMENT SHADER

#version 150

uniform sampler2DRect tex0;
uniform sampler2DRect tex1;

in vec2 texCoordVarying;

out vec4 outputColor;

void main(){
    
    vec4 tex0Col = texture(tex0,texCoordVarying);
    vec4 tex1Col = texture(tex1,texCoordVarying);
    
    float rnew = mod(1.0 + (tex0Col.r-tex1Col.r),1.0);
    float gnew = mod(1.0 + (tex0Col.g-tex1Col.g),1.0);
    float bnew = mod(1.0 + (tex0Col.b-tex1Col.b),1.0);
    
    outputColor = vec4(rnew,bnew,gnew,1.0);
}

And here are two versions of the draw loop in my ofApp. The first is the draw loop I used when I was using ofVideoPlayer, the second is a slightly modified version to deal with the fact that ofxHapPlayer.getTexture() returns a pointer instead of a reference:

//if using ofVideoPlayers:
void ofApp::draw(){
    shader.begin();
    //pass textures to shader:
    shader.setUniformTexture("tex0", video.getTexture(), 1);
    shader.setUniformTexture("tex1", video2.getTexture(), 2);
    //display a blank fbo onto which the shader will project
    fbo.draw(0,0);
    shader.end();

}

//if using ofxHapPlayers:
void ofApp::draw(){
   //store pointers to the textures of the hap players:
    ofTexture * hapTexture = hap.getTexture();
    ofTexture * hap2Texture = hap2.getTexture();
    shader.begin();
   //pass textures into the shaders via use of dereferencing operator
    shader.setUniformTexture("tex0", *hapTexture, 1);
    shader.setUniformTexture("tex1", *hap2Texture, 2);
    //display a blank fbo onto which the shader will project
    fbo.draw(0,0);
    shader.end();

}

EDIT: It's possible that the only solution to this is similar to that of #65, wherein you need to draw a video frame to an FBO and then subsequently access the texture of the FBO. I have tried this before and it does work, but I was warned that performance might quickly become a problem, so I am hoping that there is an alternative solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant