Quantcast
Viewing all articles
Browse latest Browse all 40524

How to send an array to a shader frag on oF0.9.0

I'm having the exact same problem! Came across this while trying to add a second light to a sketch and instead it came out black, so I wrote a very similar debug sketch. Strangely, using ofSetUniform[X]fv with a count of 1, and reading the result as a normal variable in the shader seems to work, but using a higher count and declaring an array in the shader fails...

ofapp.cpp

    void ofApp::setup(){
	float colors[] = { 1,0.5,0,0,0.5,1 };
	shader.load("test");
	shader.begin();
	shader.setUniform3fv("inColor", colors , 1);    //works
    //shader.setUniform3fv("inColor", colors , 2);  //fails
	shader.end();
	cout << colors;
    }

    //--------------------------------------------------------------
    void ofApp::draw(){
    	shader.begin();
    	ofDrawRectangle(100, 100, ofGetWidth() -200, ofGetHeight() -200);
    	shader.end();
    }

test.frag

#version 430

uniform vec3 inColor;         //works
//uniform vec3 inColor[2];    //fails
out vec4 outColor;

void main() {
	outColor = vec4(inColor, 1);         //works
    //outColor = vec4(inColor[0], 1);   //fails for both array positions
}

Using the 3 working lines draws an orange rectangle, using the 3 broken lines draws a black rectangle whether using array position 0 or 1 in the shader. Changing color to &color[0] as described in the previous answer had no effect on behaviour.

Not sure if this is a 0.9 bug or a GPU driver bug (I know GLSL can be funny with arrays at times). Anyone have any ideas?


Viewing all articles
Browse latest Browse all 40524

Trending Articles