Examples for GL_ARB_fragment_program?

Hi,

I am trying to learn GL_ARB_fragment_program, however I’ve a hard time finding tutorials or examples.
Do you know some tutorials, or old code example howto use this stuff?

Thank you in advance, Clemens

Especially some examples howto to use:
glGetProgramivARB
ProgramLocalParameter4fARB
ProgramEnvParameter4fARB

Any whats the difference between local and env parameters?

I think that you might find some examples in older ATI or Nvidia SDK.

Any whats the difference between local and env parameters?

The env parameters are shared between all programs of the same type (e.g. fragment) while the local parameters are set for specific program. In C++ the local parameters would be similar to class members while the env parameters would be similar to global variables.

Study ARB-asm by:

With the cgc compiler, you can specify bindings. Here’s a funky example:
(yeah, lighting etc are a mess here)


varying vec3 varN: TEX0;
varying vec2 varCoord: TEX1;
varying vec3 varPos : TEX2;


#if IS_VERTEX
attribute vec3 inN : ATTR1;
attribute vec2 inCoord: ATTR2;

uniform mat4 mvpx : C0;

void main(){
	varN = -inN;
	varCoord = inCoord;
	varPos = gl_Vertex;
	gl_Position = mvpx * gl_Vertex;
}

#endif

#if IS_FRAGMENT
uniform sampler2D tex: TEXUNIT0;

uniform vec4 AllLights[8] : C0;


void main(){
	vec4 color = texture2D(tex,varCoord);
	float diffuse = max(0.0,dot(varN,vec3(-0.5,-0.5,-0.5)));
	
	for(int i=0;i<8;i++){
		vec3 nn = varPos-AllLights[i].xyz;
		float L = AllLights[i].w / length(nn);
		float Dot = dot(normalize(nn),varN);
		Dot = max(Dot,0.0);
		//diffuse+= L*L * Dot;
		//diffuse+= L*L;
		diffuse+= L;
	}
	
	gl_FragColor = color * diffuse;
}
#endif

See the “uniform mat4 mvpx : C0;” . I haven’t found a way to make some of my uniforms global (to make them env-params), so I’m using only local-params.

Btw, look for the glProgramLocalParameters4fvEXT() , it lets you upload all uniforms at once.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.