lhkbob - I’m using a GLCanvas. Is that good or bad? Why should an application behave any different from an applet as far as the shaders go?
I’ve tried the demos at https://jogl-demos.dev.java.net/ and no, they don’t react the same way. However, those demos have virtually no geometry and maps apart from the Grand Canyon Demo - (which for me has been flaky and runs only occasionaly on any machine I have tried it on). But anyway the demos in https://jogl-demos.dev.java.net/ seem to point to “Original source code by NVidia” if it points to any source at all and I can find no no actual Java/Jogl/GLSL code. So I can not try their glsl shaders in my app.
When I write a program in c/c++/java my expectation of how it will run is usually borne out. However, beyond the remotely trivial, with glsl/gpu-programming it seems that I have no reasonable expectation over it's behaviour. If I am not alone, surely the gpu programming community must be spending vast amounts of time, painfully and indiscriminatly debugging glsl/gpu code and little time building up hiearchies of knowledge. Other shading languages like RenderMan RSL, as implemented by at least one major renderer ;), is totally predictable and you can easily and quickly build up shaders and libraries. Ok, RSL is not engineered for the GPU (by the renderer I obliquely refer to) but maybe the GPU should be engineered so it can be used effectively without prgramming it in assembler! Is the Gelato implementation of RSL, but exclusively for the gpu, the answer?
And… relax!
Anyway, here are my shaders. In so far as shader programming goes, they are trivial. So why do they apparently randomly swamp my cpu!
Vertex Shader
varying vec3 L[2], N, E;
void main()
{
int i;
/* normal in eye space */
N = gl_NormalMatrix * gl_Normal;
/* vertex in eye space */
vec3 P = vec3(gl_ModelViewMatrix * gl_Vertex);
E = normalize(-P);
for (i = 0; i < 2; i++)
{
/* light vector in eye space */
L[i] = normalize(gl_LightSource[i].position.xyz - P);
}
/* assign the uvs */
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = ftransform();
}
Fragment Shader
varying vec3 L[2], N, E;
uniform sampler2D colourmap;
void main()
{
int i, j;
vec3 nN = normalize(N);
vec4 tcol = texture2D(colourmap, gl_TexCoord[0].st);
vec4 amb = vec4(0);
vec4 diff = vec4(0);
vec4 spec = vec4(0);
for (i = 0; i < 2; i++)
{
vec3 nL = normalize(L[i]);
/* ambient term */
amb += gl_LightSource[i].ambient;
/* the diffuse term */
diff += clamp(dot(nN, nL), 0.0, 1.0)*gl_LightSource[i].diffuse;
/* specular term */
float NdotH = clamp(dot(reflect(-nL, nN), normalize(E)), 0.0, 1.0);
spec += pow(NdotH, gl_FrontMaterial.shininess)*gl_LightSource[i].specular;
}
vec4 color = tcol*(gl_FrontMaterial.ambient*amb+gl_FrontMaterial.diffuse*diff)+gl_FrontMaterial.specular*spec;
gl_FragColor = color;
}