Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/engines/workbench/workbench_private.h
| Show First 20 Lines • Show All 201 Lines • ▼ Show 20 Lines | |||||
| typedef struct WORKBENCH_PrivateData { | typedef struct WORKBENCH_PrivateData { | ||||
| struct GHash *material_hash; | struct GHash *material_hash; | ||||
| struct GHash *material_transp_hash; | struct GHash *material_transp_hash; | ||||
| struct GPUShader *prepass_sh; | struct GPUShader *prepass_sh; | ||||
| struct GPUShader *prepass_hair_sh; | struct GPUShader *prepass_hair_sh; | ||||
| struct GPUShader *prepass_uniform_sh; | struct GPUShader *prepass_uniform_sh; | ||||
| struct GPUShader *prepass_uniform_hair_sh; | struct GPUShader *prepass_uniform_hair_sh; | ||||
| struct GPUShader *prepass_textured_sh; | struct GPUShader *prepass_textured_sh; | ||||
| struct GPUShader *prepass_vertex_sh; | |||||
| struct GPUShader *composite_sh; | struct GPUShader *composite_sh; | ||||
| struct GPUShader *background_sh; | struct GPUShader *background_sh; | ||||
| struct GPUShader *transparent_accum_sh; | struct GPUShader *transparent_accum_sh; | ||||
| struct GPUShader *transparent_accum_hair_sh; | struct GPUShader *transparent_accum_hair_sh; | ||||
| struct GPUShader *transparent_accum_uniform_sh; | struct GPUShader *transparent_accum_uniform_sh; | ||||
| struct GPUShader *transparent_accum_uniform_hair_sh; | struct GPUShader *transparent_accum_uniform_hair_sh; | ||||
| struct GPUShader *transparent_accum_textured_sh; | struct GPUShader *transparent_accum_textured_sh; | ||||
| struct GPUShader *transparent_accum_vertex_sh; | |||||
| View3DShading shading; | View3DShading shading; | ||||
| StudioLight *studio_light; | StudioLight *studio_light; | ||||
| const UserDef *preferences; | const UserDef *preferences; | ||||
| /* Does this instance owns the `world_ubo` field. | /* Does this instance owns the `world_ubo` field. | ||||
| * Normally the field is borrowed from `WORKBENCH_WorldData`. In case that | * 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 | * there is no World attached to the scene the UBO cannot be cached and should | ||||
| * be freed after using. */ | * be freed after using. */ | ||||
| bool is_world_ubo_owner; | bool is_world_ubo_owner; | ||||
| ▲ Show 20 Lines • Show All 88 Lines • ▼ Show 20 Lines | |||||
| } WORKBENCH_ObjectData; | } WORKBENCH_ObjectData; | ||||
| typedef struct WORKBENCH_WorldData { | typedef struct WORKBENCH_WorldData { | ||||
| DrawData dd; | DrawData dd; | ||||
| /* The cached `GPUUniformBuffer`, that is reused between draw calls. */ | /* The cached `GPUUniformBuffer`, that is reused between draw calls. */ | ||||
| struct GPUUniformBuffer *world_ubo; | struct GPUUniformBuffer *world_ubo; | ||||
| } WORKBENCH_WorldData; | } WORKBENCH_WorldData; | ||||
| /* 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; | |||||
| /* inline helper functions */ | /* inline helper functions */ | ||||
| BLI_INLINE bool workbench_is_specular_highlight_enabled(WORKBENCH_PrivateData *wpd) | BLI_INLINE bool workbench_is_specular_highlight_enabled(WORKBENCH_PrivateData *wpd) | ||||
| { | { | ||||
| if ((wpd->shading.flag & V3D_SHADING_SPECULAR_HIGHLIGHT)) { | if ((wpd->shading.flag & V3D_SHADING_SPECULAR_HIGHLIGHT)) { | ||||
| if (STUDIOLIGHT_ENABLED(wpd) || MATCAP_ENABLED(wpd)) { | if (STUDIOLIGHT_ENABLED(wpd) || MATCAP_ENABLED(wpd)) { | ||||
| return (wpd->studio_light->flag & STUDIOLIGHT_SPECULAR_HIGHLIGHT_PASS) != 0; | return (wpd->studio_light->flag & STUDIOLIGHT_SPECULAR_HIGHLIGHT_PASS) != 0; | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | |||||
| /** Is texture paint mode enabled (globally) */ | /** Is texture paint mode enabled (globally) */ | ||||
| BLI_INLINE bool workbench_is_in_texture_paint_mode(void) | BLI_INLINE bool workbench_is_in_texture_paint_mode(void) | ||||
| { | { | ||||
| const DRWContextState *draw_ctx = DRW_context_state_get(); | const DRWContextState *draw_ctx = DRW_context_state_get(); | ||||
| return draw_ctx->object_mode == OB_MODE_TEXTURE_PAINT; | return draw_ctx->object_mode == OB_MODE_TEXTURE_PAINT; | ||||
| } | } | ||||
| /** Is texture paint mode active for the given object */ | /** Is vertex paint mode enabled (globally) */ | ||||
| BLI_INLINE bool workbench_is_object_in_texture_paint_mode(Object *ob) | 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) | |||||
| { | { | ||||
| const DRWContextState *draw_ctx = DRW_context_state_get(); | const DRWContextState *draw_ctx = DRW_context_state_get(); | ||||
| if (ob->type == OB_MESH && (draw_ctx->obact == ob)) { | if (ob->type == OB_MESH && (draw_ctx->obact == ob)) { | ||||
| const enum eContextObjectMode mode = CTX_data_mode_enum_ex( | const enum eContextObjectMode mode = CTX_data_mode_enum_ex( | ||||
| draw_ctx->object_edit, draw_ctx->obact, draw_ctx->object_mode); | draw_ctx->object_edit, draw_ctx->obact, draw_ctx->object_mode); | ||||
| return (mode == CTX_MODE_PAINT_TEXTURE); | if (mode == CTX_MODE_PAINT_TEXTURE) { | ||||
| return WORKBENCH_COLOR_OVERRIDE_TEXTURE; | |||||
| } | |||||
| else if (mode == CTX_MODE_PAINT_VERTEX) { | |||||
| return WORKBENCH_COLOR_OVERRIDE_VERTEX; | |||||
| } | |||||
| } | } | ||||
| return false; | return WORKBENCH_COLOR_OVERRIDE_OFF; | ||||
| } | } | ||||
| BLI_INLINE bool workbench_is_matdata_pass_enabled(WORKBENCH_PrivateData *wpd) | BLI_INLINE bool workbench_is_matdata_pass_enabled(WORKBENCH_PrivateData *wpd) | ||||
| { | { | ||||
| return (wpd->shading.color_type != V3D_SHADING_SINGLE_COLOR || MATCAP_ENABLED(wpd)) || | return (wpd->shading.color_type != V3D_SHADING_SINGLE_COLOR || MATCAP_ENABLED(wpd)) || | ||||
| workbench_is_in_texture_paint_mode(); | workbench_is_in_texture_paint_mode() || workbench_is_in_vertex_paint_mode(); | ||||
| } | } | ||||
| /** | /** | ||||
| * Get the default texture format to be used by the color and history buffers. | * 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 | * Use GPU_RGBA16F for final renderings and for drawing textures. This | ||||
| * allows displaying HDRI textures. Vertex Colors uses GPU_RGBA16 to resolve | * allows displaying HDRI textures. Vertex Colors uses GPU_RGBA16 to resolve | ||||
| * color banding issues (T66100). All other modes use GPU_RGBA8 to reduce | * color banding issues (T66100). All other modes use GPU_RGBA8 to reduce | ||||
| * bandwidth and gpu memory. | * bandwidth and gpu memory. | ||||
| */ | */ | ||||
| BLI_INLINE eGPUTextureFormat workbench_color_texture_format(const WORKBENCH_PrivateData *wpd) | BLI_INLINE eGPUTextureFormat workbench_color_texture_format(const WORKBENCH_PrivateData *wpd) | ||||
| { | { | ||||
| eGPUTextureFormat result; | eGPUTextureFormat result; | ||||
| if (DRW_state_is_image_render() || workbench_is_in_texture_paint_mode() || | if (DRW_state_is_image_render() || workbench_is_in_texture_paint_mode() || | ||||
| TEXTURE_DRAWING_ENABLED(wpd)) { | TEXTURE_DRAWING_ENABLED(wpd)) { | ||||
| result = GPU_RGBA16F; | result = GPU_RGBA16F; | ||||
| } | } | ||||
| else if (VERTEX_COLORS_ENABLED(wpd)) { | else if (workbench_is_in_vertex_paint_mode() || VERTEX_COLORS_ENABLED(wpd)) { | ||||
| result = GPU_RGBA16; | result = GPU_RGBA16; | ||||
| } | } | ||||
| else { | else { | ||||
| result = GPU_RGBA8; | result = GPU_RGBA8; | ||||
| } | } | ||||
| return result; | return result; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | int workbench_material_determine_color_type(WORKBENCH_PrivateData *wpd, | ||||
| Image *ima, | Image *ima, | ||||
| Object *ob, | Object *ob, | ||||
| bool use_sculpt_pbvh); | bool use_sculpt_pbvh); | ||||
| void workbench_material_get_image_and_mat( | void workbench_material_get_image_and_mat( | ||||
| Object *ob, int mat_nr, Image **r_image, ImageUser **r_iuser, int *r_interp, Material **r_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, | char *workbench_material_build_defines(WORKBENCH_PrivateData *wpd, | ||||
| bool is_uniform_color, | bool is_uniform_color, | ||||
| bool is_hair, | bool is_hair, | ||||
| bool is_texture_painting); | const WORKBENCH_ColorOverride color_override); | ||||
| void workbench_material_update_data(WORKBENCH_PrivateData *wpd, | void workbench_material_update_data(WORKBENCH_PrivateData *wpd, | ||||
| Object *ob, | Object *ob, | ||||
| Material *mat, | Material *mat, | ||||
| WORKBENCH_MaterialData *data, | WORKBENCH_MaterialData *data, | ||||
| int color_type); | int color_type); | ||||
| uint workbench_material_get_hash(WORKBENCH_MaterialData *material_template, bool is_ghost); | uint workbench_material_get_hash(WORKBENCH_MaterialData *material_template, bool is_ghost); | ||||
| int workbench_material_get_composite_shader_index(WORKBENCH_PrivateData *wpd); | int workbench_material_get_composite_shader_index(WORKBENCH_PrivateData *wpd); | ||||
| int workbench_material_get_prepass_shader_index(WORKBENCH_PrivateData *wpd, | int workbench_material_get_prepass_shader_index(WORKBENCH_PrivateData *wpd, | ||||
| bool is_uniform_color, | bool is_uniform_color, | ||||
| bool is_hair, | bool is_hair, | ||||
| bool is_texture_painting); | const WORKBENCH_ColorOverride color_override); | ||||
| int workbench_material_get_accum_shader_index(WORKBENCH_PrivateData *wpd, | int workbench_material_get_accum_shader_index(WORKBENCH_PrivateData *wpd, | ||||
| bool is_uniform_color, | bool is_uniform_color, | ||||
| bool is_hair, | bool is_hair, | ||||
| bool is_texture_painting); | const WORKBENCH_ColorOverride color_override); | ||||
| void workbench_material_shgroup_uniform(WORKBENCH_PrivateData *wpd, | void workbench_material_shgroup_uniform(WORKBENCH_PrivateData *wpd, | ||||
| DRWShadingGroup *grp, | DRWShadingGroup *grp, | ||||
| WORKBENCH_MaterialData *material, | WORKBENCH_MaterialData *material, | ||||
| Object *ob, | Object *ob, | ||||
| const bool deferred, | const bool deferred, | ||||
| const int interp); | const int interp); | ||||
| void workbench_material_copy(WORKBENCH_MaterialData *dest_material, | void workbench_material_copy(WORKBENCH_MaterialData *dest_material, | ||||
| const WORKBENCH_MaterialData *source_material); | const WORKBENCH_MaterialData *source_material); | ||||
| ▲ Show 20 Lines • Show All 42 Lines • Show Last 20 Lines | |||||