Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@gmail.com>2015-11-27 23:08:48 +0300
committerBrecht Van Lommel <brechtvanlommel@gmail.com>2015-11-28 17:35:34 +0300
commite1b8a5dc6fc8a3f7a5100a9c66b95d07c39b1cb3 (patch)
tree0f4828365023d16c784eac83364fe63c81e53314 /source/blender/gpu/intern
parentb5f9746dae9c9463705f78d15dcc7d23e66cdad5 (diff)
OpenGL: set OpenGL lights through simple shader API.
Diffstat (limited to 'source/blender/gpu/intern')
-rw-r--r--source/blender/gpu/intern/gpu_draw.c92
1 files changed, 37 insertions, 55 deletions
diff --git a/source/blender/gpu/intern/gpu_draw.c b/source/blender/gpu/intern/gpu_draw.c
index 46924a36327..193230d15bf 100644
--- a/source/blender/gpu/intern/gpu_draw.c
+++ b/source/blender/gpu/intern/gpu_draw.c
@@ -78,6 +78,7 @@
#include "GPU_draw.h"
#include "GPU_extensions.h"
#include "GPU_material.h"
+#include "GPU_simple_shader.h"
#include "PIL_time.h"
@@ -1894,7 +1895,6 @@ void GPU_end_object_materials(void)
int GPU_default_lights(void)
{
- float zero[4] = {0.0f, 0.0f, 0.0f, 0.0f}, position[4];
int a, count = 0;
/* initialize */
@@ -1918,41 +1918,27 @@ int GPU_default_lights(void)
U.light[2].spec[3] = 1.0;
}
- glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_FALSE);
+ GPU_simple_shader_light_set_viewer(false);
for (a = 0; a < 8; a++) {
- if (a < 3) {
- if (U.light[a].flag) {
- glEnable(GL_LIGHT0 + a);
+ if (a < 3 && U.light[a].flag) {
+ GPULightData light = {0};
- normalize_v3_v3(position, U.light[a].vec);
- position[3] = 0.0f;
-
- glLightfv(GL_LIGHT0 + a, GL_POSITION, position);
- glLightfv(GL_LIGHT0 + a, GL_DIFFUSE, U.light[a].col);
- glLightfv(GL_LIGHT0 + a, GL_SPECULAR, U.light[a].spec);
+ light.type = GPU_LIGHT_SUN;
- count++;
- }
- else {
- glDisable(GL_LIGHT0 + a);
+ normalize_v3_v3(light.direction, U.light[a].vec);
+ copy_v3_v3(light.diffuse, U.light[a].col);
+ copy_v3_v3(light.specular, U.light[a].spec);
- glLightfv(GL_LIGHT0 + a, GL_POSITION, zero);
- glLightfv(GL_LIGHT0 + a, GL_DIFFUSE, zero);
- glLightfv(GL_LIGHT0 + a, GL_SPECULAR, zero);
- }
+ GPU_simple_shader_light_set(a, &light);
- /* clear stuff from other opengl lamp usage */
- glLightf(GL_LIGHT0 + a, GL_SPOT_CUTOFF, 180.0);
- glLightf(GL_LIGHT0 + a, GL_CONSTANT_ATTENUATION, 1.0);
- glLightf(GL_LIGHT0 + a, GL_LINEAR_ATTENUATION, 0.0);
+ count++;
}
else
- glDisable(GL_LIGHT0 + a);
+ GPU_simple_shader_light_set(a, NULL);
}
-
- glDisable(GL_LIGHTING);
+ glDisable(GL_LIGHTING);
glDisable(GL_COLOR_MATERIAL);
return count;
@@ -1963,15 +1949,14 @@ int GPU_scene_object_lights(Scene *scene, Object *ob, int lay, float viewmat[4][
Base *base;
Lamp *la;
int count;
- float position[4], direction[4], energy[4];
/* disable all lights */
for (count = 0; count < 8; count++)
- glDisable(GL_LIGHT0 + count);
+ GPU_simple_shader_light_set(count, NULL);
/* view direction for specular is not computed correct by default in
* opengl, so we set the settings ourselfs */
- glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, ortho ? GL_FALSE : GL_TRUE);
+ GPU_simple_shader_light_set_viewer(!ortho);
count = 0;
@@ -1988,41 +1973,37 @@ int GPU_scene_object_lights(Scene *scene, Object *ob, int lay, float viewmat[4][
glPushMatrix();
glLoadMatrixf((float *)viewmat);
- if (la->type == LA_SUN) {
- /* sun lamp */
- copy_v3_v3(direction, base->object->obmat[2]);
- direction[3] = 0.0;
+ /* setup light */
+ GPULightData light = {0};
+
+ mul_v3_v3fl(light.diffuse, &la->r, la->energy);
+ mul_v3_v3fl(light.specular, &la->r, la->energy);
- glLightfv(GL_LIGHT0+count, GL_POSITION, direction);
+ if (la->type == LA_SUN) {
+ /* directional sun light */
+ light.type = GPU_LIGHT_SUN;
+ normalize_v3_v3(light.direction, base->object->obmat[2]);
}
else {
- /* other lamps with attenuation */
- copy_v3_v3(position, base->object->obmat[3]);
- position[3] = 1.0f;
-
- glLightfv(GL_LIGHT0+count, GL_POSITION, position);
- glLightf(GL_LIGHT0+count, GL_CONSTANT_ATTENUATION, 1.0);
- glLightf(GL_LIGHT0+count, GL_LINEAR_ATTENUATION, la->att1 / la->dist);
- glLightf(GL_LIGHT0+count, GL_QUADRATIC_ATTENUATION, la->att2 / (la->dist * la->dist));
+ /* other lamps with position attenuation */
+ copy_v3_v3(light.position, base->object->obmat[3]);
+
+ light.constant_attenuation = 1.0f;
+ light.linear_attenuation = la->att1 / la->dist;
+ light.quadratic_attenuation = la->att2 / (la->dist * la->dist);
if (la->type == LA_SPOT) {
- /* spot lamp */
- negate_v3_v3(direction, base->object->obmat[2]);
- glLightfv(GL_LIGHT0 + count, GL_SPOT_DIRECTION, direction);
- glLightf(GL_LIGHT0 + count, GL_SPOT_CUTOFF, RAD2DEGF(la->spotsize * 0.5f));
- glLightf(GL_LIGHT0 + count, GL_SPOT_EXPONENT, 128.0f * la->spotblend);
+ light.type = GPU_LIGHT_SPOT;
+ negate_v3_v3(light.direction, base->object->obmat[2]);
+ normalize_v3(light.direction);
+ light.spot_cutoff = RAD2DEGF(la->spotsize * 0.5f);
+ light.spot_exponent = 128.0f * la->spotblend;
}
else
- glLightf(GL_LIGHT0 + count, GL_SPOT_CUTOFF, 180.0);
+ light.type = GPU_LIGHT_POINT;
}
- /* setup energy */
- mul_v3_v3fl(energy, &la->r, la->energy);
- energy[3] = 1.0;
-
- glLightfv(GL_LIGHT0 + count, GL_DIFFUSE, energy);
- glLightfv(GL_LIGHT0 + count, GL_SPECULAR, energy);
- glEnable(GL_LIGHT0 + count);
+ GPU_simple_shader_light_set(count, &light);
glPopMatrix();
@@ -2092,6 +2073,7 @@ void GPU_state_init(void)
glDisable(GL_DEPTH_TEST);
glDisable(GL_FOG);
glDisable(GL_LIGHTING);
+ glDisable(GL_COLOR_MATERIAL);
glDisable(GL_LOGIC_OP);
glDisable(GL_STENCIL_TEST);
glDisable(GL_TEXTURE_1D);