Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/engines/clay/clay_engine.c
| Show First 20 Lines • Show All 138 Lines • ▼ Show 20 Lines | |||||
| typedef struct CLAY_Data { | typedef struct CLAY_Data { | ||||
| void *engine_type; | void *engine_type; | ||||
| CLAY_FramebufferList *fbl; | CLAY_FramebufferList *fbl; | ||||
| DRWViewportEmptyList *txl; | DRWViewportEmptyList *txl; | ||||
| CLAY_PassList *psl; | CLAY_PassList *psl; | ||||
| CLAY_StorageList *stl; | CLAY_StorageList *stl; | ||||
| } CLAY_Data; | } CLAY_Data; | ||||
| typedef struct CLAY_SceneLayerData { | typedef struct CLAY_ViewLayerData { | ||||
| struct GPUTexture *jitter_tx; | struct GPUTexture *jitter_tx; | ||||
| struct GPUUniformBuffer *sampling_ubo; | struct GPUUniformBuffer *sampling_ubo; | ||||
| int cached_sample_num; | int cached_sample_num; | ||||
| } CLAY_SceneLayerData; | } CLAY_ViewLayerData; | ||||
| /* *********** STATIC *********** */ | /* *********** STATIC *********** */ | ||||
| static struct { | static struct { | ||||
| /* Depth Pre Pass */ | /* Depth Pre Pass */ | ||||
| struct GPUShader *depth_sh; | struct GPUShader *depth_sh; | ||||
| /* Shading Pass */ | /* Shading Pass */ | ||||
| struct GPUShader *clay_sh; | struct GPUShader *clay_sh; | ||||
| Show All 22 Lines | typedef struct CLAY_PrivateData { | ||||
| DRWShadingGroup *depth_shgrp_active; | DRWShadingGroup *depth_shgrp_active; | ||||
| DRWShadingGroup *depth_shgrp_cull; | DRWShadingGroup *depth_shgrp_cull; | ||||
| DRWShadingGroup *depth_shgrp_cull_select; | DRWShadingGroup *depth_shgrp_cull_select; | ||||
| DRWShadingGroup *depth_shgrp_cull_active; | DRWShadingGroup *depth_shgrp_cull_active; | ||||
| } CLAY_PrivateData; /* Transient data */ | } CLAY_PrivateData; /* Transient data */ | ||||
| /* Functions */ | /* Functions */ | ||||
| static void clay_scene_layer_data_free(void *storage) | static void clay_view_layer_data_free(void *storage) | ||||
| { | { | ||||
| CLAY_SceneLayerData *sldata = (CLAY_SceneLayerData *)storage; | CLAY_ViewLayerData *sldata = (CLAY_ViewLayerData *)storage; | ||||
| DRW_UBO_FREE_SAFE(sldata->sampling_ubo); | DRW_UBO_FREE_SAFE(sldata->sampling_ubo); | ||||
| DRW_TEXTURE_FREE_SAFE(sldata->jitter_tx); | DRW_TEXTURE_FREE_SAFE(sldata->jitter_tx); | ||||
| } | } | ||||
| static CLAY_SceneLayerData *CLAY_scene_layer_data_get(void) | static CLAY_ViewLayerData *CLAY_view_layer_data_get(void) | ||||
| { | { | ||||
| CLAY_SceneLayerData **sldata = (CLAY_SceneLayerData **)DRW_scene_layer_engine_data_get(&draw_engine_clay_type, &clay_scene_layer_data_free); | CLAY_ViewLayerData **sldata = (CLAY_ViewLayerData **)DRW_view_layer_engine_data_get(&draw_engine_clay_type, &clay_view_layer_data_free); | ||||
| if (*sldata == NULL) { | if (*sldata == NULL) { | ||||
| *sldata = MEM_callocN(sizeof(**sldata), "CLAY_SceneLayerData"); | *sldata = MEM_callocN(sizeof(**sldata), "CLAY_ViewLayerData"); | ||||
| } | } | ||||
| return *sldata; | return *sldata; | ||||
| } | } | ||||
| static void add_icon_to_rect(PreviewImage *prv, float *final_rect, int layer) | static void add_icon_to_rect(PreviewImage *prv, float *final_rect, int layer) | ||||
| { | { | ||||
| int image_size = prv->w[0] * prv->h[0]; | int image_size = prv->w[0] * prv->h[0]; | ||||
| ▲ Show 20 Lines • Show All 109 Lines • ▼ Show 20 Lines | static struct GPUTexture *create_jitter_texture(int num_samples) | ||||
| return DRW_texture_create_2D(64, 64, DRW_TEX_RGB_16, DRW_TEX_FILTER | DRW_TEX_WRAP, &jitter[0][0]); | return DRW_texture_create_2D(64, 64, DRW_TEX_RGB_16, DRW_TEX_FILTER | DRW_TEX_WRAP, &jitter[0][0]); | ||||
| } | } | ||||
| static void CLAY_engine_init(void *vedata) | static void CLAY_engine_init(void *vedata) | ||||
| { | { | ||||
| CLAY_StorageList *stl = ((CLAY_Data *)vedata)->stl; | CLAY_StorageList *stl = ((CLAY_Data *)vedata)->stl; | ||||
| CLAY_FramebufferList *fbl = ((CLAY_Data *)vedata)->fbl; | CLAY_FramebufferList *fbl = ((CLAY_Data *)vedata)->fbl; | ||||
| CLAY_SceneLayerData *sldata = CLAY_scene_layer_data_get(); | CLAY_ViewLayerData *sldata = CLAY_view_layer_data_get(); | ||||
| /* Create Texture Array */ | /* Create Texture Array */ | ||||
| if (!e_data.matcap_array) { | if (!e_data.matcap_array) { | ||||
| PreviewImage *prv[24]; /* For now use all of the 24 internal matcaps */ | PreviewImage *prv[24]; /* For now use all of the 24 internal matcaps */ | ||||
| /* TODO only load used matcaps */ | /* TODO only load used matcaps */ | ||||
| prv[0] = UI_icon_to_preview(ICON_MATCAP_01); | prv[0] = UI_icon_to_preview(ICON_MATCAP_01); | ||||
| prv[1] = UI_icon_to_preview(ICON_MATCAP_02); | prv[1] = UI_icon_to_preview(ICON_MATCAP_02); | ||||
| ▲ Show 20 Lines • Show All 81 Lines • ▼ Show 20 Lines | if (DRW_state_is_fbo()) { | ||||
| DRW_framebuffer_init(&fbl->dupli_depth, &draw_engine_clay_type, | DRW_framebuffer_init(&fbl->dupli_depth, &draw_engine_clay_type, | ||||
| (int)viewport_size[0], (int)viewport_size[1], | (int)viewport_size[0], (int)viewport_size[1], | ||||
| &tex, 1); | &tex, 1); | ||||
| } | } | ||||
| /* SSAO setup */ | /* SSAO setup */ | ||||
| { | { | ||||
| const DRWContextState *draw_ctx = DRW_context_state_get(); | const DRWContextState *draw_ctx = DRW_context_state_get(); | ||||
| SceneLayer *scene_layer = draw_ctx->scene_layer; | ViewLayer *view_layer = draw_ctx->view_layer; | ||||
| IDProperty *props = BKE_scene_layer_engine_evaluated_get( | IDProperty *props = BKE_view_layer_engine_evaluated_get( | ||||
| scene_layer, COLLECTION_MODE_NONE, RE_engine_id_BLENDER_CLAY); | view_layer, COLLECTION_MODE_NONE, RE_engine_id_BLENDER_CLAY); | ||||
| int ssao_samples = BKE_collection_engine_property_value_get_int(props, "ssao_samples"); | int ssao_samples = BKE_collection_engine_property_value_get_int(props, "ssao_samples"); | ||||
| float invproj[4][4]; | float invproj[4][4]; | ||||
| float dfdyfacs[2]; | float dfdyfacs[2]; | ||||
| const bool is_persp = DRW_viewport_is_persp_get(); | const bool is_persp = DRW_viewport_is_persp_get(); | ||||
| /* view vectors for the corners of the view frustum. | /* view vectors for the corners of the view frustum. | ||||
| * Can be used to recreate the world space position easily */ | * Can be used to recreate the world space position easily */ | ||||
| float viewvecs[3][4] = { | float viewvecs[3][4] = { | ||||
| ▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | if (sldata->sampling_ubo == NULL) { | ||||
| MEM_freeN(samples); | MEM_freeN(samples); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static DRWShadingGroup *CLAY_shgroup_create(CLAY_Data *vedata, DRWPass *pass, int *material_id, bool use_flat) | static DRWShadingGroup *CLAY_shgroup_create(CLAY_Data *vedata, DRWPass *pass, int *material_id, bool use_flat) | ||||
| { | { | ||||
| CLAY_StorageList *stl = vedata->stl; | CLAY_StorageList *stl = vedata->stl; | ||||
| CLAY_SceneLayerData *sldata = CLAY_scene_layer_data_get(); | CLAY_ViewLayerData *sldata = CLAY_view_layer_data_get(); | ||||
| DRWShadingGroup *grp = DRW_shgroup_create(use_flat ? e_data.clay_flat_sh : e_data.clay_sh, pass); | DRWShadingGroup *grp = DRW_shgroup_create(use_flat ? e_data.clay_flat_sh : e_data.clay_sh, pass); | ||||
| DRW_shgroup_uniform_vec2(grp, "screenres", DRW_viewport_size_get(), 1); | DRW_shgroup_uniform_vec2(grp, "screenres", DRW_viewport_size_get(), 1); | ||||
| DRW_shgroup_uniform_buffer(grp, "depthtex", &e_data.depth_dup); | DRW_shgroup_uniform_buffer(grp, "depthtex", &e_data.depth_dup); | ||||
| DRW_shgroup_uniform_texture(grp, "matcaps", e_data.matcap_array); | DRW_shgroup_uniform_texture(grp, "matcaps", e_data.matcap_array); | ||||
| DRW_shgroup_uniform_mat4(grp, "WinMatrix", (float *)e_data.winmat); | DRW_shgroup_uniform_mat4(grp, "WinMatrix", (float *)e_data.winmat); | ||||
| DRW_shgroup_uniform_vec4(grp, "viewvecs[0]", (float *)e_data.viewvecs, 3); | DRW_shgroup_uniform_vec4(grp, "viewvecs[0]", (float *)e_data.viewvecs, 3); | ||||
| DRW_shgroup_uniform_vec4(grp, "ssao_params", e_data.ssao_params, 1); | DRW_shgroup_uniform_vec4(grp, "ssao_params", e_data.ssao_params, 1); | ||||
| ▲ Show 20 Lines • Show All 371 Lines • ▼ Show 20 Lines | static void CLAY_layer_collection_settings_create(RenderEngine *UNUSED(engine), IDProperty *props) | ||||
| BKE_collection_engine_property_add_float(props, "matcap_value", 0.5f); | BKE_collection_engine_property_add_float(props, "matcap_value", 0.5f); | ||||
| BKE_collection_engine_property_add_float(props, "ssao_distance", 0.2f); | BKE_collection_engine_property_add_float(props, "ssao_distance", 0.2f); | ||||
| BKE_collection_engine_property_add_float(props, "ssao_attenuation", 1.0f); | BKE_collection_engine_property_add_float(props, "ssao_attenuation", 1.0f); | ||||
| BKE_collection_engine_property_add_float(props, "ssao_factor_cavity", 1.0f); | BKE_collection_engine_property_add_float(props, "ssao_factor_cavity", 1.0f); | ||||
| BKE_collection_engine_property_add_float(props, "ssao_factor_edge", 1.0f); | BKE_collection_engine_property_add_float(props, "ssao_factor_edge", 1.0f); | ||||
| BKE_collection_engine_property_add_float(props, "hair_brightness_randomness", 0.0f); | BKE_collection_engine_property_add_float(props, "hair_brightness_randomness", 0.0f); | ||||
| } | } | ||||
| static void CLAY_scene_layer_settings_create(RenderEngine *UNUSED(engine), IDProperty *props) | static void CLAY_view_layer_settings_create(RenderEngine *UNUSED(engine), IDProperty *props) | ||||
| { | { | ||||
| BLI_assert(props && | BLI_assert(props && | ||||
| props->type == IDP_GROUP && | props->type == IDP_GROUP && | ||||
| props->subtype == IDP_GROUP_SUB_ENGINE_RENDER); | props->subtype == IDP_GROUP_SUB_ENGINE_RENDER); | ||||
| BKE_collection_engine_property_add_int(props, "ssao_samples", 16); | BKE_collection_engine_property_add_int(props, "ssao_samples", 16); | ||||
| } | } | ||||
| Show All 21 Lines | DrawEngineType draw_engine_clay_type = { | ||||
| NULL, | NULL, | ||||
| }; | }; | ||||
| RenderEngineType DRW_engine_viewport_clay_type = { | RenderEngineType DRW_engine_viewport_clay_type = { | ||||
| NULL, NULL, | NULL, NULL, | ||||
| CLAY_ENGINE, N_("Clay"), RE_INTERNAL, | CLAY_ENGINE, N_("Clay"), RE_INTERNAL, | ||||
| NULL, NULL, NULL, NULL, NULL, NULL, NULL, | NULL, NULL, NULL, NULL, NULL, NULL, NULL, | ||||
| &CLAY_layer_collection_settings_create, | &CLAY_layer_collection_settings_create, | ||||
| &CLAY_scene_layer_settings_create, | &CLAY_view_layer_settings_create, | ||||
| &draw_engine_clay_type, | &draw_engine_clay_type, | ||||
| {NULL, NULL, NULL} | {NULL, NULL, NULL} | ||||
| }; | }; | ||||
| #undef CLAY_ENGINE | #undef CLAY_ENGINE | ||||
| #endif | #endif | ||||