OpenGL immediate mode: interface_draw.c (cont)

ui_draw_but_COLORBAND
Introduced a new checker shader to be used mostly on transparent areas.

OpenGL immediate mode: interface_draw.c (cont)

ui_draw_but_UNITVEC
Introduced a new shader to be used for simple lighting.
This commit is contained in:
Clément Foucault 2017-02-07 13:04:08 +01:00 committed by Julian Eisel
parent 8fbf1c4d77
commit b4a01e7f4f
8 changed files with 249 additions and 120 deletions

View File

@ -1047,44 +1047,44 @@ void ui_draw_but_VECTORSCOPE(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wco
glDisable(GL_BLEND);
}
static void ui_draw_colorband_handle_tri_hlight(float x1, float y1, float halfwidth, float height)
static void ui_draw_colorband_handle_tri_hlight(unsigned int pos, float x1, float y1, float halfwidth, float height)
{
glEnable(GL_LINE_SMOOTH);
glBegin(GL_LINE_STRIP);
glVertex2f(x1 + halfwidth, y1);
glVertex2f(x1, y1 + height);
glVertex2f(x1 - halfwidth, y1);
glEnd();
immBegin(GL_LINE_STRIP, 3);
immVertex2f(pos, x1 + halfwidth, y1);
immVertex2f(pos, x1, y1 + height);
immVertex2f(pos, x1 - halfwidth, y1);
immEnd();
glDisable(GL_LINE_SMOOTH);
}
static void ui_draw_colorband_handle_tri(float x1, float y1, float halfwidth, float height, bool fill)
static void ui_draw_colorband_handle_tri(unsigned int pos, float x1, float y1, float halfwidth, float height, bool fill)
{
glEnable(fill ? GL_POLYGON_SMOOTH : GL_LINE_SMOOTH);
glBegin(fill ? GL_TRIANGLES : GL_LINE_LOOP);
glVertex2f(x1 + halfwidth, y1);
glVertex2f(x1, y1 + height);
glVertex2f(x1 - halfwidth, y1);
glEnd();
immBegin(fill ? GL_TRIANGLES : GL_LINE_LOOP, 3);
immVertex2f(pos, x1 + halfwidth, y1);
immVertex2f(pos, x1, y1 + height);
immVertex2f(pos, x1 - halfwidth, y1);
immEnd();
glDisable(fill ? GL_POLYGON_SMOOTH : GL_LINE_SMOOTH);
}
static void ui_draw_colorband_handle_box(float x1, float y1, float x2, float y2, bool fill)
static void ui_draw_colorband_handle_box(unsigned int pos, float x1, float y1, float x2, float y2, bool fill)
{
glBegin(fill ? GL_QUADS : GL_LINE_LOOP);
glVertex2f(x1, y1);
glVertex2f(x1, y2);
glVertex2f(x2, y2);
glVertex2f(x2, y1);
glEnd();
immBegin(fill ? GL_QUADS : GL_LINE_LOOP, 4);
immVertex2f(pos, x1, y1);
immVertex2f(pos, x1, y2);
immVertex2f(pos, x2, y2);
immVertex2f(pos, x2, y1);
immEnd();
}
static void ui_draw_colorband_handle(
const rcti *rect, float x,
unsigned int pos, const rcti *rect, float x,
const float rgb[3], struct ColorManagedDisplay *display,
bool active)
{
@ -1103,17 +1103,18 @@ static void ui_draw_colorband_handle(
y1 = floorf(y1 + 0.5f);
if (active || half_width < min_width) {
glBegin(GL_LINES);
glColor3ub(0, 0, 0);
glVertex2f(x, y1);
glVertex2f(x, y2);
glEnd();
immUniformColor3ub(0, 0, 0);
immBegin(GL_LINES, 2);
immVertex2f(pos, x, y1);
immVertex2f(pos, x, y2);
immEnd();
setlinestyle(active ? 2 : 1);
glBegin(GL_LINES);
glColor3ub(200, 200, 200);
glVertex2f(x, y1);
glVertex2f(x, y2);
glEnd();
immUniformColor3ub(200, 200, 200);
immBegin(GL_LINES, 2);
immVertex2f(pos, x, y1);
immVertex2f(pos, x, y2);
immEnd();
setlinestyle(0);
/* hide handles when zoomed out too far */
@ -1125,45 +1126,46 @@ static void ui_draw_colorband_handle(
/* shift handle down */
y1 -= half_width;
glColor3ub(0, 0, 0);
ui_draw_colorband_handle_box(x - half_width, y1 - 1, x + half_width, y1 + height, false);
immUniformColor3ub(0, 0, 0);
ui_draw_colorband_handle_box(pos, x - half_width, y1 - 1, x + half_width, y1 + height, false);
/* draw all triangles blended */
glEnable(GL_BLEND);
ui_draw_colorband_handle_tri(x, y1 + height, half_width, half_width, true);
ui_draw_colorband_handle_tri(pos, x, y1 + height, half_width, half_width, true);
if (active)
glColor3ub(196, 196, 196);
immUniformColor3ub(196, 196, 196);
else
glColor3ub(96, 96, 96);
ui_draw_colorband_handle_tri(x, y1 + height, half_width, half_width, true);
immUniformColor3ub(96, 96, 96);
ui_draw_colorband_handle_tri(pos, x, y1 + height, half_width, half_width, true);
if (active)
glColor3ub(255, 255, 255);
immUniformColor3ub(255, 255, 255);
else
glColor3ub(128, 128, 128);
ui_draw_colorband_handle_tri_hlight(x, y1 + height - 1, (half_width - 1), (half_width - 1));
immUniformColor3ub(128, 128, 128);
ui_draw_colorband_handle_tri_hlight(pos, x, y1 + height - 1, (half_width - 1), (half_width - 1));
glColor3ub(0, 0, 0);
ui_draw_colorband_handle_tri_hlight(x, y1 + height, half_width, half_width);
immUniformColor3ub(0, 0, 0);
ui_draw_colorband_handle_tri_hlight(pos, x, y1 + height, half_width, half_width);
glDisable(GL_BLEND);
glColor3ub(128, 128, 128);
ui_draw_colorband_handle_box(x - (half_width - 1), y1, x + (half_width - 1), y1 + height, true);
immUniformColor3ub(128, 128, 128);
ui_draw_colorband_handle_box(pos, x - (half_width - 1), y1, x + (half_width - 1), y1 + height, true);
if (display) {
IMB_colormanagement_scene_linear_to_display_v3(colf, display);
}
glColor3fv(colf);
ui_draw_colorband_handle_box(x - (half_width - 2), y1 + 1, x + (half_width - 2), y1 + height - 2, true);
immUniformColor3fv(colf);
ui_draw_colorband_handle_box(pos, x - (half_width - 2), y1 + 1, x + (half_width - 2), y1 + height - 2, true);
}
void ui_draw_but_COLORBAND(uiBut *but, uiWidgetColors *UNUSED(wcol), const rcti *rect)
{
struct ColorManagedDisplay *display = NULL;
unsigned int position, color;
ColorBand *coba = (ColorBand *)(but->editcoba ? but->editcoba : but->poin);
if (coba == NULL) return;
@ -1177,17 +1179,22 @@ void ui_draw_but_COLORBAND(uiBut *but, uiWidgetColors *UNUSED(wcol), const rcti
float sizey_solid = sizey / 4;
float y1 = rect->ymin;
/* Drawing the checkerboard.
* This could be optimized with a single checkerboard shader,
* instead of drawing twice and using stippling the second time. */
/* layer: background, to show tranparency */
glColor4ub(UI_ALPHA_CHECKER_DARK, UI_ALPHA_CHECKER_DARK, UI_ALPHA_CHECKER_DARK, 255);
glRectf(x1, y1, x1 + sizex, rect->ymax);
GPU_basic_shader_bind(GPU_SHADER_STIPPLE | GPU_SHADER_USE_COLOR);
glColor4ub(UI_ALPHA_CHECKER_LIGHT, UI_ALPHA_CHECKER_LIGHT, UI_ALPHA_CHECKER_LIGHT, 255);
GPU_basic_shader_stipple(GPU_SHADER_STIPPLE_CHECKER_8PX);
glRectf(x1, y1, x1 + sizex, rect->ymax);
GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
VertexFormat *format = immVertexFormat();
position = add_attrib(format, "pos", GL_FLOAT, 2, KEEP_FLOAT);
immBindBuiltinProgram(GPU_SHADER_2D_CHECKER);
/* Drawing the checkerboard. */
immUniform4f("color1", UI_ALPHA_CHECKER_DARK / 255.f, UI_ALPHA_CHECKER_DARK / 255.f, UI_ALPHA_CHECKER_DARK / 255.f, 1.0f);
immUniform4f("color2", UI_ALPHA_CHECKER_LIGHT / 255.f, UI_ALPHA_CHECKER_LIGHT / 255.f, UI_ALPHA_CHECKER_LIGHT / 255.f, 1.0f);
immUniform1i("size", 8);
immRectf(position, x1, y1, x1 + sizex, rect->ymax);
immUnbindProgram();
/* New format */
format = immVertexFormat();
position = add_attrib(format, "pos", GL_FLOAT, 2, KEEP_FLOAT);
color = add_attrib(format, "color", GL_FLOAT, 4, KEEP_FLOAT);
immBindBuiltinProgram(GPU_SHADER_2D_SMOOTH_COLOR);
/* layer: color ramp */
glEnable(GL_BLEND);
@ -1200,7 +1207,7 @@ void ui_draw_but_COLORBAND(uiBut *but, uiWidgetColors *UNUSED(wcol), const rcti
v1[1] = y1 + sizey_solid;
v2[1] = rect->ymax;
glBegin(GL_TRIANGLE_STRIP);
immBegin(GL_TRIANGLE_STRIP, (sizex+1) * 2);
for (int a = 0; a <= sizex; a++) {
float pos = ((float)a) / sizex;
do_colorband(coba, pos, colf);
@ -1209,17 +1216,17 @@ void ui_draw_but_COLORBAND(uiBut *but, uiWidgetColors *UNUSED(wcol), const rcti
v1[0] = v2[0] = x1 + a;
glColor4fv(colf);
glVertex2fv(v1);
glVertex2fv(v2);
immAttrib4fv(color, colf);
immVertex2fv(position, v1);
immVertex2fv(position, v2);
}
glEnd();
immEnd();
/* layer: color ramp without alpha for reference when manipulating ramp properties */
v1[1] = y1;
v2[1] = y1 + sizey_solid;
glBegin(GL_TRIANGLE_STRIP);
immBegin(GL_TRIANGLE_STRIP, (sizex+1) * 2);
for (int a = 0; a <= sizex; a++) {
float pos = ((float)a) / sizex;
do_colorband(coba, pos, colf);
@ -1228,31 +1235,38 @@ void ui_draw_but_COLORBAND(uiBut *but, uiWidgetColors *UNUSED(wcol), const rcti
v1[0] = v2[0] = x1 + a;
glColor4f(colf[0], colf[1], colf[2], 1.0f);
glVertex2fv(v1);
glVertex2fv(v2);
immAttrib4f(color, colf[0], colf[1], colf[2], 1.0f);
immVertex2fv(position, v1);
immVertex2fv(position, v2);
}
glEnd();
immEnd();
immUnbindProgram();
glDisable(GL_BLEND);
/* New format */
format = immVertexFormat();
position = add_attrib(format, "pos", GL_FLOAT, 2, KEEP_FLOAT);
immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
/* layer: box outline */
glColor4f(0.0, 0.0, 0.0, 1.0);
fdrawbox(x1, y1, x1 + sizex, rect->ymax);
immUniformColor4f(0.f, 0.f, 0.f, 1.f);
imm_draw_line_box(position, x1, y1, x1 + sizex, rect->ymax);
/* layer: box outline */
glEnable(GL_BLEND);
glColor4f(0.0f, 0.0f, 0.0f, 0.5f);
fdrawline(x1, y1, x1 + sizex, y1);
glColor4f(1.0f, 1.0f, 1.0f, 0.25f);
fdrawline(x1, y1 - 1, x1 + sizex, y1 - 1);
immUniformColor4f(0.f, 0.f, 0.f, 0.5f);
imm_draw_line(position, x1, y1, x1 + sizex, y1);
immUniformColor4f(1.f, 1.f, 1.f, 0.25f);
imm_draw_line(position, x1, y1 - 1, x1 + sizex, y1 - 1);
glDisable(GL_BLEND);
/* layer: draw handles */
for (int a = 0; a < coba->tot; a++, cbd++) {
if (a != coba->cur) {
float pos = x1 + cbd->pos * (sizex - 1) + 1;
ui_draw_colorband_handle(rect, pos, &cbd->r, display, false);
ui_draw_colorband_handle(position, rect, pos, &cbd->r, display, false);
}
}
@ -1260,85 +1274,129 @@ void ui_draw_but_COLORBAND(uiBut *but, uiWidgetColors *UNUSED(wcol), const rcti
if (coba->tot != 0) {
cbd = &coba->data[coba->cur];
float pos = x1 + cbd->pos * (sizex - 1) + 1;
ui_draw_colorband_handle(rect, pos, &cbd->r, display, true);
ui_draw_colorband_handle(position, rect, pos, &cbd->r, display, true);
}
immUnbindProgram();
}
#define SPHERE_LAT_RES 24
#define SPHERE_LON_RES 32
static float sphere_coords[SPHERE_LON_RES][SPHERE_LAT_RES][3] = {{{2.0f}}};
static void ui_draw_lat_lon_vert(unsigned int pos, unsigned int nor, float radius, int lat, int lon)
{
const float x = sphere_coords[lon][lat][0];
const float y = sphere_coords[lon][lat][1];
const float z = sphere_coords[lon][lat][2];
immAttrib3f(nor, x, y, z);
immVertex3f(pos, x * radius, y * radius, z * radius);
}
static void ui_draw_unitvec_sphere(unsigned int pos, unsigned int nor, float radius)
{
const float lon_inc = 2 * M_PI / SPHERE_LON_RES;
const float lat_inc = M_PI / SPHERE_LAT_RES;
float lon, lat;
/* TODO put that in a batch */
/* Init coords only once */
if (sphere_coords[0][0][0] == 2.0f) {
lon = 0.0f;
for(int i = 0; i < SPHERE_LON_RES; i++, lon += lon_inc) {
lat = 0.0f;
for(int j = 0; j < SPHERE_LAT_RES; j++, lat += lat_inc) {
sphere_coords[i][j][0] = sinf(lat) * cosf(lon);
sphere_coords[i][j][1] = cosf(lat);
sphere_coords[i][j][2] = sinf(lat) * sinf(lon);
}
}
}
immBegin(GL_TRIANGLES, (SPHERE_LAT_RES-1) * SPHERE_LON_RES * 6);
for(int i = 0; i < SPHERE_LON_RES; i++) {
for(int j = 0; j < SPHERE_LAT_RES; j++) {
if (j != SPHERE_LAT_RES - 1) { /* Pole */
ui_draw_lat_lon_vert(pos, nor, radius, j, i);
ui_draw_lat_lon_vert(pos, nor, radius, j+1, i);
ui_draw_lat_lon_vert(pos, nor, radius, j+1, i+1);
}
if (j != 0) { /* Pole */
ui_draw_lat_lon_vert(pos, nor, radius, j, i);
ui_draw_lat_lon_vert(pos, nor, radius, j+1, i+1);
ui_draw_lat_lon_vert(pos, nor, radius, j, i+1);
}
}
}
immEnd();
}
#undef SPHERE_LAT_RES
#undef SPHERE_LON_RES
void ui_draw_but_UNITVEC(uiBut *but, uiWidgetColors *wcol, const rcti *rect)
{
static GLuint displist = 0;
/* sphere color */
float diffuse[3] = {1.0f, 1.0f, 1.0f};
float light[3];
float size;
/* backdrop */
UI_draw_roundbox_corner_set(UI_CNR_ALL);
UI_draw_roundbox_gl_mode_3ubAlpha(GL_TRIANGLE_FAN, rect->xmin, rect->ymin, rect->xmax, rect->ymax, 5.0f, (unsigned char *)wcol->inner, 255);
/* sphere color */
glCullFace(GL_BACK);
glEnable(GL_CULL_FACE);
/* setup lights */
GPULightData light = {0};
light.type = GPU_LIGHT_SUN;
copy_v3_v3(light.diffuse, diffuse);
zero_v3(light.specular);
ui_but_v3_get(but, light.direction);
ui_but_v3_get(but, light);
light[2] = -light[2];
GPU_basic_shader_light_set(0, &light);
for (int a = 1; a < 8; a++)
GPU_basic_shader_light_set(a, NULL);
/* setup shader */
GPU_basic_shader_colors(diffuse, NULL, 0, 1.0f);
GPU_basic_shader_bind(GPU_SHADER_LIGHTING);
VertexFormat *format = immVertexFormat();
unsigned int pos = add_attrib(format, "pos", GL_FLOAT, 3, KEEP_FLOAT);
unsigned int nor = add_attrib(format, "nor", GL_FLOAT, 3, KEEP_FLOAT);
immBindBuiltinProgram(GPU_SHADER_SIMPLE_LIGHTING);
immUniformColor3fv(diffuse);
immUniform3fv("light", light);
/* transform to button */
glPushMatrix();
glTranslatef(rect->xmin + 0.5f * BLI_rcti_size_x(rect), rect->ymin + 0.5f * BLI_rcti_size_y(rect), 0.0f);
gpuMatrixBegin3D_legacy();
gpuPushMatrix();
if (BLI_rcti_size_x(rect) < BLI_rcti_size_y(rect))
size = BLI_rcti_size_x(rect) / 200.f;
else
size = BLI_rcti_size_y(rect) / 200.f;
glScalef(size, size, MIN2(size, 1.0f));
gpuTranslate3f(rect->xmin + 0.5f * BLI_rcti_size_x(rect), rect->ymin + 0.5f * BLI_rcti_size_y(rect), 0.0f);
gpuScale3f(size, size, MIN2(size, 1.0f));
if (displist == 0) {
GLUquadricObj *qobj;
displist = glGenLists(1);
glNewList(displist, GL_COMPILE);
qobj = gluNewQuadric();
gluQuadricDrawStyle(qobj, GLU_FILL);
GPU_basic_shader_bind(GPU_basic_shader_bound_options());
gluSphere(qobj, 100.0, 32, 24);
gluDeleteQuadric(qobj);
glEndList();
}
glCallList(displist);
ui_draw_unitvec_sphere(pos, nor, 100.0);
immUnbindProgram();
/* restore */
GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
GPU_default_lights();
glDisable(GL_CULL_FACE);
/* AA circle */
format = immVertexFormat();
pos = add_attrib(format, "pos", GL_FLOAT, 2, KEEP_FLOAT);
immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
immUniformColor3ubv((unsigned char *)wcol->inner);
glEnable(GL_BLEND);
glEnable(GL_LINE_SMOOTH);
glColor3ubv((unsigned char *)wcol->inner);
glutil_draw_lined_arc(0.0f, M_PI * 2.0, 100.0f, 32);
imm_draw_lined_circle(pos, 0.0f, 0.0f, 100.0f, 32);
glDisable(GL_BLEND);
glDisable(GL_LINE_SMOOTH);
/* matrix after circle */
glPopMatrix();
gpuPopMatrix();
gpuMatrixEnd();
/* We disabled all blender lights above, so restore them here. */
GPU_default_lights();
immUnbindProgram();
}
static void ui_draw_but_curve_grid(const rcti *rect, float zoomx, float zoomy, float offsx, float offsy, float step)

View File

@ -133,6 +133,8 @@ set(SRC
data_to_c_simple(shaders/gpu_shader_depth_only_frag.glsl SRC)
data_to_c_simple(shaders/gpu_shader_uniform_color_frag.glsl SRC)
data_to_c_simple(shaders/gpu_shader_checker_frag.glsl SRC)
data_to_c_simple(shaders/gpu_shader_simple_lighting_frag.glsl SRC)
data_to_c_simple(shaders/gpu_shader_flat_color_frag.glsl SRC)
data_to_c_simple(shaders/gpu_shader_flat_color_alpha_test_0_frag.glsl SRC)
data_to_c_simple(shaders/gpu_shader_2D_vert.glsl SRC)

View File

@ -101,11 +101,13 @@ typedef enum GPUBuiltinShader {
GPU_SHADER_EDGES_FRONT_BACK_ORTHO,
GPU_SHADER_EDGES_OVERLAY_SIMPLE,
GPU_SHADER_EDGES_OVERLAY,
GPU_SHADER_SIMPLE_LIGHTING,
/* for simple 2D drawing */
GPU_SHADER_2D_UNIFORM_COLOR,
GPU_SHADER_2D_FLAT_COLOR,
GPU_SHADER_2D_SMOOTH_COLOR,
GPU_SHADER_2D_IMAGE_COLOR,
GPU_SHADER_2D_CHECKER,
/* for simple 3D drawing */
GPU_SHADER_3D_UNIFORM_COLOR,
GPU_SHADER_3D_UNIFORM_COLOR_INSTANCE,

View File

@ -750,7 +750,7 @@ void immUniform2fv(const char* name, const float data[2])
}
void immUniform3f(const char* name, float x, float y, float z)
{
{
int loc = glGetUniformLocation(imm.bound_program, name);
#if TRUST_NO_ONE
@ -758,10 +758,10 @@ void immUniform3f(const char* name, float x, float y, float z)
#endif
glUniform3f(loc, x, y, z);
}
}
void immUniform3fv(const char* name, const float data[3])
{
{
int loc = glGetUniformLocation(imm.bound_program, name);
#if TRUST_NO_ONE
@ -769,7 +769,7 @@ void immUniform3fv(const char* name, const float data[3])
#endif
glUniform3fv(loc, 1, data);
}
}
void immUniform4f(const char* name, float x, float y, float z, float w)
{

View File

@ -49,6 +49,8 @@
/* Non-generated shaders */
extern char datatoc_gpu_shader_depth_only_frag_glsl[];
extern char datatoc_gpu_shader_uniform_color_frag_glsl[];
extern char datatoc_gpu_shader_checker_frag_glsl[];
extern char datatoc_gpu_shader_simple_lighting_frag_glsl[];
extern char datatoc_gpu_shader_flat_color_frag_glsl[];
extern char datatoc_gpu_shader_flat_color_alpha_test_0_frag_glsl[];
extern char datatoc_gpu_shader_2D_vert_glsl[];
@ -655,6 +657,7 @@ GPUShader *GPU_shader_get_builtin_shader(GPUBuiltinShader shader)
[GPU_SHADER_EDGES_OVERLAY] = { datatoc_gpu_shader_edges_overlay_vert_glsl,
datatoc_gpu_shader_edges_overlay_frag_glsl,
datatoc_gpu_shader_edges_overlay_geom_glsl },
[GPU_SHADER_SIMPLE_LIGHTING] = { datatoc_gpu_shader_3D_vert_glsl, datatoc_gpu_shader_simple_lighting_frag_glsl },
[GPU_SHADER_2D_IMAGE_MASK_UNIFORM_COLOR] = { datatoc_gpu_shader_3D_image_vert_glsl,
datatoc_gpu_shader_image_mask_uniform_color_frag_glsl },
@ -667,6 +670,7 @@ GPUShader *GPU_shader_get_builtin_shader(GPUBuiltinShader shader)
[GPU_SHADER_2D_IMAGE_INTERLACE] = { datatoc_gpu_shader_2D_image_vert_glsl,
datatoc_gpu_shader_image_interlace_frag_glsl },
[GPU_SHADER_2D_CHECKER] = { datatoc_gpu_shader_2D_vert_glsl, datatoc_gpu_shader_checker_frag_glsl },
[GPU_SHADER_2D_UNIFORM_COLOR] = { datatoc_gpu_shader_2D_vert_glsl, datatoc_gpu_shader_uniform_color_frag_glsl },
[GPU_SHADER_2D_FLAT_COLOR] = { datatoc_gpu_shader_2D_flat_color_vert_glsl,
@ -724,7 +728,8 @@ GPUShader *GPU_shader_get_builtin_shader(GPUBuiltinShader shader)
if (builtin_shaders[shader] == NULL) {
/* just a few special cases */
const char *defines = (shader == GPU_SHADER_SMOKE_COBA) ? "#define USE_COBA;\n" : NULL;
const char *defines = (shader == GPU_SHADER_SMOKE_COBA) ? "#define USE_COBA;\n" :
(shader == GPU_SHADER_SIMPLE_LIGHTING) ? "#define USE_NORMALS;\n" : NULL;
const GPUShaderStages *stages = builtin_shader_stages + shader;
@ -736,6 +741,14 @@ GPUShader *GPU_shader_get_builtin_shader(GPUBuiltinShader shader)
stages = &legacy_fancy_edges;
}
if (shader == GPU_SHADER_EDGES_FRONT_BACK_PERSP && !GLEW_VERSION_3_2) {
/* TODO: remove after switch to core profile (maybe) */
static const GPUShaderStages legacy_fancy_edges =
{ datatoc_gpu_shader_edges_front_back_persp_legacy_vert_glsl,
datatoc_gpu_shader_flat_color_alpha_test_0_frag_glsl };
stages = &legacy_fancy_edges;
}
/* common case */
builtin_shaders[shader] = GPU_shader_create(stages->vert, stages->frag, stages->geom,
NULL, defines, 0, 0, 0);

View File

@ -1,13 +1,27 @@
uniform mat4 ModelViewProjectionMatrix;
#ifdef USE_NORMALS
uniform mat3 NormalMatrix;
#endif
#if __VERSION__ == 120
attribute vec3 pos;
#ifdef USE_NORMALS
attribute vec3 nor;
varying vec3 normal;
#endif
#else
in vec3 pos;
#ifdef USE_NORMALS
in vec3 nor;
out vec3 normal;
#endif
#endif
void main()
{
#ifdef USE_NORMALS
normal = normalize(NormalMatrix * nor);
#endif
gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
}

View File

@ -0,0 +1,24 @@
uniform vec4 color1;
uniform vec4 color2;
uniform int size;
#if __VERSION__ == 120
#define fragColor gl_FragColor
#else
out vec4 fragColor;
#endif
void main()
{
vec2 phase = mod(gl_FragCoord.xy, (size*2));
if ((phase.x > size && phase.y < size) ||
(phase.x < size && phase.y > size))
{
fragColor = color1;
}
else {
fragColor = color2;
}
}

View File

@ -0,0 +1,16 @@
uniform vec4 color;
uniform vec3 light;
#if __VERSION__ == 120
varying vec3 normal;
#define fragColor gl_FragColor
#else
in vec3 normal;
out vec4 fragColor;
#endif
void main()
{
fragColor = color * max(0.0, dot(normalize(normal), light));
}