Changeset View
Changeset View
Standalone View
Standalone View
source/blender/gpu/intern/gpu_basic_shader.c
| Show First 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | |||||
| * - Optimize for case where no texture matrix is used. | * - Optimize for case where no texture matrix is used. | ||||
| */ | */ | ||||
| #include "BLI_math.h" | #include "BLI_math.h" | ||||
| #include "BLI_utildefines.h" | #include "BLI_utildefines.h" | ||||
| #include "GPU_basic_shader.h" | #include "GPU_basic_shader.h" | ||||
| #include "GPU_glew.h" | #include "GPU_glew.h" | ||||
| #include "GPU_legacy_stubs.h" | |||||
| #include "GPU_shader.h" | #include "GPU_shader.h" | ||||
| /* State */ | /* State */ | ||||
| static struct { | static struct { | ||||
| GPUShader *cached_shaders[GPU_SHADER_OPTION_COMBINATIONS]; | GPUShader *cached_shaders[GPU_SHADER_OPTION_COMBINATIONS]; | ||||
| bool failed_shaders[GPU_SHADER_OPTION_COMBINATIONS]; | bool failed_shaders[GPU_SHADER_OPTION_COMBINATIONS]; | ||||
| ▲ Show 20 Lines • Show All 283 Lines • ▼ Show 20 Lines | void GPU_basic_shader_colors( | ||||
| gl_diffuse[3] = alpha; | gl_diffuse[3] = alpha; | ||||
| if (specular) | if (specular) | ||||
| copy_v3_v3(gl_specular, specular); | copy_v3_v3(gl_specular, specular); | ||||
| else | else | ||||
| zero_v3(gl_specular); | zero_v3(gl_specular); | ||||
| gl_specular[3] = 1.0f; | gl_specular[3] = 1.0f; | ||||
| glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, gl_diffuse); | oldMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, gl_diffuse); | ||||
| glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, gl_specular); | oldMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, gl_specular); | ||||
| glMateriali(GL_FRONT_AND_BACK, GL_SHININESS, CLAMPIS(shininess, 1, 128)); | oldMateriali(GL_FRONT_AND_BACK, GL_SHININESS, CLAMPIS(shininess, 1, 128)); | ||||
| } | } | ||||
| void GPU_basic_shader_light_set(int light_num, GPULightData *light) | void GPU_basic_shader_light_set(int light_num, GPULightData *light) | ||||
| { | { | ||||
| int light_bit = (1 << light_num); | int light_bit = (1 << light_num); | ||||
| /* note that light position is affected by the current modelview matrix! */ | /* note that light position is affected by the current modelview matrix! */ | ||||
| Show All 9 Lines | if (light) { | ||||
| if (light->type == GPU_LIGHT_SUN) { | if (light->type == GPU_LIGHT_SUN) { | ||||
| copy_v3_v3(position, light->direction); | copy_v3_v3(position, light->direction); | ||||
| position[3] = 0.0f; | position[3] = 0.0f; | ||||
| } | } | ||||
| else { | else { | ||||
| copy_v3_v3(position, light->position); | copy_v3_v3(position, light->position); | ||||
| position[3] = 1.0f; | position[3] = 1.0f; | ||||
| } | } | ||||
| glLightfv(GL_LIGHT0 + light_num, GL_POSITION, position); | oldLightfv(GL_LIGHT0 + light_num, GL_POSITION, position); | ||||
| /* energy */ | /* energy */ | ||||
| copy_v3_v3(diffuse, light->diffuse); | copy_v3_v3(diffuse, light->diffuse); | ||||
| copy_v3_v3(specular, light->specular); | copy_v3_v3(specular, light->specular); | ||||
| diffuse[3] = 1.0f; | diffuse[3] = 1.0f; | ||||
| specular[3] = 1.0f; | specular[3] = 1.0f; | ||||
| glLightfv(GL_LIGHT0 + light_num, GL_DIFFUSE, diffuse); | oldLightfv(GL_LIGHT0 + light_num, GL_DIFFUSE, diffuse); | ||||
| glLightfv(GL_LIGHT0 + light_num, GL_SPECULAR, specular); | oldLightfv(GL_LIGHT0 + light_num, GL_SPECULAR, specular); | ||||
| /* attenuation */ | /* attenuation */ | ||||
| if (light->type == GPU_LIGHT_SUN) { | if (light->type == GPU_LIGHT_SUN) { | ||||
| glLightf(GL_LIGHT0 + light_num, GL_CONSTANT_ATTENUATION, 1.0f); | oldLightf(GL_LIGHT0 + light_num, GL_CONSTANT_ATTENUATION, 1.0f); | ||||
| glLightf(GL_LIGHT0 + light_num, GL_LINEAR_ATTENUATION, 0.0f); | oldLightf(GL_LIGHT0 + light_num, GL_LINEAR_ATTENUATION, 0.0f); | ||||
| glLightf(GL_LIGHT0 + light_num, GL_QUADRATIC_ATTENUATION, 0.0f); | oldLightf(GL_LIGHT0 + light_num, GL_QUADRATIC_ATTENUATION, 0.0f); | ||||
| } | } | ||||
| else { | else { | ||||
| glLightf(GL_LIGHT0 + light_num, GL_CONSTANT_ATTENUATION, light->constant_attenuation); | oldLightf(GL_LIGHT0 + light_num, GL_CONSTANT_ATTENUATION, light->constant_attenuation); | ||||
| glLightf(GL_LIGHT0 + light_num, GL_LINEAR_ATTENUATION, light->linear_attenuation); | oldLightf(GL_LIGHT0 + light_num, GL_LINEAR_ATTENUATION, light->linear_attenuation); | ||||
| glLightf(GL_LIGHT0 + light_num, GL_QUADRATIC_ATTENUATION, light->quadratic_attenuation); | oldLightf(GL_LIGHT0 + light_num, GL_QUADRATIC_ATTENUATION, light->quadratic_attenuation); | ||||
| } | } | ||||
| /* spot */ | /* spot */ | ||||
| glLightfv(GL_LIGHT0 + light_num, GL_SPOT_DIRECTION, light->direction); | oldLightfv(GL_LIGHT0 + light_num, GL_SPOT_DIRECTION, light->direction); | ||||
| if (light->type == GPU_LIGHT_SPOT) { | if (light->type == GPU_LIGHT_SPOT) { | ||||
| glLightf(GL_LIGHT0 + light_num, GL_SPOT_CUTOFF, light->spot_cutoff); | oldLightf(GL_LIGHT0 + light_num, GL_SPOT_CUTOFF, light->spot_cutoff); | ||||
| glLightf(GL_LIGHT0 + light_num, GL_SPOT_EXPONENT, light->spot_exponent); | oldLightf(GL_LIGHT0 + light_num, GL_SPOT_EXPONENT, light->spot_exponent); | ||||
| } | } | ||||
| else { | else { | ||||
| glLightf(GL_LIGHT0 + light_num, GL_SPOT_CUTOFF, 180.0f); | oldLightf(GL_LIGHT0 + light_num, GL_SPOT_CUTOFF, 180.0f); | ||||
| glLightf(GL_LIGHT0 + light_num, GL_SPOT_EXPONENT, 0.0f); | oldLightf(GL_LIGHT0 + light_num, GL_SPOT_EXPONENT, 0.0f); | ||||
| } | } | ||||
| GPU_MATERIAL_STATE.lights_enabled |= light_bit; | GPU_MATERIAL_STATE.lights_enabled |= light_bit; | ||||
| if (position[3] == 0.0f) | if (position[3] == 0.0f) | ||||
| GPU_MATERIAL_STATE.lights_directional |= light_bit; | GPU_MATERIAL_STATE.lights_directional |= light_bit; | ||||
| } | } | ||||
| else { | else { | ||||
| /* TODO(sergey): Needs revisit. */ | /* TODO(sergey): Needs revisit. */ | ||||
| /* glsl shader needs these zero to skip them */ | /* glsl shader needs these zero to skip them */ | ||||
| const float zero[4] = {0.0f, 0.0f, 0.0f, 0.0f}; | const float zero[4] = {0.0f, 0.0f, 0.0f, 0.0f}; | ||||
| glLightfv(GL_LIGHT0 + light_num, GL_POSITION, zero); | oldLightfv(GL_LIGHT0 + light_num, GL_POSITION, zero); | ||||
| glLightfv(GL_LIGHT0 + light_num, GL_DIFFUSE, zero); | oldLightfv(GL_LIGHT0 + light_num, GL_DIFFUSE, zero); | ||||
| glLightfv(GL_LIGHT0 + light_num, GL_SPECULAR, zero); | oldLightfv(GL_LIGHT0 + light_num, GL_SPECULAR, zero); | ||||
| glDisable(GL_LIGHT0 + light_num); | glDisable(GL_LIGHT0 + light_num); | ||||
| } | } | ||||
| } | } | ||||
| void GPU_basic_shader_light_set_viewer(bool local) | void GPU_basic_shader_light_set_viewer(bool local) | ||||
| { | { | ||||
| glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, (local) ? GL_TRUE: GL_FALSE); | glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, (local) ? GL_TRUE: GL_FALSE); | ||||
| Show All 20 Lines | |||||