[PD] Lua + Pd + Gem = vertex dataflow (was Re: [psql] object hand-holding)

vade doktorp at mac.com
Sun Dec 23 10:51:33 CET 2007


this distorts the verts with a cos function. with per pixel lighting  
and texture support.


vertex

	uniform float time, amount;
	varying vec4 diffuse,ambient;
	varying vec3 normal,lightDir,halfVector;

	void main()
	{	
	
		//vertz
	
		vec4 v = vec4(gl_Vertex);

		v.xz = v.xz * (cos( gl_Vertex.y + time * 0.01));
			
		gl_Position =  gl_ModelViewProjectionMatrix * v;

		// apply proper texture coord
		gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0 ;

		
		// lights
		/* first transform the normal into eye space and
		normalize the result */
		
		normal = normalize(gl_NormalMatrix * gl_Normal);

		/* now normalize the light's direction. Note that
		according to the OpenGL specification, the light
		is stored in eye space. Also since we're talking about
		a directional light, the position field is actually direction */
		
		lightDir = normalize(vec3(gl_LightSource[0].position));

		/* Normalize the halfVector to pass it to the fragment shader */
		
		halfVector = normalize(gl_LightSource[0].halfVector.xyz);

		/* Compute the diffuse, ambient and globalAmbient terms */
		
		diffuse = gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse;
		ambient = gl_FrontMaterial.ambient * gl_LightSource[0].ambient;
		ambient += gl_LightModel.ambient * gl_FrontMaterial.ambient;

	
		
	}

fragment
		uniform sampler2D tex0;
		
		varying vec4 diffuse,ambient;
		varying vec3 normal,lightDir,halfVector;


		void main()
		{
			
			vec3 ct,cf;
			vec4 texel;
			float intensity,at,af;

			intensity = max(dot(lightDir,normalize(normal)),0.0);

			cf = intensity * (gl_FrontMaterial.diffuse).rgb +
							  gl_FrontMaterial.ambient.rgb;
			af = gl_FrontMaterial.diffuse.a;

			texel = texture2D(tex0,gl_TexCoord[0].st);
			ct = texel.rgb;
			at = texel.a;

			gl_FragColor = vec4(ct * cf, at * af);
		
		}



On Dec 22, 2007, at 8:14 PM, Chris McCormick wrote:

> On Sat, Dec 22, 2007 at 11:26:18AM -0600, chris clepper wrote:
>> This is what the vertex_array objects basically do.  The  
>> vertex_model object
>> opens up a .obj and then passes the vertex, normal, texcoord and  
>> color data
>> to other vertex_ objects for processing.  The speed is pretty good  
>> - better
>> than standard geos - but the better route is to use shaders.   
>> Shaders allow
>> for more end user manipulation than the vertex_objects could ever  
>> offer.
>
> Alright, I'll have to take a closer look at shaders in Gem then.  
> Thanks
> for the advice. Can anyone point me to a simple vertex manipulation
> shader I can run in Gem to get started?
>
> Best,
>
> Chris.
>
> -------------------
> http://mccormick.cx
>
> _______________________________________________
> PD-list at iem.at mailing list
> UNSUBSCRIBE and account-management -> http://lists.puredata.info/listinfo/pd-list





More information about the Pd-list mailing list