[PD] Image from shader back to Gem

oliver oliver at klingt.org
Mon Feb 15 10:46:14 CET 2021


cyrille henry wrote:
> What I understand from the original question was how to feed an image 
> generated with a shader to pix_movement.
> So one need an image, not a texture.
> I'm afraid pix_snap is the only solution.

on a more general note:

it would be great to have something like a public [GEM-shader] archive, 
probably something like pdpatchrepo.info

should we open a new category there ?
or maybe that already exists and i missed it ?
anybody else on this list that has some GEM shaders to share ?

i have the feeling that a lot of people using GEM "roll their own" 
shaders  (i, for one, did) and it would be a great thing to join forces, 
so one doesn't have to reinvent the wheel when looking for a simple 
"brightness/contrast" shader ...

my own technical knowledge about shader scripting is close to 
non-existant, but i succeeded in adapting stuff found on the net, so 
that it loads as a shader in GEM. basic stuff only, mixers etc ...

since csaba's original post talks about cropping/rotating a texture 
created from a MATLAB shader (would be also great to share !), one 
possibility could be to feed this texture into another shader.

i tried my clumsy hands on a quick and dirty adaption of MAX's [rota] 
shader, and even though it loads succesfully, it's obviously wrong as 
the resulting texture seems to be 1x1 dimension. i'm sure the error is 
somewhere in the .vert part.

as i said, i got no deep insight into shader scripting, but maybe this 
can help somebody who has

best

oliver

> 
> Cheers
> c
> 
> Le 15/02/2021 à 08:39, IOhannes m zmoelnig a écrit :
>> On 2/14/21 9:52 PM, Miller Puckette via Pd-list wrote:
>>> I think the question is - within a shader, can you 'snap' an image to
>>> a texture so that it doesn't have to go back and forth between the
>>> GPU and CPU?  I'm curious too... I guess there must be a way to do 
>>> this...
>>
>>
>> [pix_snap2tex]
>> or, preferably [gemframebuffer].
>>
>> gfamsdr
>> IOhannes
>>
>>
>> _______________________________________________
>> Pd-list at lists.iem.at mailing list
>> UNSUBSCRIBE and account-management -> 
>> https://lists.puredata.info/listinfo/pd-list
> 
> 
> 
> _______________________________________________
> Pd-list at lists.iem.at mailing list
> UNSUBSCRIBE and account-management -> 
> https://lists.puredata.info/listinfo/pd-list
> 


-- 
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
/////////////// http://pendler.klingt.org //////////////
\\\\\\\\\\\\\\\ http://oliver.klingt.org  \\\\\\\\\\\\\\
////////////////////////////////////////////////////////
-------------- next part --------------
/*
 *
 * Andrew Benson - andrewb at cycling74.com
 * Copyright 2005 - Cycling '74
 *
 * GLSL vertex program for doing a standard vertex transform
 * with texture coordinates, also passing the texture dimensions to the fragment shader.
 *
 */

varying vec2 texcoord0;
varying vec2 texcoord1;

varying vec2 texdim0;
varying vec2 texdim1;

void main()
{
    // perform standard transform on vertex
    gl_Position = ftransform();

    // transform texcoords
    texcoord0 = vec2(gl_TextureMatrix[0] * gl_MultiTexCoord0);
    texcoord1 = vec2(gl_TextureMatrix[1] * gl_MultiTexCoord1);
 
	texdim0 = vec2 (abs(gl_TextureMatrix[0][0][0]),abs(gl_TextureMatrix[0][1][1]));
//	texdim0 = vec2 (abs(gl_TextureMatrix[1][0][0]),abs(gl_TextureMatrix[1][1][1])); // this was a royal fuckup :(
    texdim1 = vec2 (abs(gl_TextureMatrix[1][0][0]),abs(gl_TextureMatrix[1][1][1]));
}
-------------- next part --------------
//setup for 2 texture
varying vec2 texcoord0;
varying vec2 texcoord1;
varying vec2 texdim0;
uniform vec2 zoom;
uniform vec2 offset;
uniform float theta; 
uniform vec2 anchor;
uniform int boundmode; 
uniform sampler2DRect tex0;
uniform sampler2DRect tex1;
const float pi=3.1415926;

void main()
{
	// where is the point?
	vec2 sizea = texdim0;
	vec2 point = texcoord0;
	
	//transormation matrices
	mat2 sca = mat2 (1./zoom.x,0.,0.,1./zoom.y);//scaling matrix (zoom)
	mat2 rot = mat2 (cos(theta),sin(theta),-sin(theta),cos(theta));//rotation matrix

	//perform transform
	vec2 no = ((((point-anchor*sizea)*rot)*sca)+anchor*sizea)+offset;

	//create boundmodes
	vec2 no2 = mod(no,sizea);//wrap	
	
	vec2 no4 = mix(mod(no,sizea),sizea-mod(no,sizea),floor(mod(no,sizea*2.)/sizea));//folded coords
	
	// sampler coord
	vec2 tc = no*float(boundmode==0) + no*float(boundmode==1) + no2*float(boundmode==2) + no*float(boundmode==3) + no4*float(boundmode==4);
	
	
	//sample textures
	vec4 smp0 = texture2DRect(tex0,tc);
	vec4 smp1 = texture2DRect(tex1,texcoord0);
	
	vec2 outbound = sign(floor(no/sizea));//check for point>size
	float boundchk = float(sign(float(outbound.x!=0.)+float(outbound.y!=0.)));
	float checkm0 = float(boundmode==0)*boundchk;
	float checkm1 = float(boundmode==1)*float(boundchk==0.);
	vec4 ifb0 = mix(smp0,smp1,checkm0);//ignore
	vec4 final = ifb0*float(boundmode != 1) + ifb0*float(checkm1==1.);//clear
	
	
	// output texture
	gl_FragColor = final;
}


More information about the Pd-list mailing list