[PD] glsl code

marius schebella marius.schebella at gmail.com
Thu Nov 8 16:08:10 CET 2007


hmm, sometimes writing emails brings new ideas.
I replaced the two floats with one vec2 pass_other
and that works.
marius.

-----
uniform sampler2D texture;
varying vec2 texcoord0;
uniform vec4 hithresh;	// hi and lo threshold
uniform vec4 lothresh;
uniform vec2 pass_other;

void main()
{
	vec4 A = texture2D(texture, texcoord0);
	A.a = pass_other[0];
	if ((A.r >= hithresh.r) || (A.r <= lothresh.r))
	{
		A.a = pass_other[1];
	}
	gl_FragColor = A;

}
------------


marius schebella wrote:
> hi,
> is it possible to ask shader related questions on the pd list? I am 
> trying to write pix_alpha as a shader, but for now I have problems with 
> the glsl code. (maybe you can also point me to a shader forum or mailing 
> list that you know is good?)
> I have a fragment shader, which is not working, and I don't know why.
> the problem is that "A.a = other" does not set the value correct (it 
> always sets 0).
> If I write A.a = 0.5 for example, then it is working.
> The variables are passed correctly, all other variables work too, so I 
> think it is really a problem of how glsl works, and an error in the 
> code. what it should do is when the red pixel value is within a certain 
> range, the alpha value should be set to the pass value, and if it is 
> outside, it should be set to the other value. (similar to pix_alpha, but 
> only with red at the moment)
> thanks,
> marius.
> 
> ---------
> // red pix alpha
> 
> uniform sampler2D texture;
> varying vec2 texcoord0;
> 
> uniform vec4 hithresh;    // hi and lo threshold
> uniform vec4 lothresh;
> uniform float pass;
> uniform float other;
> 
> void main()
> {
>     vec4 A = texture2D(texture, texcoord0);
>     A.a = pass;
>     if ((A.r >= hithresh.r) || (A.r <= lothresh.r))
>     {
>         A.a = other;
>     }
>     gl_FragColor = A;
> }
> 





More information about the Pd-list mailing list