2018-04-13 15:49:50 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright 2016, Blender Foundation.
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
*
|
|
|
|
|
* Contributor(s): Blender Institute
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/** \file workbench_private.h
|
|
|
|
|
* \ingroup draw_engine
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef __WORKBENCH_PRIVATE_H__
|
|
|
|
|
#define __WORKBENCH_PRIVATE_H__
|
|
|
|
|
|
|
|
|
|
|
2018-05-11 16:55:14 +02:00
|
|
|
#include "BKE_studiolight.h"
|
|
|
|
|
|
2018-05-07 14:59:27 +02:00
|
|
|
#include "DNA_image_types.h"
|
2018-04-19 09:45:52 +02:00
|
|
|
#include "DNA_view3d_types.h"
|
2018-04-13 15:49:50 +02:00
|
|
|
|
2018-05-07 14:59:27 +02:00
|
|
|
#include "DRW_render.h"
|
|
|
|
|
|
|
|
|
|
|
2018-04-17 16:34:41 +02:00
|
|
|
#define WORKBENCH_ENGINE "BLENDER_WORKBENCH"
|
2018-04-25 10:59:48 +02:00
|
|
|
#define M_GOLDEN_RATION_CONJUGATE 0.618033988749895
|
2018-05-22 14:12:47 +02:00
|
|
|
#define MAX_SHADERS 255
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define OBJECT_ID_PASS_ENABLED(wpd) (wpd->shading.flag & V3D_SHADING_OBJECT_OUTLINE)
|
|
|
|
|
#define SHADOW_ENABLED(wpd) (wpd->shading.flag & V3D_SHADING_SHADOW)
|
|
|
|
|
#define NORMAL_VIEWPORT_PASS_ENABLED(wpd) (wpd->shading.light & V3D_LIGHTING_STUDIO || SHADOW_ENABLED(wpd))
|
|
|
|
|
#define NORMAL_ENCODING_ENABLED() (true)
|
2018-05-24 09:06:29 +02:00
|
|
|
#define WORKBENCH_REVEALAGE_ENABLED
|
2018-05-22 14:12:47 +02:00
|
|
|
#define STUDIOLIGHT_ORIENTATION_WORLD_ENABLED(wpd) (wpd->studio_light->flag & STUDIOLIGHT_ORIENTATION_WORLD)
|
2018-04-17 16:34:41 +02:00
|
|
|
|
2018-05-07 14:59:27 +02:00
|
|
|
|
2018-04-25 10:59:48 +02:00
|
|
|
typedef struct WORKBENCH_FramebufferList {
|
2018-05-22 14:12:47 +02:00
|
|
|
/* Deferred render buffers */
|
2018-04-25 10:59:48 +02:00
|
|
|
struct GPUFrameBuffer *prepass_fb;
|
2018-05-04 16:26:31 +02:00
|
|
|
struct GPUFrameBuffer *composite_fb;
|
2018-05-22 14:12:47 +02:00
|
|
|
|
|
|
|
|
/* Forward render buffers */
|
2018-05-23 12:30:12 +02:00
|
|
|
struct GPUFrameBuffer *object_outline_fb;
|
2018-05-22 14:12:47 +02:00
|
|
|
struct GPUFrameBuffer *transparent_accum_fb;
|
2018-05-24 09:06:29 +02:00
|
|
|
|
|
|
|
|
#ifdef WORKBENCH_REVEALAGE_ENABLED
|
2018-05-23 16:35:34 +02:00
|
|
|
struct GPUFrameBuffer *transparent_revealage_fb;
|
2018-05-24 09:06:29 +02:00
|
|
|
#endif
|
2018-04-25 10:59:48 +02:00
|
|
|
} WORKBENCH_FramebufferList;
|
2018-04-13 15:49:50 +02:00
|
|
|
|
|
|
|
|
typedef struct WORKBENCH_StorageList {
|
|
|
|
|
struct WORKBENCH_PrivateData *g_data;
|
|
|
|
|
} WORKBENCH_StorageList;
|
|
|
|
|
|
|
|
|
|
typedef struct WORKBENCH_PassList {
|
2018-05-22 14:12:47 +02:00
|
|
|
/* deferred rendering */
|
2018-04-25 10:59:48 +02:00
|
|
|
struct DRWPass *prepass_pass;
|
2018-05-20 15:15:22 +02:00
|
|
|
struct DRWPass *shadow_depth_pass_pass;
|
|
|
|
|
struct DRWPass *shadow_depth_fail_pass;
|
|
|
|
|
struct DRWPass *shadow_depth_fail_caps_pass;
|
2018-04-25 10:59:48 +02:00
|
|
|
struct DRWPass *composite_pass;
|
2018-05-04 14:07:00 +02:00
|
|
|
struct DRWPass *composite_shadow_pass;
|
2018-05-22 14:12:47 +02:00
|
|
|
|
|
|
|
|
/* forward rendering */
|
|
|
|
|
struct DRWPass *transparent_accum_pass;
|
2018-05-24 09:06:29 +02:00
|
|
|
#ifdef WORKBENCH_REVEALAGE_ENABLED
|
2018-05-23 16:35:34 +02:00
|
|
|
struct DRWPass *transparent_revealage_pass;
|
2018-05-24 09:06:29 +02:00
|
|
|
#endif
|
2018-05-23 12:30:12 +02:00
|
|
|
struct DRWPass *object_outline_pass;
|
2018-05-22 14:12:47 +02:00
|
|
|
struct DRWPass *depth_pass;
|
2018-05-23 15:22:16 +02:00
|
|
|
struct DRWPass *checker_depth_pass;
|
2018-04-13 15:49:50 +02:00
|
|
|
} WORKBENCH_PassList;
|
|
|
|
|
|
|
|
|
|
typedef struct WORKBENCH_Data {
|
|
|
|
|
void *engine_type;
|
2018-04-25 10:59:48 +02:00
|
|
|
WORKBENCH_FramebufferList *fbl;
|
2018-04-18 12:11:36 +02:00
|
|
|
DRWViewportEmptyList *txl;
|
2018-04-13 15:49:50 +02:00
|
|
|
WORKBENCH_PassList *psl;
|
|
|
|
|
WORKBENCH_StorageList *stl;
|
|
|
|
|
} WORKBENCH_Data;
|
|
|
|
|
|
2018-04-25 10:59:48 +02:00
|
|
|
typedef struct WORKBENCH_UBO_World {
|
2018-04-25 15:59:15 +02:00
|
|
|
float diffuse_light_x_pos[4];
|
|
|
|
|
float diffuse_light_x_neg[4];
|
|
|
|
|
float diffuse_light_y_pos[4];
|
|
|
|
|
float diffuse_light_y_neg[4];
|
|
|
|
|
float diffuse_light_z_pos[4];
|
|
|
|
|
float diffuse_light_z_neg[4];
|
2018-04-25 10:59:48 +02:00
|
|
|
float background_color_low[4];
|
|
|
|
|
float background_color_high[4];
|
2018-05-22 14:12:47 +02:00
|
|
|
float object_outline_color[4];
|
2018-04-25 10:59:48 +02:00
|
|
|
} WORKBENCH_UBO_World;
|
|
|
|
|
BLI_STATIC_ASSERT_ALIGN(WORKBENCH_UBO_World, 16)
|
2018-04-19 12:44:37 +02:00
|
|
|
|
2018-04-25 10:59:48 +02:00
|
|
|
typedef struct WORKBENCH_PrivateData {
|
2018-04-18 13:44:33 +02:00
|
|
|
struct GHash *material_hash;
|
2018-05-07 14:59:27 +02:00
|
|
|
struct GPUShader *prepass_solid_sh;
|
|
|
|
|
struct GPUShader *prepass_texture_sh;
|
2018-04-25 10:59:48 +02:00
|
|
|
struct GPUShader *composite_sh;
|
2018-05-22 14:12:47 +02:00
|
|
|
struct GPUShader *transparent_accum_sh;
|
|
|
|
|
struct GPUShader *transparent_accum_texture_sh;
|
2018-05-05 10:45:15 +02:00
|
|
|
View3DShading shading;
|
2018-05-11 16:55:14 +02:00
|
|
|
StudioLight *studio_light;
|
2018-05-07 14:59:27 +02:00
|
|
|
int drawtype;
|
2018-04-25 10:59:48 +02:00
|
|
|
struct GPUUniformBuffer *world_ubo;
|
2018-05-04 14:07:00 +02:00
|
|
|
struct DRWShadingGroup *shadow_shgrp;
|
2018-05-23 12:30:12 +02:00
|
|
|
struct DRWShadingGroup *depth_shgrp;
|
2018-05-24 09:06:29 +02:00
|
|
|
#ifdef WORKBENCH_REVEALAGE_ENABLED
|
2018-05-23 16:35:34 +02:00
|
|
|
struct DRWShadingGroup *transparent_revealage_shgrp;
|
2018-05-26 10:41:25 +02:00
|
|
|
#endif
|
2018-04-25 10:59:48 +02:00
|
|
|
WORKBENCH_UBO_World world_data;
|
2018-05-15 15:19:57 +02:00
|
|
|
float shadow_multiplier;
|
2018-04-13 15:49:50 +02:00
|
|
|
} WORKBENCH_PrivateData; /* Transient data */
|
|
|
|
|
|
2018-04-18 13:44:33 +02:00
|
|
|
typedef struct WORKBENCH_MaterialData {
|
2018-04-18 14:56:25 +02:00
|
|
|
/* Solid color */
|
2018-05-22 14:12:47 +02:00
|
|
|
float color[4];
|
2018-04-25 10:59:48 +02:00
|
|
|
int object_id;
|
2018-05-07 14:59:27 +02:00
|
|
|
int drawtype;
|
2018-05-11 07:55:41 +02:00
|
|
|
Image *ima;
|
2018-04-22 08:44:23 +02:00
|
|
|
|
2018-04-18 14:56:25 +02:00
|
|
|
/* Linked shgroup for drawing */
|
2018-04-19 07:47:03 +02:00
|
|
|
DRWShadingGroup *shgrp;
|
2018-05-22 14:12:47 +02:00
|
|
|
/* forward rendering */
|
2018-05-23 15:22:16 +02:00
|
|
|
DRWShadingGroup *shgrp_object_outline;
|
2018-04-18 13:44:33 +02:00
|
|
|
} WORKBENCH_MaterialData;
|
2018-04-13 15:49:50 +02:00
|
|
|
|
2018-04-25 10:59:48 +02:00
|
|
|
typedef struct WORKBENCH_ObjectData {
|
|
|
|
|
struct ObjectEngineData *next, *prev;
|
|
|
|
|
struct DrawEngineType *engine_type;
|
|
|
|
|
/* Only nested data, NOT the engine data itself. */
|
|
|
|
|
ObjectEngineDataFreeCb free;
|
|
|
|
|
/* Accumulated recalc flags, which corresponds to ID->recalc flags. */
|
|
|
|
|
int recalc;
|
2018-05-19 18:53:53 +02:00
|
|
|
/* Shadow direction in local object space. */
|
|
|
|
|
float shadow_dir[3];
|
2018-04-25 10:59:48 +02:00
|
|
|
|
|
|
|
|
int object_id;
|
|
|
|
|
} WORKBENCH_ObjectData;
|
2018-04-18 13:44:33 +02:00
|
|
|
|
|
|
|
|
/* workbench_engine.c */
|
2018-04-25 10:59:48 +02:00
|
|
|
void workbench_solid_materials_init(WORKBENCH_Data *vedata);
|
2018-04-19 07:47:03 +02:00
|
|
|
void workbench_solid_materials_cache_init(WORKBENCH_Data *vedata);
|
|
|
|
|
void workbench_solid_materials_cache_populate(WORKBENCH_Data *vedata, Object *ob);
|
|
|
|
|
void workbench_solid_materials_cache_finish(WORKBENCH_Data *vedata);
|
|
|
|
|
void workbench_solid_materials_draw_scene(WORKBENCH_Data *vedata);
|
2018-04-17 16:34:41 +02:00
|
|
|
void workbench_solid_materials_free(void);
|
2018-04-13 15:49:50 +02:00
|
|
|
|
2018-05-22 14:12:47 +02:00
|
|
|
/* workbench_deferred.c */
|
|
|
|
|
void workbench_deferred_engine_init(WORKBENCH_Data *vedata);
|
|
|
|
|
void workbench_deferred_engine_free(void);
|
|
|
|
|
void workbench_deferred_draw_background(WORKBENCH_Data *vedata);
|
|
|
|
|
void workbench_deferred_draw_scene(WORKBENCH_Data *vedata);
|
|
|
|
|
void workbench_deferred_cache_init(WORKBENCH_Data *vedata);
|
|
|
|
|
void workbench_deferred_solid_cache_populate(WORKBENCH_Data *vedata, Object *ob);
|
|
|
|
|
void workbench_deferred_cache_finish(WORKBENCH_Data *vedata);
|
|
|
|
|
|
|
|
|
|
/* workbench_forward.c */
|
|
|
|
|
void workbench_forward_engine_init(WORKBENCH_Data *vedata);
|
|
|
|
|
void workbench_forward_engine_free(void);
|
|
|
|
|
void workbench_forward_draw_background(WORKBENCH_Data *vedata);
|
|
|
|
|
void workbench_forward_draw_scene(WORKBENCH_Data *vedata);
|
|
|
|
|
void workbench_forward_cache_init(WORKBENCH_Data *vedata);
|
|
|
|
|
void workbench_forward_cache_populate(WORKBENCH_Data *vedata, Object *ob);
|
|
|
|
|
void workbench_forward_cache_finish(WORKBENCH_Data *vedata);
|
|
|
|
|
|
2018-04-18 13:44:33 +02:00
|
|
|
/* workbench_materials.c */
|
2018-05-22 14:12:47 +02:00
|
|
|
char *workbench_material_build_defines(WORKBENCH_PrivateData *wpd, int drawtype);
|
|
|
|
|
void workbench_material_get_solid_color(WORKBENCH_PrivateData *wpd, Object *ob, Material *mat, float *color);
|
|
|
|
|
uint workbench_material_get_hash(WORKBENCH_MaterialData *material_template);
|
|
|
|
|
int workbench_material_get_shader_index(WORKBENCH_PrivateData *wpd, int drawtype);
|
2018-05-26 10:41:25 +02:00
|
|
|
void workbench_material_set_normal_world_matrix(
|
|
|
|
|
DRWShadingGroup *grp, WORKBENCH_PrivateData *wpd, float persistent_matrix[3][3]);
|
2018-04-13 15:49:50 +02:00
|
|
|
|
2018-05-03 15:31:03 +02:00
|
|
|
/* workbench_studiolight.c */
|
2018-05-11 16:55:14 +02:00
|
|
|
void studiolight_update_world(StudioLight *sl, WORKBENCH_UBO_World *wd);
|
2018-05-03 15:31:03 +02:00
|
|
|
|
2018-05-22 14:12:47 +02:00
|
|
|
/* workbench_data.c */
|
|
|
|
|
void workbench_private_data_init(WORKBENCH_PrivateData *wpd);
|
|
|
|
|
void workbench_private_data_free(WORKBENCH_PrivateData *wpd);
|
|
|
|
|
|
|
|
|
|
extern DrawEngineType draw_engine_workbench_solid;
|
|
|
|
|
extern DrawEngineType draw_engine_workbench_transparent;
|
|
|
|
|
|
2018-04-13 15:49:50 +02:00
|
|
|
#endif
|