2018-04-13 15:49:50 +02:00
|
|
|
/*
|
|
|
|
|
* 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.
|
|
|
|
|
*
|
2019-01-23 11:29:18 +11:00
|
|
|
* Copyright 2016, Blender Foundation.
|
2018-04-13 15:49:50 +02:00
|
|
|
*/
|
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup draw_engine
|
2018-04-13 15:49:50 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#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-06-01 08:15:50 +02:00
|
|
|
#include "DNA_world_types.h"
|
2018-06-18 08:51:29 +02:00
|
|
|
#include "DNA_userdef_types.h"
|
2018-04-13 15:49:50 +02:00
|
|
|
|
2018-05-07 14:59:27 +02:00
|
|
|
#include "DRW_render.h"
|
|
|
|
|
|
2018-07-11 11:43:56 +02:00
|
|
|
#include "workbench_engine.h"
|
2018-05-07 14:59:27 +02:00
|
|
|
|
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
|
2019-08-27 08:42:50 +02:00
|
|
|
#define MAX_COMPOSITE_SHADERS (1 << 7)
|
2019-04-16 14:00:16 +02:00
|
|
|
#define MAX_PREPASS_SHADERS (1 << 7)
|
2019-08-27 08:42:50 +02:00
|
|
|
#define MAX_ACCUM_SHADERS (1 << 7)
|
2018-11-30 01:53:50 +01:00
|
|
|
#define MAX_CAVITY_SHADERS (1 << 3)
|
2018-06-05 08:15:30 +02:00
|
|
|
|
2018-12-20 23:23:59 +01:00
|
|
|
#define TEXTURE_DRAWING_ENABLED(wpd) (wpd->shading.color_type == V3D_SHADING_TEXTURE_COLOR)
|
2019-04-16 14:00:16 +02:00
|
|
|
#define VERTEX_COLORS_ENABLED(wpd) (wpd->shading.color_type == V3D_SHADING_VERTEX_COLOR)
|
2019-07-04 15:38:47 +02:00
|
|
|
#define MATERIAL_COLORS_ENABLED(wpd) (wpd->shading.color_type == V3D_SHADING_MATERIAL_COLOR)
|
2018-06-05 08:15:30 +02:00
|
|
|
#define FLAT_ENABLED(wpd) (wpd->shading.light == V3D_LIGHTING_FLAT)
|
|
|
|
|
#define STUDIOLIGHT_ENABLED(wpd) (wpd->shading.light == V3D_LIGHTING_STUDIO)
|
2018-06-21 14:56:00 +02:00
|
|
|
#define MATCAP_ENABLED(wpd) (wpd->shading.light == V3D_LIGHTING_MATCAP)
|
2018-11-29 20:57:09 +01:00
|
|
|
#define USE_WORLD_ORIENTATION(wpd) ((wpd->shading.flag & V3D_SHADING_WORLD_ORIENTATION) != 0)
|
2019-04-17 06:17:24 +02:00
|
|
|
#define STUDIOLIGHT_TYPE_WORLD_ENABLED(wpd) \
|
|
|
|
|
(STUDIOLIGHT_ENABLED(wpd) && (wpd->studio_light->flag & STUDIOLIGHT_TYPE_WORLD))
|
|
|
|
|
#define STUDIOLIGHT_TYPE_STUDIO_ENABLED(wpd) \
|
|
|
|
|
(STUDIOLIGHT_ENABLED(wpd) && (wpd->studio_light->flag & STUDIOLIGHT_TYPE_STUDIO))
|
|
|
|
|
#define STUDIOLIGHT_TYPE_MATCAP_ENABLED(wpd) \
|
|
|
|
|
(MATCAP_ENABLED(wpd) && (wpd->studio_light->flag & STUDIOLIGHT_TYPE_MATCAP))
|
|
|
|
|
#define SSAO_ENABLED(wpd) \
|
|
|
|
|
((wpd->shading.flag & V3D_SHADING_CAVITY) && \
|
|
|
|
|
((wpd->shading.cavity_type == V3D_SHADING_CAVITY_SSAO) || \
|
|
|
|
|
(wpd->shading.cavity_type == V3D_SHADING_CAVITY_BOTH)))
|
|
|
|
|
#define CURVATURE_ENABLED(wpd) \
|
|
|
|
|
((wpd->shading.flag & V3D_SHADING_CAVITY) && \
|
|
|
|
|
((wpd->shading.cavity_type == V3D_SHADING_CAVITY_CURVATURE) || \
|
|
|
|
|
(wpd->shading.cavity_type == V3D_SHADING_CAVITY_BOTH)))
|
2018-12-03 00:36:54 +01:00
|
|
|
#define CAVITY_ENABLED(wpd) (CURVATURE_ENABLED(wpd) || SSAO_ENABLED(wpd))
|
2018-05-22 14:12:47 +02:00
|
|
|
#define SHADOW_ENABLED(wpd) (wpd->shading.flag & V3D_SHADING_SHADOW)
|
2019-04-17 06:17:24 +02:00
|
|
|
#define GHOST_ENABLED(psl) \
|
|
|
|
|
(!DRW_pass_is_empty(psl->ghost_prepass_pass) || !DRW_pass_is_empty(psl->ghost_prepass_hair_pass))
|
2019-01-29 03:06:59 +01:00
|
|
|
#define CULL_BACKFACE_ENABLED(wpd) ((wpd->shading.flag & V3D_SHADING_BACKFACE_CULLING) != 0)
|
2019-04-17 06:17:24 +02:00
|
|
|
#define OIT_ENABLED(wpd) \
|
|
|
|
|
(ELEM(wpd->shading.color_type, \
|
|
|
|
|
V3D_SHADING_MATERIAL_COLOR, \
|
|
|
|
|
V3D_SHADING_OBJECT_COLOR, \
|
2019-04-16 14:00:16 +02:00
|
|
|
V3D_SHADING_TEXTURE_COLOR, \
|
|
|
|
|
V3D_SHADING_VERTEX_COLOR))
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
|
#define IS_NAVIGATING(wpd) \
|
2019-09-28 23:37:16 +02:00
|
|
|
((DRW_context_state_get()->rv3d) && \
|
|
|
|
|
(DRW_context_state_get()->rv3d->rflag & (RV3D_NAVIGATING | RV3D_PAINTING)))
|
2019-05-02 15:18:53 +02:00
|
|
|
|
2018-11-26 16:49:56 +01:00
|
|
|
#define OBJECT_OUTLINE_ENABLED(wpd) (wpd->shading.flag & V3D_SHADING_OBJECT_OUTLINE)
|
|
|
|
|
#define OBJECT_ID_PASS_ENABLED(wpd) (OBJECT_OUTLINE_ENABLED(wpd) || CURVATURE_ENABLED(wpd))
|
2019-04-17 06:17:24 +02:00
|
|
|
#define NORMAL_VIEWPORT_COMP_PASS_ENABLED(wpd) \
|
|
|
|
|
(MATCAP_ENABLED(wpd) || STUDIOLIGHT_ENABLED(wpd) || SHADOW_ENABLED(wpd))
|
|
|
|
|
#define NORMAL_VIEWPORT_PASS_ENABLED(wpd) \
|
|
|
|
|
(NORMAL_VIEWPORT_COMP_PASS_ENABLED(wpd) || SSAO_ENABLED(wpd) || CURVATURE_ENABLED(wpd))
|
2018-05-22 14:12:47 +02:00
|
|
|
#define NORMAL_ENCODING_ENABLED() (true)
|
2019-03-19 15:41:14 +01:00
|
|
|
#define WORLD_CLIPPING_ENABLED(wpd) (wpd->world_clip_planes != NULL)
|
2018-06-21 14:56:00 +02:00
|
|
|
|
2018-07-11 11:43:56 +02:00
|
|
|
struct RenderEngine;
|
|
|
|
|
struct RenderLayer;
|
|
|
|
|
struct rcti;
|
|
|
|
|
|
2018-04-25 10:59:48 +02:00
|
|
|
typedef struct WORKBENCH_FramebufferList {
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Deferred render buffers */
|
|
|
|
|
struct GPUFrameBuffer *prepass_fb;
|
|
|
|
|
struct GPUFrameBuffer *ghost_prepass_fb;
|
|
|
|
|
struct GPUFrameBuffer *cavity_fb;
|
|
|
|
|
struct GPUFrameBuffer *composite_fb;
|
|
|
|
|
struct GPUFrameBuffer *id_clear_fb;
|
|
|
|
|
|
|
|
|
|
struct GPUFrameBuffer *effect_fb;
|
|
|
|
|
struct GPUFrameBuffer *effect_taa_fb;
|
|
|
|
|
struct GPUFrameBuffer *depth_buffer_fb;
|
|
|
|
|
struct GPUFrameBuffer *color_only_fb;
|
|
|
|
|
|
|
|
|
|
struct GPUFrameBuffer *dof_downsample_fb;
|
|
|
|
|
struct GPUFrameBuffer *dof_coc_tile_h_fb;
|
|
|
|
|
struct GPUFrameBuffer *dof_coc_tile_v_fb;
|
|
|
|
|
struct GPUFrameBuffer *dof_coc_dilate_fb;
|
|
|
|
|
struct GPUFrameBuffer *dof_blur1_fb;
|
|
|
|
|
struct GPUFrameBuffer *dof_blur2_fb;
|
|
|
|
|
|
|
|
|
|
/* Forward render buffers */
|
|
|
|
|
struct GPUFrameBuffer *object_outline_fb;
|
|
|
|
|
struct GPUFrameBuffer *transparent_accum_fb;
|
|
|
|
|
struct GPUFrameBuffer *transparent_revealage_fb;
|
2018-04-25 10:59:48 +02:00
|
|
|
} WORKBENCH_FramebufferList;
|
2018-04-13 15:49:50 +02:00
|
|
|
|
2018-06-25 09:06:39 +02:00
|
|
|
typedef struct WORKBENCH_TextureList {
|
2019-04-17 06:17:24 +02:00
|
|
|
struct GPUTexture *dof_source_tx;
|
|
|
|
|
struct GPUTexture *coc_halfres_tx;
|
|
|
|
|
struct GPUTexture *history_buffer_tx;
|
|
|
|
|
struct GPUTexture *depth_buffer_tx;
|
2018-06-25 09:06:39 +02:00
|
|
|
} WORKBENCH_TextureList;
|
|
|
|
|
|
2018-04-13 15:49:50 +02:00
|
|
|
typedef struct WORKBENCH_StorageList {
|
2019-04-17 06:17:24 +02:00
|
|
|
struct WORKBENCH_PrivateData *g_data;
|
|
|
|
|
struct WORKBENCH_EffectInfo *effects;
|
|
|
|
|
float *dof_ubo_data;
|
2018-04-13 15:49:50 +02:00
|
|
|
} WORKBENCH_StorageList;
|
|
|
|
|
|
|
|
|
|
typedef struct WORKBENCH_PassList {
|
2019-04-17 06:17:24 +02:00
|
|
|
/* deferred rendering */
|
|
|
|
|
struct DRWPass *prepass_pass;
|
|
|
|
|
struct DRWPass *prepass_hair_pass;
|
|
|
|
|
struct DRWPass *ghost_prepass_pass;
|
|
|
|
|
struct DRWPass *ghost_prepass_hair_pass;
|
|
|
|
|
struct DRWPass *cavity_pass;
|
|
|
|
|
struct DRWPass *shadow_depth_pass_pass;
|
|
|
|
|
struct DRWPass *shadow_depth_pass_mani_pass;
|
|
|
|
|
struct DRWPass *shadow_depth_fail_pass;
|
|
|
|
|
struct DRWPass *shadow_depth_fail_mani_pass;
|
|
|
|
|
struct DRWPass *shadow_depth_fail_caps_pass;
|
|
|
|
|
struct DRWPass *shadow_depth_fail_caps_mani_pass;
|
|
|
|
|
struct DRWPass *composite_pass;
|
|
|
|
|
struct DRWPass *composite_shadow_pass;
|
|
|
|
|
struct DRWPass *oit_composite_pass;
|
|
|
|
|
struct DRWPass *background_pass;
|
|
|
|
|
struct DRWPass *background_pass_clip;
|
|
|
|
|
struct DRWPass *ghost_resolve_pass;
|
|
|
|
|
struct DRWPass *effect_aa_pass;
|
|
|
|
|
struct DRWPass *dof_down_ps;
|
|
|
|
|
struct DRWPass *dof_down2_ps;
|
|
|
|
|
struct DRWPass *dof_flatten_v_ps;
|
|
|
|
|
struct DRWPass *dof_flatten_h_ps;
|
|
|
|
|
struct DRWPass *dof_dilate_h_ps;
|
|
|
|
|
struct DRWPass *dof_dilate_v_ps;
|
|
|
|
|
struct DRWPass *dof_blur1_ps;
|
|
|
|
|
struct DRWPass *dof_blur2_ps;
|
|
|
|
|
struct DRWPass *dof_resolve_ps;
|
|
|
|
|
struct DRWPass *volume_pass;
|
|
|
|
|
|
|
|
|
|
/* forward rendering */
|
|
|
|
|
struct DRWPass *transparent_accum_pass;
|
|
|
|
|
struct DRWPass *object_outline_pass;
|
|
|
|
|
struct DRWPass *depth_pass;
|
|
|
|
|
struct DRWPass *checker_depth_pass;
|
2018-04-13 15:49:50 +02:00
|
|
|
} WORKBENCH_PassList;
|
|
|
|
|
|
|
|
|
|
typedef struct WORKBENCH_Data {
|
2019-04-17 06:17:24 +02:00
|
|
|
void *engine_type;
|
|
|
|
|
WORKBENCH_FramebufferList *fbl;
|
|
|
|
|
WORKBENCH_TextureList *txl;
|
|
|
|
|
WORKBENCH_PassList *psl;
|
|
|
|
|
WORKBENCH_StorageList *stl;
|
2018-04-13 15:49:50 +02:00
|
|
|
} WORKBENCH_Data;
|
|
|
|
|
|
2018-05-31 13:32:53 +02:00
|
|
|
typedef struct WORKBENCH_UBO_Light {
|
2019-04-17 06:17:24 +02:00
|
|
|
float light_direction[4];
|
|
|
|
|
float specular_color[3], pad;
|
|
|
|
|
float diffuse_color[3], wrapped;
|
2018-05-31 13:32:53 +02:00
|
|
|
} WORKBENCH_UBO_Light;
|
|
|
|
|
|
2018-04-25 10:59:48 +02:00
|
|
|
typedef struct WORKBENCH_UBO_World {
|
2019-04-17 06:17:24 +02:00
|
|
|
float background_color_low[4];
|
|
|
|
|
float background_color_high[4];
|
|
|
|
|
float object_outline_color[4];
|
|
|
|
|
float shadow_direction_vs[4];
|
|
|
|
|
WORKBENCH_UBO_Light lights[4];
|
|
|
|
|
float ambient_color[4];
|
|
|
|
|
int num_lights;
|
|
|
|
|
int matcap_orientation;
|
|
|
|
|
float background_alpha;
|
|
|
|
|
float curvature_ridge;
|
|
|
|
|
float curvature_valley;
|
2019-10-16 15:30:57 +02:00
|
|
|
float background_dither_factor;
|
|
|
|
|
int pad[2];
|
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 {
|
2019-04-17 06:17:24 +02:00
|
|
|
struct GHash *material_hash;
|
|
|
|
|
struct GHash *material_transp_hash;
|
2019-04-16 14:00:16 +02:00
|
|
|
struct GPUShader *prepass_sh;
|
|
|
|
|
struct GPUShader *prepass_hair_sh;
|
|
|
|
|
struct GPUShader *prepass_uniform_sh;
|
|
|
|
|
struct GPUShader *prepass_uniform_hair_sh;
|
2019-07-04 15:38:47 +02:00
|
|
|
struct GPUShader *prepass_textured_sh;
|
2019-12-18 09:09:09 +01:00
|
|
|
struct GPUShader *prepass_vertex_sh;
|
2019-04-17 06:17:24 +02:00
|
|
|
struct GPUShader *composite_sh;
|
|
|
|
|
struct GPUShader *background_sh;
|
|
|
|
|
struct GPUShader *transparent_accum_sh;
|
|
|
|
|
struct GPUShader *transparent_accum_hair_sh;
|
2019-04-16 14:00:16 +02:00
|
|
|
struct GPUShader *transparent_accum_uniform_sh;
|
|
|
|
|
struct GPUShader *transparent_accum_uniform_hair_sh;
|
2019-07-04 15:38:47 +02:00
|
|
|
struct GPUShader *transparent_accum_textured_sh;
|
2019-12-18 09:09:09 +01:00
|
|
|
struct GPUShader *transparent_accum_vertex_sh;
|
2019-04-17 06:17:24 +02:00
|
|
|
View3DShading shading;
|
|
|
|
|
StudioLight *studio_light;
|
|
|
|
|
const UserDef *preferences;
|
2019-10-17 15:27:53 +02:00
|
|
|
/* Does this instance owns the `world_ubo` field.
|
|
|
|
|
* Normally the field is borrowed from `WORKBENCH_WorldData`. In case that
|
|
|
|
|
* there is no World attached to the scene the UBO cannot be cached and should
|
|
|
|
|
* be freed after using. */
|
|
|
|
|
bool is_world_ubo_owner;
|
2019-04-17 06:17:24 +02:00
|
|
|
struct GPUUniformBuffer *world_ubo;
|
|
|
|
|
struct DRWShadingGroup *shadow_shgrp;
|
|
|
|
|
struct DRWShadingGroup *depth_shgrp;
|
|
|
|
|
WORKBENCH_UBO_World world_data;
|
|
|
|
|
float shadow_multiplier;
|
|
|
|
|
float shadow_shift;
|
|
|
|
|
float shadow_focus;
|
|
|
|
|
float cached_shadow_direction[3];
|
|
|
|
|
float shadow_mat[4][4];
|
|
|
|
|
float shadow_inv[4][4];
|
|
|
|
|
/* Far plane of the view frustum. */
|
|
|
|
|
float shadow_far_plane[4];
|
|
|
|
|
/* Near plane corners in shadow space. */
|
|
|
|
|
float shadow_near_corners[4][3];
|
|
|
|
|
/* min and max of shadow_near_corners. allow fast test */
|
|
|
|
|
float shadow_near_min[3];
|
|
|
|
|
float shadow_near_max[3];
|
|
|
|
|
/* This is a parallelogram, so only 2 normal and distance to the edges. */
|
|
|
|
|
float shadow_near_sides[2][4];
|
|
|
|
|
bool shadow_changed;
|
|
|
|
|
bool is_playback;
|
|
|
|
|
|
|
|
|
|
float (*world_clip_planes)[4];
|
|
|
|
|
struct GPUBatch *world_clip_planes_batch;
|
|
|
|
|
float world_clip_planes_color[4];
|
|
|
|
|
|
|
|
|
|
/* Volumes */
|
|
|
|
|
bool volumes_do;
|
|
|
|
|
ListBase smoke_domains;
|
|
|
|
|
|
|
|
|
|
/* Ssao */
|
|
|
|
|
float winmat[4][4];
|
|
|
|
|
float viewvecs[3][4];
|
|
|
|
|
float ssao_params[4];
|
|
|
|
|
float ssao_settings[4];
|
|
|
|
|
|
|
|
|
|
/* Dof */
|
|
|
|
|
struct GPUTexture *dof_blur_tx;
|
|
|
|
|
struct GPUTexture *coc_temp_tx;
|
|
|
|
|
struct GPUTexture *coc_tiles_tx[2];
|
|
|
|
|
struct GPUUniformBuffer *dof_ubo;
|
|
|
|
|
float dof_aperturesize;
|
|
|
|
|
float dof_distance;
|
|
|
|
|
float dof_invsensorsize;
|
|
|
|
|
float dof_near_far[2];
|
|
|
|
|
float dof_blades;
|
|
|
|
|
float dof_rotation;
|
|
|
|
|
float dof_ratio;
|
|
|
|
|
bool dof_enabled;
|
|
|
|
|
|
|
|
|
|
/* Color Management */
|
|
|
|
|
bool use_color_management;
|
|
|
|
|
bool use_color_render_settings;
|
2018-04-13 15:49:50 +02:00
|
|
|
} WORKBENCH_PrivateData; /* Transient data */
|
|
|
|
|
|
2018-06-25 09:06:39 +02:00
|
|
|
typedef struct WORKBENCH_EffectInfo {
|
2019-05-20 20:33:56 +02:00
|
|
|
/** View */
|
|
|
|
|
struct DRWView *view;
|
|
|
|
|
/** Last projection matrix to see if view is still valid. */
|
2019-04-17 06:17:24 +02:00
|
|
|
float last_mat[4][4];
|
|
|
|
|
int jitter_index;
|
|
|
|
|
float taa_mix_factor;
|
|
|
|
|
bool view_updated;
|
2018-06-25 09:06:39 +02:00
|
|
|
} WORKBENCH_EffectInfo;
|
|
|
|
|
|
2018-04-18 13:44:33 +02:00
|
|
|
typedef struct WORKBENCH_MaterialData {
|
2019-05-31 01:45:41 +02:00
|
|
|
float base_color[3], metallic;
|
|
|
|
|
float roughness, alpha;
|
2019-04-17 06:17:24 +02:00
|
|
|
int color_type;
|
|
|
|
|
int interp;
|
|
|
|
|
Image *ima;
|
|
|
|
|
ImageUser *iuser;
|
|
|
|
|
|
|
|
|
|
/* Linked shgroup for drawing */
|
|
|
|
|
DRWShadingGroup *shgrp;
|
|
|
|
|
/* forward rendering */
|
|
|
|
|
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 {
|
2019-04-17 06:17:24 +02:00
|
|
|
DrawData dd;
|
2018-07-10 14:14:55 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Shadow direction in local object space. */
|
|
|
|
|
float shadow_dir[3], shadow_depth;
|
|
|
|
|
/* Min, max in shadow space */
|
|
|
|
|
float shadow_min[3], shadow_max[3];
|
|
|
|
|
BoundBox shadow_bbox;
|
|
|
|
|
bool shadow_bbox_dirty;
|
2018-04-25 10:59:48 +02:00
|
|
|
} WORKBENCH_ObjectData;
|
2018-04-18 13:44:33 +02:00
|
|
|
|
2019-10-17 15:27:53 +02:00
|
|
|
typedef struct WORKBENCH_WorldData {
|
|
|
|
|
DrawData dd;
|
|
|
|
|
/* The cached `GPUUniformBuffer`, that is reused between draw calls. */
|
|
|
|
|
struct GPUUniformBuffer *world_ubo;
|
|
|
|
|
} WORKBENCH_WorldData;
|
|
|
|
|
|
2019-12-18 09:09:09 +01:00
|
|
|
/* Enumeration containing override options for base color rendering.
|
|
|
|
|
* This is used to during painting to force the base color to show what you are
|
|
|
|
|
* painting using the selected lighting model. */
|
|
|
|
|
typedef enum WORKBENCH_ColorOverride {
|
|
|
|
|
WORKBENCH_COLOR_OVERRIDE_OFF = 0,
|
|
|
|
|
WORKBENCH_COLOR_OVERRIDE_TEXTURE = CTX_MODE_PAINT_TEXTURE,
|
|
|
|
|
WORKBENCH_COLOR_OVERRIDE_VERTEX = CTX_MODE_PAINT_VERTEX,
|
|
|
|
|
} WORKBENCH_ColorOverride;
|
|
|
|
|
|
2019-05-02 15:18:53 +02:00
|
|
|
/* inline helper functions */
|
2019-08-27 08:42:50 +02:00
|
|
|
BLI_INLINE bool workbench_is_specular_highlight_enabled(WORKBENCH_PrivateData *wpd)
|
|
|
|
|
{
|
|
|
|
|
if ((wpd->shading.flag & V3D_SHADING_SPECULAR_HIGHLIGHT)) {
|
|
|
|
|
if (STUDIOLIGHT_ENABLED(wpd) || MATCAP_ENABLED(wpd)) {
|
|
|
|
|
return (wpd->studio_light->flag & STUDIOLIGHT_SPECULAR_HIGHLIGHT_PASS) != 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-02 15:18:53 +02:00
|
|
|
BLI_INLINE bool workbench_is_taa_enabled(WORKBENCH_PrivateData *wpd)
|
|
|
|
|
{
|
|
|
|
|
if (DRW_state_is_image_render()) {
|
2019-05-08 15:38:11 +02:00
|
|
|
const DRWContextState *draw_ctx = DRW_context_state_get();
|
|
|
|
|
if (draw_ctx->v3d) {
|
|
|
|
|
return draw_ctx->scene->display.viewport_aa > SCE_DISPLAY_AA_FXAA;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return draw_ctx->scene->display.render_aa > SCE_DISPLAY_AA_FXAA;
|
|
|
|
|
}
|
2019-05-02 15:18:53 +02:00
|
|
|
}
|
|
|
|
|
else {
|
2019-05-21 10:07:41 +02:00
|
|
|
return !(IS_NAVIGATING(wpd) || wpd->is_playback) &&
|
|
|
|
|
wpd->preferences->viewport_aa > SCE_DISPLAY_AA_FXAA;
|
2019-05-02 15:18:53 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BLI_INLINE bool workbench_is_fxaa_enabled(WORKBENCH_PrivateData *wpd)
|
|
|
|
|
{
|
|
|
|
|
if (DRW_state_is_image_render()) {
|
2019-05-08 15:38:11 +02:00
|
|
|
const DRWContextState *draw_ctx = DRW_context_state_get();
|
|
|
|
|
if (draw_ctx->v3d) {
|
|
|
|
|
return draw_ctx->scene->display.viewport_aa == SCE_DISPLAY_AA_FXAA;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return draw_ctx->scene->display.render_aa == SCE_DISPLAY_AA_FXAA;
|
|
|
|
|
}
|
2019-05-02 15:18:53 +02:00
|
|
|
}
|
|
|
|
|
else {
|
2019-05-08 15:38:11 +02:00
|
|
|
if (wpd->preferences->viewport_aa == SCE_DISPLAY_AA_FXAA) {
|
2019-05-02 15:18:53 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-21 10:07:41 +02:00
|
|
|
/* when navigating or animation playback use FXAA if scene uses TAA. */
|
|
|
|
|
return (IS_NAVIGATING(wpd) || wpd->is_playback) &&
|
|
|
|
|
wpd->preferences->viewport_aa > SCE_DISPLAY_AA_FXAA;
|
2019-05-02 15:18:53 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-04 15:38:47 +02:00
|
|
|
/** Is texture paint mode enabled (globally) */
|
|
|
|
|
BLI_INLINE bool workbench_is_in_texture_paint_mode(void)
|
|
|
|
|
{
|
|
|
|
|
const DRWContextState *draw_ctx = DRW_context_state_get();
|
|
|
|
|
return draw_ctx->object_mode == OB_MODE_TEXTURE_PAINT;
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-18 09:09:09 +01:00
|
|
|
/** Is vertex paint mode enabled (globally) */
|
|
|
|
|
BLI_INLINE bool workbench_is_in_vertex_paint_mode(void)
|
|
|
|
|
{
|
|
|
|
|
const DRWContextState *draw_ctx = DRW_context_state_get();
|
|
|
|
|
return draw_ctx->object_mode == OB_MODE_VERTEX_PAINT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Must the `View3DShading.color_type` be overriden for the given object. */
|
|
|
|
|
BLI_INLINE WORKBENCH_ColorOverride workbench_object_color_override_get(Object *ob)
|
2019-07-04 15:38:47 +02:00
|
|
|
{
|
|
|
|
|
const DRWContextState *draw_ctx = DRW_context_state_get();
|
|
|
|
|
if (ob->type == OB_MESH && (draw_ctx->obact == ob)) {
|
|
|
|
|
const enum eContextObjectMode mode = CTX_data_mode_enum_ex(
|
|
|
|
|
draw_ctx->object_edit, draw_ctx->obact, draw_ctx->object_mode);
|
2019-12-18 09:09:09 +01:00
|
|
|
if (mode == CTX_MODE_PAINT_TEXTURE) {
|
|
|
|
|
return WORKBENCH_COLOR_OVERRIDE_TEXTURE;
|
|
|
|
|
}
|
|
|
|
|
else if (mode == CTX_MODE_PAINT_VERTEX) {
|
|
|
|
|
return WORKBENCH_COLOR_OVERRIDE_VERTEX;
|
|
|
|
|
}
|
2019-07-04 15:38:47 +02:00
|
|
|
}
|
|
|
|
|
|
2019-12-18 09:09:09 +01:00
|
|
|
return WORKBENCH_COLOR_OVERRIDE_OFF;
|
2019-07-04 15:38:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BLI_INLINE bool workbench_is_matdata_pass_enabled(WORKBENCH_PrivateData *wpd)
|
|
|
|
|
{
|
|
|
|
|
return (wpd->shading.color_type != V3D_SHADING_SINGLE_COLOR || MATCAP_ENABLED(wpd)) ||
|
2019-12-18 09:09:09 +01:00
|
|
|
workbench_is_in_texture_paint_mode() || workbench_is_in_vertex_paint_mode();
|
2019-07-04 15:38:47 +02:00
|
|
|
}
|
|
|
|
|
|
2019-07-04 08:27:17 +02:00
|
|
|
/**
|
|
|
|
|
* Get the default texture format to be used by the color and history buffers.
|
|
|
|
|
*
|
|
|
|
|
* Use GPU_RGBA16F for final renderings and for drawing textures. This
|
|
|
|
|
* allows displaying HDRI textures. Vertex Colors uses GPU_RGBA16 to resolve
|
|
|
|
|
* color banding issues (T66100). All other modes use GPU_RGBA8 to reduce
|
|
|
|
|
* bandwidth and gpu memory.
|
|
|
|
|
*/
|
2019-08-06 17:04:46 +10:00
|
|
|
BLI_INLINE eGPUTextureFormat workbench_color_texture_format(const WORKBENCH_PrivateData *wpd)
|
2019-07-04 08:27:17 +02:00
|
|
|
{
|
|
|
|
|
eGPUTextureFormat result;
|
|
|
|
|
if (DRW_state_is_image_render() || workbench_is_in_texture_paint_mode() ||
|
|
|
|
|
TEXTURE_DRAWING_ENABLED(wpd)) {
|
|
|
|
|
result = GPU_RGBA16F;
|
|
|
|
|
}
|
2019-12-18 09:09:09 +01:00
|
|
|
else if (workbench_is_in_vertex_paint_mode() || VERTEX_COLORS_ENABLED(wpd)) {
|
2019-07-04 08:27:17 +02:00
|
|
|
result = GPU_RGBA16;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
result = GPU_RGBA8;
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-17 12:19:59 +11:00
|
|
|
BLI_INLINE bool workbench_background_dither_factor(const WORKBENCH_PrivateData *wpd)
|
|
|
|
|
{
|
2019-10-16 15:30:57 +02:00
|
|
|
/* Only apply dithering when rendering on a RGBA8 texture.
|
|
|
|
|
* The dithering will remove banding when using a gradient as background */
|
|
|
|
|
return workbench_color_texture_format(wpd) == GPU_RGBA8;
|
|
|
|
|
}
|
|
|
|
|
|
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);
|
2018-07-11 11:43:56 +02:00
|
|
|
void workbench_deferred_draw_finish(WORKBENCH_Data *vedata);
|
2018-05-22 14:12:47 +02:00
|
|
|
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);
|
2018-08-21 10:59:01 +02:00
|
|
|
void workbench_forward_draw_finish(WORKBENCH_Data *vedata);
|
2018-05-22 14:12:47 +02:00
|
|
|
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);
|
|
|
|
|
|
2019-01-29 03:06:59 +01:00
|
|
|
/* For OIT in deferred */
|
2019-03-23 13:30:02 +11:00
|
|
|
void workbench_forward_outline_shaders_ensure(WORKBENCH_PrivateData *wpd, eGPUShaderConfig sh_cfg);
|
|
|
|
|
void workbench_forward_choose_shaders(WORKBENCH_PrivateData *wpd, eGPUShaderConfig sh_cfg);
|
2019-04-17 06:17:24 +02:00
|
|
|
WORKBENCH_MaterialData *workbench_forward_get_or_create_material_data(WORKBENCH_Data *vedata,
|
|
|
|
|
Object *ob,
|
|
|
|
|
Material *mat,
|
|
|
|
|
Image *ima,
|
|
|
|
|
ImageUser *iuser,
|
|
|
|
|
int color_type,
|
2019-07-04 15:38:47 +02:00
|
|
|
int interp);
|
2019-01-29 03:06:59 +01:00
|
|
|
|
2018-06-28 14:09:48 +02:00
|
|
|
/* workbench_effect_aa.c */
|
|
|
|
|
void workbench_aa_create_pass(WORKBENCH_Data *vedata, GPUTexture **tx);
|
|
|
|
|
void workbench_aa_draw_pass(WORKBENCH_Data *vedata, GPUTexture *tx);
|
|
|
|
|
|
2018-06-25 09:06:39 +02:00
|
|
|
/* workbench_effect_fxaa.c */
|
|
|
|
|
void workbench_fxaa_engine_init(void);
|
|
|
|
|
void workbench_fxaa_engine_free(void);
|
|
|
|
|
DRWPass *workbench_fxaa_create_pass(GPUTexture **color_buffer_tx);
|
|
|
|
|
|
|
|
|
|
/* workbench_effect_taa.c */
|
|
|
|
|
void workbench_taa_engine_init(WORKBENCH_Data *vedata);
|
|
|
|
|
void workbench_taa_engine_free(void);
|
2018-06-27 12:55:49 +02:00
|
|
|
DRWPass *workbench_taa_create_pass(WORKBENCH_Data *vedata, GPUTexture **color_buffer_tx);
|
|
|
|
|
void workbench_taa_draw_scene_start(WORKBENCH_Data *vedata);
|
2018-06-25 09:06:39 +02:00
|
|
|
void workbench_taa_draw_scene_end(WORKBENCH_Data *vedata);
|
|
|
|
|
void workbench_taa_view_updated(WORKBENCH_Data *vedata);
|
2018-06-27 12:55:49 +02:00
|
|
|
int workbench_taa_calculate_num_iterations(WORKBENCH_Data *vedata);
|
2019-05-02 15:18:53 +02:00
|
|
|
int workbench_num_viewport_rendering_iterations(WORKBENCH_Data *vedata);
|
2018-06-25 09:06:39 +02:00
|
|
|
|
2019-01-24 17:28:51 +01:00
|
|
|
/* workbench_effect_dof.c */
|
|
|
|
|
void workbench_dof_engine_init(WORKBENCH_Data *vedata, Object *camera);
|
|
|
|
|
void workbench_dof_engine_free(void);
|
2019-04-17 06:17:24 +02:00
|
|
|
void workbench_dof_create_pass(WORKBENCH_Data *vedata,
|
|
|
|
|
GPUTexture **dof_input,
|
|
|
|
|
GPUTexture *noise_tex);
|
2019-01-24 17:28:51 +01:00
|
|
|
void workbench_dof_draw_pass(WORKBENCH_Data *vedata);
|
|
|
|
|
|
2018-04-18 13:44:33 +02:00
|
|
|
/* workbench_materials.c */
|
2019-04-16 14:00:16 +02:00
|
|
|
int workbench_material_determine_color_type(WORKBENCH_PrivateData *wpd,
|
|
|
|
|
Image *ima,
|
|
|
|
|
Object *ob,
|
2019-05-31 14:04:16 +02:00
|
|
|
bool use_sculpt_pbvh);
|
2019-04-17 06:17:24 +02:00
|
|
|
void workbench_material_get_image_and_mat(
|
|
|
|
|
Object *ob, int mat_nr, Image **r_image, ImageUser **r_iuser, int *r_interp, Material **r_mat);
|
|
|
|
|
char *workbench_material_build_defines(WORKBENCH_PrivateData *wpd,
|
2019-04-16 14:00:16 +02:00
|
|
|
bool is_uniform_color,
|
2019-07-04 15:38:47 +02:00
|
|
|
bool is_hair,
|
2019-12-18 09:09:09 +01:00
|
|
|
const WORKBENCH_ColorOverride color_override);
|
2019-04-17 06:17:24 +02:00
|
|
|
void workbench_material_update_data(WORKBENCH_PrivateData *wpd,
|
|
|
|
|
Object *ob,
|
|
|
|
|
Material *mat,
|
2019-07-04 15:38:47 +02:00
|
|
|
WORKBENCH_MaterialData *data,
|
|
|
|
|
int color_type);
|
2018-08-14 20:26:21 +02:00
|
|
|
uint workbench_material_get_hash(WORKBENCH_MaterialData *material_template, bool is_ghost);
|
2018-12-05 02:07:23 +01:00
|
|
|
int workbench_material_get_composite_shader_index(WORKBENCH_PrivateData *wpd);
|
2019-04-17 06:17:24 +02:00
|
|
|
int workbench_material_get_prepass_shader_index(WORKBENCH_PrivateData *wpd,
|
2019-04-16 14:00:16 +02:00
|
|
|
bool is_uniform_color,
|
2019-07-04 15:38:47 +02:00
|
|
|
bool is_hair,
|
2019-12-18 09:09:09 +01:00
|
|
|
const WORKBENCH_ColorOverride color_override);
|
2019-04-17 06:17:24 +02:00
|
|
|
int workbench_material_get_accum_shader_index(WORKBENCH_PrivateData *wpd,
|
2019-04-16 14:00:16 +02:00
|
|
|
bool is_uniform_color,
|
2019-07-04 15:38:47 +02:00
|
|
|
bool is_hair,
|
2019-12-18 09:09:09 +01:00
|
|
|
const WORKBENCH_ColorOverride color_override);
|
2019-04-17 06:17:24 +02:00
|
|
|
void workbench_material_shgroup_uniform(WORKBENCH_PrivateData *wpd,
|
|
|
|
|
DRWShadingGroup *grp,
|
|
|
|
|
WORKBENCH_MaterialData *material,
|
|
|
|
|
Object *ob,
|
|
|
|
|
const bool deferred,
|
|
|
|
|
const int interp);
|
|
|
|
|
void workbench_material_copy(WORKBENCH_MaterialData *dest_material,
|
|
|
|
|
const WORKBENCH_MaterialData *source_material);
|
2018-04-13 15:49:50 +02:00
|
|
|
|
2018-05-03 15:31:03 +02:00
|
|
|
/* workbench_studiolight.c */
|
2019-04-17 06:17:24 +02:00
|
|
|
void studiolight_update_world(WORKBENCH_PrivateData *wpd,
|
|
|
|
|
StudioLight *sl,
|
|
|
|
|
WORKBENCH_UBO_World *wd);
|
2018-05-26 22:28:35 +02:00
|
|
|
void studiolight_update_light(WORKBENCH_PrivateData *wpd, const float light_direction[3]);
|
2019-04-17 06:17:24 +02:00
|
|
|
bool studiolight_object_cast_visible_shadow(WORKBENCH_PrivateData *wpd,
|
|
|
|
|
Object *ob,
|
|
|
|
|
WORKBENCH_ObjectData *oed);
|
|
|
|
|
float studiolight_object_shadow_distance(WORKBENCH_PrivateData *wpd,
|
|
|
|
|
Object *ob,
|
|
|
|
|
WORKBENCH_ObjectData *oed);
|
|
|
|
|
bool studiolight_camera_in_object_shadow(WORKBENCH_PrivateData *wpd,
|
|
|
|
|
Object *ob,
|
|
|
|
|
WORKBENCH_ObjectData *oed);
|
2018-05-03 15:31:03 +02:00
|
|
|
|
2018-05-22 14:12:47 +02:00
|
|
|
/* workbench_data.c */
|
2018-06-25 09:06:39 +02:00
|
|
|
void workbench_effect_info_init(WORKBENCH_EffectInfo *effect_info);
|
2018-05-22 14:12:47 +02:00
|
|
|
void workbench_private_data_init(WORKBENCH_PrivateData *wpd);
|
|
|
|
|
void workbench_private_data_free(WORKBENCH_PrivateData *wpd);
|
2019-10-17 15:27:53 +02:00
|
|
|
void workbench_private_data_get_light_direction(float r_light_direction[3]);
|
2018-05-22 14:12:47 +02:00
|
|
|
|
2018-07-16 15:01:44 +02:00
|
|
|
/* workbench_volume.c */
|
|
|
|
|
void workbench_volume_engine_init(void);
|
|
|
|
|
void workbench_volume_engine_free(void);
|
|
|
|
|
void workbench_volume_cache_init(WORKBENCH_Data *vedata);
|
2019-04-17 06:17:24 +02:00
|
|
|
void workbench_volume_cache_populate(WORKBENCH_Data *vedata,
|
|
|
|
|
Scene *scene,
|
|
|
|
|
Object *ob,
|
|
|
|
|
struct ModifierData *md);
|
2018-07-16 15:01:44 +02:00
|
|
|
void workbench_volume_smoke_textures_free(WORKBENCH_PrivateData *wpd);
|
|
|
|
|
|
2018-07-11 11:43:56 +02:00
|
|
|
/* workbench_render.c */
|
2019-04-17 06:17:24 +02:00
|
|
|
void workbench_render(WORKBENCH_Data *vedata,
|
|
|
|
|
struct RenderEngine *engine,
|
|
|
|
|
struct RenderLayer *render_layer,
|
|
|
|
|
const struct rcti *rect);
|
|
|
|
|
void workbench_render_update_passes(struct RenderEngine *engine,
|
|
|
|
|
struct Scene *scene,
|
|
|
|
|
struct ViewLayer *view_layer);
|
2018-05-22 14:12:47 +02:00
|
|
|
|
2018-04-13 15:49:50 +02:00
|
|
|
#endif
|