Basic shader not rendering STL object correctly


I’m learning myself shaders using the tutorials form lighthouse3d website, I was using ofSphere for my examples, I had not problems at all, then I decided to test with a different 3d object, so I download a teapot from the grabcad website unfortunately the shader does not render the teapot the same way it renders a ofSphere, please see image attached as reference.

Here is my code

#include "testApp.h"  
void testApp::setup(){  
	shader.load("shaders/shader.vert", "shaders/shader.frag");  
//	teapot.centerModel();  
void testApp::draw(){  
	ofBackground( ofColor::black );  
	float posX = ofGetMouseX() - ofGetWidth() * 0.5;  
	float posY = ofGetMouseY() - ofGetHeight() * 0.5;  
	ofVec3f lightPos(posX, -posY, 200);  
	shader.setUniform3fv("lightPos", lightPos.getPtr());  
	ofSphere( 80, 0, 0, 30 );  
	ofTranslate(-80, -20);  


varying vec3 normal;  
void main() {  
	normal = gl_NormalMatrix * gl_Normal;  
	gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;  


uniform vec3 lightPos;  
varying vec3 normal;  
void main() {  
	float intensity;  
	vec4 color;  
	intensity = dot(lightPos, normalize(normal));  
	if (intensity > 0.95) {  
		color = vec4(1.0, 0.5, 0.5, 1.0);  
	else if (intensity > 0.5) {  
		color = vec4(0.6, 0.3, 0.3, 1.0);  
	else if (intensity > 0.25) {  
		color = vec4(0.4, 0.2, 0.2, 1.0);  
	else {  
		color = vec4(0.2, 0.1, 0.1, 1.0);  
	gl_FragColor = color;  

Any help will be much appreciated!

Where can I download this teapot test this out? It almost looks like the vertices are oddly setup. Also, you only have 4 colors you’re spitting out, you probably want something more like this no?

Please find the file inf the link below, the reason for outputting just 4 colours is because I’m doing the lighthouse3d glsl tutorials, and the is the toon shader :wink:

Hey Nardove,

I see the model is scaled by x5, the normals are probably scaling as well in the stl draw. Have you tried glEnable(GL_NORMALIZE)?

Hi Trent,

Did as suggested but same results, I even try not scaling the model and did not make any difference

I’m assuming that you’re not happy with the jagged edges on the side of the teapot? That’s an artifact of the model afaict, here’s your shaders running with a different teapot. Is that the problem that you’re talking about?

![]( Shot 2013-08-10 at 6.20.20 PM.png)

Hi Josh,

I see, there most be something wrong with my implementation, the example I took it from uses the same teapot model that you have and it looks better, please have a look at -this link

Hi Josh,

I see, there most be something wrong with my implementation but I cant see where :frowning: the example I took it from uses the same teapot model that you have and it looks better, please have a look at -this link

Shouldn’t you be using:

	normal = gl_Normal;  
	gl_Position = ftransform();  

since your light isn’t specified in eye space but is rather in world space (that’s the default in OF)

Make the changes but unfortunately the same result

Since you’re calculating your light in the shader, try not using ofLight. That calls a GL_Light, which I don’t think you need at all and might be messing things up. The light is really just a vector that you’re calculating and I wonder if that’s making things a bit strange at the moment.