Passing second texture to GLSL shader



  • I'm jumping into some shader dev in HaxeFlixel and one thing I want to do is a multiplication filter.

    Right now I have this shader code:

    #pragma header
    uniform sampler2D tex;
    
    void main()
    {
    	vec4 source= flixel_texture2D(tex, openfl_TextureCoordv);
    	vec4 other= texture2D(tex, openfl_TextureCoordv);
    	gl_FragColor = vec4(source.r * other.r, source.g * other.g, source.b * other.b, source.a);
    }
    

    And am using the shader this way:

    	var mul = new MultiplyShader();
    	var si = new ShaderInput<BitmapData>();
    	var fs = new FlxSprite(0,0, "assets/images/quads.png");
    	si.input = fs.pixels.clone();
    
    	mul.tex = si;
    	FlxG.camera.setFilters([new ShaderFilter(cast inv)]);
    

    Testing other things (like mapping the openfl_TextureCoordv to r/g) works, but I can't access anything from the passed in texture.



  • Seems my problem is partially a little bug with the current release version of OpenFL:
    http://community.openfl.org/t/sampling-second-texture-in-glsl-shader/10628

    Using the GIT develop version allows it to work on flixel sprites.
    But, I can't get a shader that samples a second texture to work in the FlxCamera's shaders.


Log in to reply
 

Looks like your connection to HaxeFlixel was lost, please wait while we try to reconnect.