OpenGL: set OpenGL lights through simple shader API.
This commit is contained in:
@@ -55,6 +55,9 @@
|
|||||||
|
|
||||||
#include "BLF_api.h"
|
#include "BLF_api.h"
|
||||||
|
|
||||||
|
#include "GPU_draw.h"
|
||||||
|
#include "GPU_simple_shader.h"
|
||||||
|
|
||||||
#include "UI_interface.h"
|
#include "UI_interface.h"
|
||||||
|
|
||||||
/* own include */
|
/* own include */
|
||||||
@@ -1216,14 +1219,12 @@ void ui_draw_but_COLORBAND(uiBut *but, uiWidgetColors *UNUSED(wcol), const rcti
|
|||||||
void ui_draw_but_UNITVEC(uiBut *but, uiWidgetColors *wcol, const rcti *rect)
|
void ui_draw_but_UNITVEC(uiBut *but, uiWidgetColors *wcol, const rcti *rect)
|
||||||
{
|
{
|
||||||
static GLuint displist = 0;
|
static GLuint displist = 0;
|
||||||
int a, old[8];
|
float diff[4], diffn[4] = {1.0f, 1.0f, 1.0f, 1.0f};
|
||||||
GLfloat diff[4], diffn[4] = {1.0f, 1.0f, 1.0f, 1.0f};
|
float size;
|
||||||
float vec0[4] = {0.0f, 0.0f, 0.0f, 0.0f};
|
|
||||||
float dir[4], size;
|
|
||||||
|
|
||||||
/* store stuff */
|
/* store stuff */
|
||||||
glGetMaterialfv(GL_FRONT, GL_DIFFUSE, diff);
|
glGetMaterialfv(GL_FRONT, GL_DIFFUSE, diff);
|
||||||
|
|
||||||
/* backdrop */
|
/* backdrop */
|
||||||
glColor3ubv((unsigned char *)wcol->inner);
|
glColor3ubv((unsigned char *)wcol->inner);
|
||||||
UI_draw_roundbox_corner_set(UI_CNR_ALL);
|
UI_draw_roundbox_corner_set(UI_CNR_ALL);
|
||||||
@@ -1234,24 +1235,18 @@ void ui_draw_but_UNITVEC(uiBut *but, uiWidgetColors *wcol, const rcti *rect)
|
|||||||
glCullFace(GL_BACK);
|
glCullFace(GL_BACK);
|
||||||
glEnable(GL_CULL_FACE);
|
glEnable(GL_CULL_FACE);
|
||||||
|
|
||||||
/* disable blender light */
|
/* setup lights */
|
||||||
for (a = 0; a < 8; a++) {
|
GPULightData light = {0};
|
||||||
old[a] = glIsEnabled(GL_LIGHT0 + a);
|
light.type = GPU_LIGHT_SUN;
|
||||||
glDisable(GL_LIGHT0 + a);
|
copy_v3_v3(light.diffuse, diffn);
|
||||||
}
|
zero_v3(light.specular);
|
||||||
|
ui_but_v3_get(but, light.direction);
|
||||||
/* own light */
|
|
||||||
glEnable(GL_LIGHT7);
|
|
||||||
glEnable(GL_LIGHTING);
|
|
||||||
|
|
||||||
ui_but_v3_get(but, dir);
|
|
||||||
|
|
||||||
dir[3] = 0.0f; /* glLightfv needs 4 args, 0.0 is sun */
|
GPU_simple_shader_light_set(0, &light);
|
||||||
glLightfv(GL_LIGHT7, GL_POSITION, dir);
|
for (int a = 1; a < 8; a++)
|
||||||
glLightfv(GL_LIGHT7, GL_DIFFUSE, diffn);
|
GPU_simple_shader_light_set(a, NULL);
|
||||||
glLightfv(GL_LIGHT7, GL_SPECULAR, vec0);
|
|
||||||
glLightf(GL_LIGHT7, GL_CONSTANT_ATTENUATION, 1.0f);
|
glEnable(GL_LIGHTING);
|
||||||
glLightf(GL_LIGHT7, GL_LINEAR_ATTENUATION, 0.0f);
|
|
||||||
|
|
||||||
/* transform to button */
|
/* transform to button */
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
@@ -1283,10 +1278,10 @@ void ui_draw_but_UNITVEC(uiBut *but, uiWidgetColors *wcol, const rcti *rect)
|
|||||||
glCallList(displist);
|
glCallList(displist);
|
||||||
|
|
||||||
/* restore */
|
/* restore */
|
||||||
|
GPU_default_lights();
|
||||||
glDisable(GL_LIGHTING);
|
glDisable(GL_LIGHTING);
|
||||||
glDisable(GL_CULL_FACE);
|
glDisable(GL_CULL_FACE);
|
||||||
glMaterialfv(GL_FRONT, GL_DIFFUSE, diff);
|
glMaterialfv(GL_FRONT, GL_DIFFUSE, diff);
|
||||||
glDisable(GL_LIGHT7);
|
|
||||||
|
|
||||||
/* AA circle */
|
/* AA circle */
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
@@ -1298,12 +1293,6 @@ void ui_draw_but_UNITVEC(uiBut *but, uiWidgetColors *wcol, const rcti *rect)
|
|||||||
|
|
||||||
/* matrix after circle */
|
/* matrix after circle */
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
|
|
||||||
/* enable blender light */
|
|
||||||
for (a = 0; a < 8; a++) {
|
|
||||||
if (old[a])
|
|
||||||
glEnable(GL_LIGHT0 + a);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ui_draw_but_curve_grid(const rcti *rect, float zoomx, float zoomy, float offsx, float offsy, float step)
|
static void ui_draw_but_curve_grid(const rcti *rect, float zoomx, float zoomy, float offsx, float offsy, float step)
|
||||||
|
@@ -78,6 +78,7 @@
|
|||||||
#include "GPU_draw.h"
|
#include "GPU_draw.h"
|
||||||
#include "GPU_extensions.h"
|
#include "GPU_extensions.h"
|
||||||
#include "GPU_material.h"
|
#include "GPU_material.h"
|
||||||
|
#include "GPU_simple_shader.h"
|
||||||
|
|
||||||
#include "PIL_time.h"
|
#include "PIL_time.h"
|
||||||
|
|
||||||
@@ -1894,7 +1895,6 @@ void GPU_end_object_materials(void)
|
|||||||
|
|
||||||
int GPU_default_lights(void)
|
int GPU_default_lights(void)
|
||||||
{
|
{
|
||||||
float zero[4] = {0.0f, 0.0f, 0.0f, 0.0f}, position[4];
|
|
||||||
int a, count = 0;
|
int a, count = 0;
|
||||||
|
|
||||||
/* initialize */
|
/* initialize */
|
||||||
@@ -1918,41 +1918,27 @@ int GPU_default_lights(void)
|
|||||||
U.light[2].spec[3] = 1.0;
|
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++) {
|
for (a = 0; a < 8; a++) {
|
||||||
if (a < 3) {
|
if (a < 3 && U.light[a].flag) {
|
||||||
if (U.light[a].flag) {
|
GPULightData light = {0};
|
||||||
glEnable(GL_LIGHT0 + a);
|
|
||||||
|
|
||||||
normalize_v3_v3(position, U.light[a].vec);
|
light.type = GPU_LIGHT_SUN;
|
||||||
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);
|
|
||||||
|
|
||||||
count++;
|
normalize_v3_v3(light.direction, U.light[a].vec);
|
||||||
}
|
copy_v3_v3(light.diffuse, U.light[a].col);
|
||||||
else {
|
copy_v3_v3(light.specular, U.light[a].spec);
|
||||||
glDisable(GL_LIGHT0 + a);
|
|
||||||
|
|
||||||
glLightfv(GL_LIGHT0 + a, GL_POSITION, zero);
|
GPU_simple_shader_light_set(a, &light);
|
||||||
glLightfv(GL_LIGHT0 + a, GL_DIFFUSE, zero);
|
|
||||||
glLightfv(GL_LIGHT0 + a, GL_SPECULAR, zero);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* clear stuff from other opengl lamp usage */
|
count++;
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
glDisable(GL_LIGHT0 + a);
|
GPU_simple_shader_light_set(a, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
glDisable(GL_LIGHTING);
|
|
||||||
|
|
||||||
|
glDisable(GL_LIGHTING);
|
||||||
glDisable(GL_COLOR_MATERIAL);
|
glDisable(GL_COLOR_MATERIAL);
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
@@ -1963,15 +1949,14 @@ int GPU_scene_object_lights(Scene *scene, Object *ob, int lay, float viewmat[4][
|
|||||||
Base *base;
|
Base *base;
|
||||||
Lamp *la;
|
Lamp *la;
|
||||||
int count;
|
int count;
|
||||||
float position[4], direction[4], energy[4];
|
|
||||||
|
|
||||||
/* disable all lights */
|
/* disable all lights */
|
||||||
for (count = 0; count < 8; count++)
|
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
|
/* view direction for specular is not computed correct by default in
|
||||||
* opengl, so we set the settings ourselfs */
|
* 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;
|
count = 0;
|
||||||
|
|
||||||
@@ -1988,41 +1973,37 @@ int GPU_scene_object_lights(Scene *scene, Object *ob, int lay, float viewmat[4][
|
|||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glLoadMatrixf((float *)viewmat);
|
glLoadMatrixf((float *)viewmat);
|
||||||
|
|
||||||
if (la->type == LA_SUN) {
|
/* setup light */
|
||||||
/* sun lamp */
|
GPULightData light = {0};
|
||||||
copy_v3_v3(direction, base->object->obmat[2]);
|
|
||||||
direction[3] = 0.0;
|
|
||||||
|
|
||||||
glLightfv(GL_LIGHT0+count, GL_POSITION, direction);
|
mul_v3_v3fl(light.diffuse, &la->r, la->energy);
|
||||||
|
mul_v3_v3fl(light.specular, &la->r, la->energy);
|
||||||
|
|
||||||
|
if (la->type == LA_SUN) {
|
||||||
|
/* directional sun light */
|
||||||
|
light.type = GPU_LIGHT_SUN;
|
||||||
|
normalize_v3_v3(light.direction, base->object->obmat[2]);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* other lamps with attenuation */
|
/* other lamps with position attenuation */
|
||||||
copy_v3_v3(position, base->object->obmat[3]);
|
copy_v3_v3(light.position, base->object->obmat[3]);
|
||||||
position[3] = 1.0f;
|
|
||||||
|
|
||||||
glLightfv(GL_LIGHT0+count, GL_POSITION, position);
|
light.constant_attenuation = 1.0f;
|
||||||
glLightf(GL_LIGHT0+count, GL_CONSTANT_ATTENUATION, 1.0);
|
light.linear_attenuation = la->att1 / la->dist;
|
||||||
glLightf(GL_LIGHT0+count, GL_LINEAR_ATTENUATION, la->att1 / la->dist);
|
light.quadratic_attenuation = la->att2 / (la->dist * la->dist);
|
||||||
glLightf(GL_LIGHT0+count, GL_QUADRATIC_ATTENUATION, la->att2 / (la->dist * la->dist));
|
|
||||||
|
|
||||||
if (la->type == LA_SPOT) {
|
if (la->type == LA_SPOT) {
|
||||||
/* spot lamp */
|
light.type = GPU_LIGHT_SPOT;
|
||||||
negate_v3_v3(direction, base->object->obmat[2]);
|
negate_v3_v3(light.direction, base->object->obmat[2]);
|
||||||
glLightfv(GL_LIGHT0 + count, GL_SPOT_DIRECTION, direction);
|
normalize_v3(light.direction);
|
||||||
glLightf(GL_LIGHT0 + count, GL_SPOT_CUTOFF, RAD2DEGF(la->spotsize * 0.5f));
|
light.spot_cutoff = RAD2DEGF(la->spotsize * 0.5f);
|
||||||
glLightf(GL_LIGHT0 + count, GL_SPOT_EXPONENT, 128.0f * la->spotblend);
|
light.spot_exponent = 128.0f * la->spotblend;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
glLightf(GL_LIGHT0 + count, GL_SPOT_CUTOFF, 180.0);
|
light.type = GPU_LIGHT_POINT;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* setup energy */
|
GPU_simple_shader_light_set(count, &light);
|
||||||
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);
|
|
||||||
|
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
|
|
||||||
@@ -2092,6 +2073,7 @@ void GPU_state_init(void)
|
|||||||
glDisable(GL_DEPTH_TEST);
|
glDisable(GL_DEPTH_TEST);
|
||||||
glDisable(GL_FOG);
|
glDisable(GL_FOG);
|
||||||
glDisable(GL_LIGHTING);
|
glDisable(GL_LIGHTING);
|
||||||
|
glDisable(GL_COLOR_MATERIAL);
|
||||||
glDisable(GL_LOGIC_OP);
|
glDisable(GL_LOGIC_OP);
|
||||||
glDisable(GL_STENCIL_TEST);
|
glDisable(GL_STENCIL_TEST);
|
||||||
glDisable(GL_TEXTURE_1D);
|
glDisable(GL_TEXTURE_1D);
|
||||||
|
Reference in New Issue
Block a user