Commit f85b1b3a2952fdc0437d6f7e0dc5c0b322a3de9b
1 parent
e1700dd0
add proper light
Showing
1 changed file
with
52 additions
and
24 deletions
Show diff stats
main.cu
... | ... | @@ -76,6 +76,10 @@ float radius = 3; //equals to radius |
76 | 76 | int adjoint_fac = 0; |
77 | 77 | int light_fac = 0; |
78 | 78 | |
79 | +//light position | |
80 | +stim::vec3<float> l1(0.0, 0.0, 0.0); | |
81 | +stim::vec3<float> l2(0.0, 0.0, 0.0); | |
82 | + | |
79 | 83 | //sets an OpenGL viewport taking up the entire window |
80 | 84 | void glut_render_single_projection(){ |
81 | 85 | |
... | ... | @@ -126,6 +130,50 @@ void glut_render_modelview(){ |
126 | 130 | //draws the network(s) |
127 | 131 | void glut_render(void) { |
128 | 132 | |
133 | + // light | |
134 | + stim::vec3<float> eye = cam.getPosition(); //get the camera position (eye point) | |
135 | + if (l1[0] + l1[1] + l1[2] + l2[0] + l2[1] + l2[2] == 0) { | |
136 | + stim::vec3<float> s = bb.size(); | |
137 | + | |
138 | + l1[0] = eye[0] + s[0] / 2; | |
139 | + l1[1] = eye[1] + s[1] / 2; | |
140 | + l1[2] = eye[2] + s[2] / 2; | |
141 | + l2[0] = eye[0] - s[0] / 2; | |
142 | + l2[1] = eye[1] - s[1] / 2; | |
143 | + l2[2] = eye[2] - s[2] / 2; | |
144 | + } | |
145 | + | |
146 | + GLfloat global_ambient[] = { 0.3, 0.3, 0.3, 1.0 }; | |
147 | + GLfloat ambient[] = { 0.0, 0.0, 0.0, 1.0 }; | |
148 | + GLfloat diffuse1[] = { 0.6, 0.6, 0.6, 1.0 }; | |
149 | + GLfloat diffuse2[] = { 0.4, 0.4, 0.4, 1.0 }; | |
150 | + GLfloat specular[] = { 0.6, 0.6, 0.6, 1.0 }; | |
151 | + GLfloat position1[] = { l1[0], l1[1], 50, 0.0 }; // upper right light source | |
152 | + GLfloat position2[] = { l2[0], l2[1], 0, 0.0 }; // lower left light source | |
153 | + GLfloat position[] = { eye[0], eye[1], 50, 1.0 }; | |
154 | + | |
155 | + glClearColor(0.0, 0.0, 0.0, 1.0); | |
156 | + glShadeModel(GL_SMOOTH); | |
157 | + | |
158 | + glLightModelfv(GL_LIGHT_MODEL_AMBIENT, global_ambient); | |
159 | + | |
160 | + glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); | |
161 | + glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse1); | |
162 | + glLightfv(GL_LIGHT0, GL_SPECULAR, specular); | |
163 | + glLightfv(GL_LIGHT0, GL_POSITION, position1); | |
164 | + | |
165 | + glLightfv(GL_LIGHT1, GL_AMBIENT, ambient); | |
166 | + glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse2); | |
167 | + glLightfv(GL_LIGHT1, GL_SPECULAR, specular); | |
168 | + glLightfv(GL_LIGHT1, GL_POSITION, position2); | |
169 | + | |
170 | + glLightfv(GL_LIGHT2, GL_AMBIENT, ambient); | |
171 | + glLightfv(GL_LIGHT2, GL_DIFFUSE, diffuse1); | |
172 | + glLightfv(GL_LIGHT2, GL_SPECULAR, specular); | |
173 | + glLightfv(GL_LIGHT2, GL_POSITION, position); | |
174 | + | |
175 | + glEnable(GL_COLOR_MATERIAL); | |
176 | + | |
129 | 177 | //no mapping, just comparing |
130 | 178 | if (ind == 0) { |
131 | 179 | if (num_nets == 1) { //if a single network is loaded |
... | ... | @@ -266,6 +314,8 @@ void glut_render(void) { |
266 | 314 | glEnable(GL_LIGHTING); |
267 | 315 | } |
268 | 316 | |
317 | + glDisable(GL_COLOR_MATERIAL); | |
318 | + | |
269 | 319 | glutSwapBuffers(); |
270 | 320 | } |
271 | 321 | |
... | ... | @@ -409,12 +459,14 @@ void glut_keyboard(unsigned char key, int x, int y){ |
409 | 459 | glEnable(GL_LIGHTING); |
410 | 460 | glEnable(GL_LIGHT0); |
411 | 461 | glEnable(GL_LIGHT1); |
462 | + glEnable(GL_LIGHT2); | |
412 | 463 | } |
413 | 464 | else if (light_fac && !adjoint_fac) { |
414 | 465 | light_fac = 0; |
415 | 466 | glDisable(GL_LIGHTING); |
416 | 467 | glDisable(GL_LIGHT0); |
417 | 468 | glDisable(GL_LIGHT1); |
469 | + glDisable(GL_LIGHT2); | |
418 | 470 | } |
419 | 471 | break; |
420 | 472 | |
... | ... | @@ -496,30 +548,6 @@ void glut_initialize(){ |
496 | 548 | //place the camera along the z-axis at a distance determined by the network size along x and y |
497 | 549 | cam.setPosition(c + stim::vec<float>(0, 0, camera_factor * std::max(bb.size()[0], bb.size()[1]))); |
498 | 550 | cam.LookAt(c[0], c[1], c[2]); //look at the center of the network |
499 | - | |
500 | - // light | |
501 | - GLfloat ambient[] = { 0.2, 0.2, 0.2, 1.0 }; | |
502 | - GLfloat diffuse1[] = { 0.8, 0.8, 0.8, 1.0 }; | |
503 | - GLfloat diffuse2[] = { 0.4, 0.4, 0.4, 1.0 }; | |
504 | - //GLfloat specular[] = { 1.0, 1.0, 1.0, 1.0 }; | |
505 | - GLfloat position1[] = { 2 * c[0], 4 * c[1], 1 * c[0], 1.0 }; // upper right light source | |
506 | - GLfloat position2[] = { 0.0, -2 * c[1], 1 * c[0], 1.0 }; // lower left light source | |
507 | - glClearColor(0.0, 0.0, 0.0, 1.0); | |
508 | - glShadeModel(GL_SMOOTH); | |
509 | - | |
510 | - | |
511 | - glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient); | |
512 | - | |
513 | - glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse1); | |
514 | - //glLightfv(GL_LIGHT0, GL_SPECULAR, specular); | |
515 | - glLightfv(GL_LIGHT0, GL_POSITION, position1); | |
516 | - //glMaterialfv(GL_FRONT, GL_SPECULAR, specular); | |
517 | - //glMaterialf(GL_FRONT, GL_SHININESS, 60.0); | |
518 | - | |
519 | - glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse2); | |
520 | - glLightfv(GL_LIGHT1, GL_POSITION, position2); | |
521 | - | |
522 | - glEnable(GL_NORMALIZE); | |
523 | 551 | } |
524 | 552 | |
525 | 553 | #ifdef __CUDACC__ | ... | ... |