Commit 859a3df7 by Kai Westerkamp

Normals added ^^

specular color fixed
parent 26c7c733
...@@ -32,11 +32,9 @@ void CubeWidget::initializeGL () ...@@ -32,11 +32,9 @@ void CubeWidget::initializeGL ()
static GLfloat lightPosition[4] = { 0.5, 0.0, 2.0, 1.0 }; static GLfloat lightPosition[4] = { 0.5, 0.0, 2.0, 1.0 };
glLightfv(GL_LIGHT0, GL_POSITION, lightPosition); glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
GLfloat white[] = {1.0,1.0,1.0}; GLfloat white[] = {1.0,1.0,1.0};
glLightfv(GL_LIGHT0, GL_DIFFUSE, white); //glLightfv(GL_LIGHT0, GL_DIFFUSE, white);
glLightfv(GL_LIGHT0, GL_SPECULAR, white); //glLightfv(GL_LIGHT0, GL_SPECULAR, white);
//glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 2.0f);
} }
...@@ -60,10 +58,12 @@ void CubeWidget::prepareShader() ...@@ -60,10 +58,12 @@ void CubeWidget::prepareShader()
void CubeWidget::setMaterial(GLfloat *color ) void CubeWidget::setMaterial(GLfloat *color )
{ {
glMaterialfv(GL_FRONT,GL_AMBIENT,color); glMaterialfv(GL_FRONT,GL_AMBIENT,color);
GLfloat white[] = {1.0,1.0,1.0};
glMaterialfv(GL_FRONT,GL_DIFFUSE,color); glMaterialfv(GL_FRONT,GL_DIFFUSE,color);
glMaterialfv(GL_FRONT,GL_SPECULAR,color); glMaterialfv(GL_FRONT,GL_SPECULAR,white);
glMaterialfv(GL_FRONT,GL_SHININESS,new GLfloat(50.0)); GLfloat mShininess[] = {128};
glMaterialfv(GL_FRONT,GL_SHININESS,mShininess);
} }
...@@ -88,6 +88,7 @@ void CubeWidget::paintGL ( ) ...@@ -88,6 +88,7 @@ void CubeWidget::paintGL ( )
glBegin(GL_QUADS); glBegin(GL_QUADS);
setMaterial(red); setMaterial(red);
glNormal3f(0,1,0);
for (float x = -0.5; x < 0.5 ; x+= increment) { for (float x = -0.5; x < 0.5 ; x+= increment) {
for (float y = -0.5; y < 0.5 ; y+= increment ) { for (float y = -0.5; y < 0.5 ; y+= increment ) {
glVertex3f( x+increment, 0.5f,y); glVertex3f( x+increment, 0.5f,y);
...@@ -100,6 +101,7 @@ void CubeWidget::paintGL ( ) ...@@ -100,6 +101,7 @@ void CubeWidget::paintGL ( )
glBegin(GL_QUADS); glBegin(GL_QUADS);
setMaterial(magenta); setMaterial(magenta);
glNormal3f(0,-1,0);
for (float x = -0.5; x < 0.5 ; x+= increment) { for (float x = -0.5; x < 0.5 ; x+= increment) {
for (float y = -0.5; y < 0.5 ; y+= increment ) { for (float y = -0.5; y < 0.5 ; y+= increment ) {
glVertex3f( x+increment, -0.5f,y+increment); glVertex3f( x+increment, -0.5f,y+increment);
...@@ -112,6 +114,7 @@ void CubeWidget::paintGL ( ) ...@@ -112,6 +114,7 @@ void CubeWidget::paintGL ( )
glBegin(GL_QUADS); glBegin(GL_QUADS);
setMaterial(green); setMaterial(green);
glNormal3f(0,0,1);
for (float x = -0.5; x < 0.5 ; x+= increment) { for (float x = -0.5; x < 0.5 ; x+= increment) {
for (float y = -0.5; y < 0.5 ; y+= increment ) { for (float y = -0.5; y < 0.5 ; y+= increment ) {
glVertex3f( x+increment,y+increment, 0.5f); glVertex3f( x+increment,y+increment, 0.5f);
...@@ -124,6 +127,7 @@ void CubeWidget::paintGL ( ) ...@@ -124,6 +127,7 @@ void CubeWidget::paintGL ( )
glBegin(GL_QUADS); glBegin(GL_QUADS);
setMaterial(yellow); setMaterial(yellow);
glNormal3f(0,0,-1);
for (float x = -0.5; x < 0.5 ; x+= increment) { for (float x = -0.5; x < 0.5 ; x+= increment) {
for (float y = -0.5; y < 0.5 ; y+= increment ) { for (float y = -0.5; y < 0.5 ; y+= increment ) {
glVertex3f( x+increment,y, -0.5f); glVertex3f( x+increment,y, -0.5f);
...@@ -136,6 +140,7 @@ void CubeWidget::paintGL ( ) ...@@ -136,6 +140,7 @@ void CubeWidget::paintGL ( )
glBegin(GL_QUADS); glBegin(GL_QUADS);
setMaterial(blue); setMaterial(blue);
glNormal3f(-1,0,0);
for (float x = -0.5; x < 0.5 ; x+= increment) { for (float x = -0.5; x < 0.5 ; x+= increment) {
for (float y = -0.5; y < 0.5 ; y+= increment ) { for (float y = -0.5; y < 0.5 ; y+= increment ) {
glVertex3f( -0.5f, x+increment,y+increment); glVertex3f( -0.5f, x+increment,y+increment);
...@@ -147,6 +152,7 @@ void CubeWidget::paintGL ( ) ...@@ -147,6 +152,7 @@ void CubeWidget::paintGL ( )
glEnd(); glEnd();
glBegin(GL_QUADS); glBegin(GL_QUADS);
setMaterial(cyan); setMaterial(cyan);
glNormal3f(1,0,0);
for (float x = -0.5; x < 0.5 ; x+= increment) { for (float x = -0.5; x < 0.5 ; x+= increment) {
for (float y = -0.5; y < 0.5 ; y+= increment ) { for (float y = -0.5; y < 0.5 ; y+= increment ) {
glVertex3f( 0.5f, x+increment,y); glVertex3f( 0.5f, x+increment,y);
......
...@@ -8,21 +8,29 @@ varying vec3 normal; ...@@ -8,21 +8,29 @@ varying vec3 normal;
void main(void) void main(void)
{ {
vec3 N = normalize(normal); vec3 N = normalize(normal);
vec3 L = normalize(vec3(gl_LightSource[0].position)-position); vec3 L = normalize(gl_LightSource[0].position-position);
vec3 V = normalize(-position.xyz);
vec3 R = reflect(-L,N);
vec4 diffuse = vec4(max(dot(L,N),0.0)); vec4 diffuse = vec4(max(dot(L,N),0.0));
vec4 specular = vec4(pow(max(dot(R,V),0.0),gl_FrontMaterial.shininess));
vec4 Iamb = gl_FrontLightProduct[0].ambient; vec4 Iamb = gl_FrontLightProduct[0].ambient;
vec4 Idiff = gl_FrontLightProduct[0].diffuse*diffuse; vec4 Idiff = gl_FrontLightProduct[0].diffuse*diffuse;
Idiff = clamp(Idiff, 0.0, 1.0); Idiff = clamp(Idiff, 0.0, 1.0);
vec4 Ispec = gl_FrontLightProduct[0].specular*specular; vec3 V = normalize(-position);
Ispec = clamp(Idiff, 0.0, 1.0);
vec4 color = /*gl_FrontLightModelProduct.sceneColor +*/ Iamb + Idiff + Ispec;
gl_FragColor = vec4(color); vec3 R = normalize(reflect(-L,N));
float specular = pow(max(dot(R,V),0.0),gl_FrontMaterial.shininess);//);
vec4 Ispec = gl_FrontLightProduct[0].specular * specular;
Ispec = clamp(Ispec, 0.0, 1.0);
vec4 color = (
Iamb
+ Idiff
+ Ispec
);
gl_FragColor = vec4(specular);
gl_FragColor = color;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment