GLGraphics & GLSL
in
Contributed Library Questions
•
3 years ago
I've been trying out the shader examples in the GLGraphics library, but having some problems to make them work. I'm on WinXP with an ATI Radeon 4800 series graphics card.
1) I installed the CG toolkit from NVidia, but the CGShader and CGFX examples don't work correctly, giving me the following message in the console: GL_ARB_geometry_shader4 extension not available.
2) The provided GLSLShader example does work, but I'm having trouble using other GLSL shaders. I installed RenderMonkey and Shader Designer to create new shaders. RenderMonkey seems to be quite elaborate, making it difficult for a beginner to cross-over the needed files, so that one's on hold. Shader Designer is a lot clearer in it's approach. You have the vertex and fragment shader code and the preview. However when you use that code in the GLGraphics library it doesn't work. I've tried all the example shaders from Shader Designer with the GLGraphics library by replacing the shaders from the GLGraphics toon shader example sketch. Conclusion: none of them really work, even though most seem to run without errors.
Here is a graphical example. On the left how the shader should look, on the right how it comes out in Processing.
The Processing console output when running with this code is error-free:
Vertex shader polkadot3d.vert compilation:
Vertex shader was successfully compiled to run on hardware.
Fragment shader polkadot3d.frag compilation:
Fragment shader was successfully compiled to run on hardware.
GLSL program validation:
Fragment shader(s) linked, vertex shader(s) linked.
Validation successful.
Here is the full code for the vertex and fragment shader.
The above code it just to make the discussion a little less abstract, but like I said, none of the shaders I tried work. I even tried a brick example vertex and fragment shader directly from the "OpenGL Shading Language, Third Edition" book, but alas. I'll be the first to admit I have currently no knowledge of OPENGL or GLSL, which severely limits by problem-solving abilities on this issue.
So what could be the problem?
3) Finally a more general point. During my search today, I noticed that a lot of the websites were from (many) years back. Which makes me wonder if GLSL is the one I should be getting into. Or has it been replaced by modern alternatives? Since for me at this point there's no path dependency to go with one over the other, should there be other options. The goal being (1) using the GPU for faster sketches and (2) creating cool new effects.
1) I installed the CG toolkit from NVidia, but the CGShader and CGFX examples don't work correctly, giving me the following message in the console: GL_ARB_geometry_shader4 extension not available.
2) The provided GLSLShader example does work, but I'm having trouble using other GLSL shaders. I installed RenderMonkey and Shader Designer to create new shaders. RenderMonkey seems to be quite elaborate, making it difficult for a beginner to cross-over the needed files, so that one's on hold. Shader Designer is a lot clearer in it's approach. You have the vertex and fragment shader code and the preview. However when you use that code in the GLGraphics library it doesn't work. I've tried all the example shaders from Shader Designer with the GLGraphics library by replacing the shaders from the GLGraphics toon shader example sketch. Conclusion: none of them really work, even though most seem to run without errors.
Here is a graphical example. On the left how the shader should look, on the right how it comes out in Processing.
The Processing console output when running with this code is error-free:
Vertex shader polkadot3d.vert compilation:
Vertex shader was successfully compiled to run on hardware.
Fragment shader polkadot3d.frag compilation:
Fragment shader was successfully compiled to run on hardware.
GLSL program validation:
Fragment shader(s) linked, vertex shader(s) linked.
Validation successful.
Here is the full code for the vertex and fragment shader.
- // Vertex Shader for three dimensional polka dots.
- // author(s): Joshua Doss
- // Copyright (C) 2002-2004 3Dlabs Inc. Ltd.
- //Create uniform variables for lighting to allow user interaction
- uniform float SpecularContribution;
- uniform vec3 LightPosition;
- varying vec3 MCPosition;
- varying float LightIntensity;
- void main(void)
- {
- float diffusecontribution = 1.0 - SpecularContribution;
- // compute the vertex position in eye coordinates
- vec3 ecPosition = vec3(gl_ModelViewMatrix * gl_Vertex);
- // compute the transformed normal
- vec3 tnorm = normalize(gl_NormalMatrix * gl_Normal);
- // compute a vector from the model to the light position
- vec3 lightVec = normalize(LightPosition - ecPosition);
- // compute the reflection vector
- vec3 reflectVec = reflect(-lightVec, tnorm);
- // compute a unit vector in direction of viewing position
- vec3 viewVec = normalize(-ecPosition);
- // calculate amount of diffuse light based on normal and light angle
- float diffuse = max(dot(lightVec, tnorm), 0.0);
- float spec = 0.0;
- // if there is diffuse lighting, calculate specular
- if(diffuse > 0.0)
- {
- spec = max(dot(reflectVec, viewVec), 0.0);
- spec = pow(spec, 16.0);
- }
- // add up the light sources, since this is a varying (global) it will pass to frag shader
- LightIntensity = diffusecontribution * diffuse * 1.5 +
- SpecularContribution * spec;
- // the varying variable MCPosition will be used by the fragment shader to determine where
- // in model space the current pixel is
- MCPosition = vec3 (gl_Vertex);
- // send vertex information
- gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
- }
- // Fragment shader for 3 dimensional polka dot shader.
- // Author: Joshua Doss
- // Copyright (C) 2002-2004 3Dlabs Inc. Ltd.
- varying float LightIntensity;
- varying vec3 MCPosition;
- //Create uniform variables so dots can be spaced and scaled by user
- uniform vec3 Spacing;
- uniform float DotSize;
- //Create colors as uniform variables so they can be easily changed
- uniform vec3 ModelColor, PolkaDotColor;
- void main(void)
- {
- float insidesphere, sphereradius, scaledpointlength;
- vec3 scaledpoint, finalcolor;
- // Scale the coordinate system
- // The following line of code is not yet implemented in current drivers:
- // mcpos = mod(Spacing, MCposition);
- // We will use a workaround found below for now
- scaledpoint = MCPosition - (Spacing * floor(MCPosition/Spacing));
- // Bring the scaledpoint vector into the center of the scaled coordinate system
- scaledpoint = scaledpoint - Spacing/2.0;
- // Find the length of the scaledpoint vector and compare it to the dotsize
- scaledpointlength = length(scaledpoint);
- insidesphere = step(scaledpointlength,DotSize);
- // Determine final output color before lighting
- finalcolor = vec3(mix(ModelColor, PolkaDotColor, insidesphere));
- // Output final color and factor in lighting
- gl_FragColor = clamp((vec4( finalcolor, 1.0 ) * LightIntensity), vec4(0.0), vec4(1.0));
- }
The above code it just to make the discussion a little less abstract, but like I said, none of the shaders I tried work. I even tried a brick example vertex and fragment shader directly from the "OpenGL Shading Language, Third Edition" book, but alas. I'll be the first to admit I have currently no knowledge of OPENGL or GLSL, which severely limits by problem-solving abilities on this issue.
So what could be the problem?
3) Finally a more general point. During my search today, I noticed that a lot of the websites were from (many) years back. Which makes me wonder if GLSL is the one I should be getting into. Or has it been replaced by modern alternatives? Since for me at this point there's no path dependency to go with one over the other, should there be other options. The goal being (1) using the GPU for faster sketches and (2) creating cool new effects.
1