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:
authorJeroen Bakker <j.bakker@atmind.nl>2018-05-11 17:55:14 +0300
committerJeroen Bakker <j.bakker@atmind.nl>2018-05-11 18:02:13 +0300
commitd3c4248946f65d287f18b3d6488cd450dfb6d81d (patch)
tree47ed70266631c5e40cf221031d84315d85f27983 /source/blender/draw
parent68b736ce248fbfc6eacfa2fed4f677523087accb (diff)
Workbench: StudioLight HDRI's
The Studio lights are now loaded from disk. The location is `datafiles/studiolights` they need to be JPG for now. JPG cannot store HDRI color range but they are clamped inside the Workbench engine for speed reason. I didn't select JP2K as it might not be enabled. Users can add upto 20 HDRI files. This limitation is inside the RNA_space.c Currently the icons are calculated when you first open the selection box for the HDRI's. We could add them to a background rendering later. I added 2 test files a sky texture rendered in Cycles and an HDRI from cloud.blender.org.
Diffstat (limited to 'source/blender/draw')
-rw-r--r--source/blender/draw/DRW_engine.h1
-rw-r--r--source/blender/draw/engines/workbench/workbench_materials.c5
-rw-r--r--source/blender/draw/engines/workbench/workbench_private.h5
-rw-r--r--source/blender/draw/engines/workbench/workbench_studiolight.c117
4 files changed, 17 insertions, 111 deletions
diff --git a/source/blender/draw/DRW_engine.h b/source/blender/draw/DRW_engine.h
index a1a2a36e75a..524a94e5886 100644
--- a/source/blender/draw/DRW_engine.h
+++ b/source/blender/draw/DRW_engine.h
@@ -135,5 +135,4 @@ void DRW_opengl_context_disable(void);
void DRW_deferred_shader_remove(struct GPUMaterial *mat);
-uint *WORKBENCH_generate_studiolight_preview(int studiolight_id, int icon_size);
#endif /* __DRW_ENGINE_H__ */
diff --git a/source/blender/draw/engines/workbench/workbench_materials.c b/source/blender/draw/engines/workbench/workbench_materials.c
index 0fee42619c3..680ac264233 100644
--- a/source/blender/draw/engines/workbench/workbench_materials.c
+++ b/source/blender/draw/engines/workbench/workbench_materials.c
@@ -338,6 +338,7 @@ void workbench_materials_cache_init(WORKBENCH_Data *vedata)
if (v3d) {
wpd->shading = v3d->shading;
wpd->drawtype = v3d->drawtype;
+ wpd->studio_light = BKE_studiolight_find(wpd->shading.studio_light);
}
else {
/* XXX: We should get the default shading from the view layer, after we implemented the render callback */
@@ -346,7 +347,9 @@ void workbench_materials_cache_init(WORKBENCH_Data *vedata)
wpd->shading.shadow_intensity = 0.5;
copy_v3_fl(wpd->shading.single_color, 0.8f);
wpd->drawtype = OB_SOLID;
+ wpd->studio_light = BKE_studiolight_findindex(0);
}
+ BKE_studiolight_ensure_flag(wpd->studio_light, STUDIOLIGHT_DIFFUSE_LIGHT_CALCULATED);
select_deferred_shaders(wpd);
/* Deferred Mix Pass */
@@ -360,7 +363,7 @@ void workbench_materials_cache_init(WORKBENCH_Data *vedata)
srgb_to_linearrgb_v3_v3(wd->background_color_high, wd->background_color_high);
srgb_to_linearrgb_v3_v3(wd->background_color_low, wd->background_color_low);
- studiolight_update_world(wpd->shading.studio_light, wd);
+ studiolight_update_world(wpd->studio_light, wd);
wpd->world_ubo = DRW_uniformbuffer_create(sizeof(WORKBENCH_UBO_World), NULL);
DRW_uniformbuffer_update(wpd->world_ubo, &wpd->world_data);
diff --git a/source/blender/draw/engines/workbench/workbench_private.h b/source/blender/draw/engines/workbench/workbench_private.h
index 7a646d056b5..dde62302f62 100644
--- a/source/blender/draw/engines/workbench/workbench_private.h
+++ b/source/blender/draw/engines/workbench/workbench_private.h
@@ -27,6 +27,8 @@
#define __WORKBENCH_PRIVATE_H__
+#include "BKE_studiolight.h"
+
#include "DNA_image_types.h"
#include "DNA_view3d_types.h"
@@ -81,6 +83,7 @@ typedef struct WORKBENCH_PrivateData {
struct GPUShader *prepass_texture_sh;
struct GPUShader *composite_sh;
View3DShading shading;
+ StudioLight *studio_light;
int drawtype;
struct GPUUniformBuffer *world_ubo;
struct DRWShadingGroup *shadow_shgrp;
@@ -127,6 +130,6 @@ void workbench_materials_solid_cache_populate(WORKBENCH_Data *vedata, Object *ob
void workbench_materials_cache_finish(WORKBENCH_Data *vedata);
/* workbench_studiolight.c */
-void studiolight_update_world(int studio_light, WORKBENCH_UBO_World *wd);
+void studiolight_update_world(StudioLight *sl, WORKBENCH_UBO_World *wd);
#endif
diff --git a/source/blender/draw/engines/workbench/workbench_studiolight.c b/source/blender/draw/engines/workbench/workbench_studiolight.c
index 5b1d4432ca7..f7d107ea403 100644
--- a/source/blender/draw/engines/workbench/workbench_studiolight.c
+++ b/source/blender/draw/engines/workbench/workbench_studiolight.c
@@ -22,118 +22,19 @@
/** \file workbench_studiolight.c
* \ingroup draw_engine
*/
+#include "BKE_studiolight.h"
+
#include "DRW_engine.h"
#include "workbench_private.h"
#include "BLI_math.h"
-
-#define STUDIOLIGHT_X_POS 0
-#define STUDIOLIGHT_X_NEG 1
-#define STUDIOLIGHT_Y_POS 2
-#define STUDIOLIGHT_Y_NEG 3
-#define STUDIOLIGHT_Z_POS 4
-#define STUDIOLIGHT_Z_NEG 5
-
-const float studiolights[][6][3] = {
- {
- {1.0, 0.8, 0.6},
- {1.0, 0.6, 0.6},
- {0.9, 0.9, 1.0},
- {0.05, 0.025, 0.025},
- {0.8, 0.8, 0.75},
- {1.0, 0.95, 0.8},
- },
- {
- {0.0, 0.0, 0.0},
- {0.0, 0.0, 0.0},
- {0.0, 0.0, 0.0},
- {0.0, 0.0, 0.0},
- {0.8, 0.8, 1.0},
- {0.0, 0.0, 0.0},
- },
- {
- {0.4, 0.3, 0.8},
- {0.4, 0.3, 0.8},
- {0.8, 0.8, 0.2},
- {0.0, 0.0, 0.0},
- {0.4, 0.4, 0.8},
- {0.0, 0.0, 0.0},
- },
- {
- {0.2, 0.2, 0.0},
- {0.8, 0.2, 0.0},
- {0.8, 0.2, 0.0},
- {0.2, 0.2, 0.0},
- {0.8, 0.6, 0.4},
- {0.0, 0.0, 0.0},
- },
- {
- {0.8, 0.2, 0.0},
- {0.8, 0.2, 0.0},
- {0.8, 0.6, 0.0},
- {0.2, 0.2, 0.0},
- {1.0, 0.5, 0.0},
- {0.0, 0.0, 0.0},
- },
-};
-
-void studiolight_update_world(int studio_light, WORKBENCH_UBO_World *wd)
-{
- copy_v3_v3(wd->diffuse_light_x_pos, studiolights[studio_light][STUDIOLIGHT_X_POS]);
- copy_v3_v3(wd->diffuse_light_x_neg, studiolights[studio_light][STUDIOLIGHT_X_NEG]);
- copy_v3_v3(wd->diffuse_light_y_pos, studiolights[studio_light][STUDIOLIGHT_Y_POS]);
- copy_v3_v3(wd->diffuse_light_y_neg, studiolights[studio_light][STUDIOLIGHT_Y_NEG]);
- copy_v3_v3(wd->diffuse_light_z_pos, studiolights[studio_light][STUDIOLIGHT_Z_POS]);
- copy_v3_v3(wd->diffuse_light_z_neg, studiolights[studio_light][STUDIOLIGHT_Z_NEG]);
-}
-
-uint *WORKBENCH_generate_studiolight_preview(int studiolight_id, int icon_size)
+void studiolight_update_world(StudioLight *sl, WORKBENCH_UBO_World *wd)
{
- uint *rect = MEM_mallocN(icon_size * icon_size * sizeof(uint), __func__);
- int icon_center = icon_size / 2;
- float sphere_radius = icon_center * 0.9;
-
- int offset = 0;
- for (int y = 0; y < icon_size; y++) {
- float dy = y - icon_center;
- for (int x = 0; x < icon_size; x++) {
- float dx = x - icon_center;
- /* calculate aliasing */
- float alias = 0;
- const float alias_step = 0.2;
- for (float ay = dy - 0.5; ay < dy + 0.5; ay += alias_step) {
- for (float ax = dx - 0.5; ax < dx + 0.5; ax += alias_step) {
- if (sqrt(ay * ay + ax * ax) < sphere_radius) {
- alias += alias_step * alias_step;
- }
- }
- }
- uint pixelresult = 0x0;
- uint alias_i = clamp_i(alias * 256, 0, 255);
- if (alias_i != 0) {
- /* calculate normal */
- uint alias_mask = alias_i << 24;
- float normal[3];
- normal[0] = dx / sphere_radius;
- normal[1] = dy / sphere_radius;
- normal[2] = sqrt(-(normal[0] * normal[0]) - (normal[1] * normal[1]) + 1);
- normalize_v3(normal);
-
- float color[3];
- mul_v3_v3fl(color, studiolights[studiolight_id][STUDIOLIGHT_X_POS], clamp_f(normal[0], 0.0, 1.0));
- interp_v3_v3v3(color, color, studiolights[studiolight_id][STUDIOLIGHT_X_NEG], clamp_f(-normal[0], 0.0, 1.0));
- interp_v3_v3v3(color, color, studiolights[studiolight_id][STUDIOLIGHT_Y_POS], clamp_f(normal[1], 0.0, 1.0));
- interp_v3_v3v3(color, color, studiolights[studiolight_id][STUDIOLIGHT_Y_NEG], clamp_f(-normal[1], 0.0, 1.0));
- interp_v3_v3v3(color, color, studiolights[studiolight_id][STUDIOLIGHT_Z_POS], clamp_f(normal[2], 0.0, 1.0));
-
- pixelresult = rgb_to_cpack(
- linearrgb_to_srgb(color[0]),
- linearrgb_to_srgb(color[1]),
- linearrgb_to_srgb(color[2])) | alias_mask;
- }
- rect[offset++] = pixelresult;
- }
- }
- return rect;
+ copy_v3_v3(wd->diffuse_light_x_pos, sl->diffuse_light[STUDIOLIGHT_X_POS]);
+ copy_v3_v3(wd->diffuse_light_x_neg, sl->diffuse_light[STUDIOLIGHT_X_NEG]);
+ copy_v3_v3(wd->diffuse_light_y_pos, sl->diffuse_light[STUDIOLIGHT_Y_POS]);
+ copy_v3_v3(wd->diffuse_light_y_neg, sl->diffuse_light[STUDIOLIGHT_Y_NEG]);
+ copy_v3_v3(wd->diffuse_light_z_pos, sl->diffuse_light[STUDIOLIGHT_Z_POS]);
+ copy_v3_v3(wd->diffuse_light_z_neg, sl->diffuse_light[STUDIOLIGHT_Z_NEG]);
}