Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/engines/eevee/eevee_lookdev.c
| Show First 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | static void eevee_lookdev_lightcache_delete(EEVEE_Data *vedata) | ||||
| MEM_SAFE_FREE(stl->lookdev_cube_data); | MEM_SAFE_FREE(stl->lookdev_cube_data); | ||||
| DRW_TEXTURE_FREE_SAFE(txl->lookdev_grid_tx); | DRW_TEXTURE_FREE_SAFE(txl->lookdev_grid_tx); | ||||
| DRW_TEXTURE_FREE_SAFE(txl->lookdev_cube_tx); | DRW_TEXTURE_FREE_SAFE(txl->lookdev_cube_tx); | ||||
| g_data->studiolight_index = -1; | g_data->studiolight_index = -1; | ||||
| g_data->studiolight_rot_z = 0.0f; | g_data->studiolight_rot_z = 0.0f; | ||||
| } | } | ||||
| void EEVEE_lookdev_cache_init(EEVEE_Data *vedata, | void EEVEE_lookdev_cache_init(EEVEE_Data *vedata, | ||||
| DRWShadingGroup **grp, | EEVEE_ViewLayerData *sldata, | ||||
| DRWShadingGroup **r_grp, | |||||
| DRWPass *pass, | DRWPass *pass, | ||||
| float background_alpha, | |||||
| World *UNUSED(world), | World *UNUSED(world), | ||||
| EEVEE_LightProbesInfo *pinfo) | EEVEE_LightProbesInfo *pinfo) | ||||
| { | { | ||||
| EEVEE_StorageList *stl = vedata->stl; | EEVEE_StorageList *stl = vedata->stl; | ||||
| EEVEE_TextureList *txl = vedata->txl; | EEVEE_TextureList *txl = vedata->txl; | ||||
| EEVEE_EffectsInfo *effects = stl->effects; | EEVEE_EffectsInfo *effects = stl->effects; | ||||
| EEVEE_PrivateData *g_data = stl->g_data; | EEVEE_PrivateData *g_data = stl->g_data; | ||||
| const DRWContextState *draw_ctx = DRW_context_state_get(); | const DRWContextState *draw_ctx = DRW_context_state_get(); | ||||
| View3D *v3d = draw_ctx->v3d; | View3D *v3d = draw_ctx->v3d; | ||||
| View3DShading *shading = &v3d->shading; | |||||
| Scene *scene = draw_ctx->scene; | Scene *scene = draw_ctx->scene; | ||||
| const bool probe_render = pinfo != NULL; | |||||
| effects->lookdev_view = NULL; | effects->lookdev_view = NULL; | ||||
| if (LOOK_DEV_OVERLAY_ENABLED(v3d)) { | if (LOOK_DEV_OVERLAY_ENABLED(v3d)) { | ||||
| /* Viewport / Spheres size. */ | /* Viewport / Spheres size. */ | ||||
| const rcti *rect = ED_region_visible_rect(draw_ctx->ar); | const rcti *rect = ED_region_visible_rect(draw_ctx->ar); | ||||
| /* Make the viewport width scale the lookdev spheres a bit. | /* Make the viewport width scale the lookdev spheres a bit. | ||||
| * Scale between 1000px and 2000px. */ | * Scale between 1000px and 2000px. */ | ||||
| const float viewport_scale = clamp_f( | const float viewport_scale = clamp_f( | ||||
| BLI_rcti_size_x(rect) / (2000.0f * U.dpi_fac), 0.5f, 1.0f); | BLI_rcti_size_x(rect) / (2000.0f * U.dpi_fac), 0.5f, 1.0f); | ||||
| const int sphere_size = U.lookdev_sphere_size * U.dpi_fac * viewport_scale; | const int sphere_size = U.lookdev_sphere_size * U.dpi_fac * viewport_scale; | ||||
| if (sphere_size != effects->sphere_size || rect->xmax != effects->anchor[0] || | if (sphere_size != effects->sphere_size || rect->xmax != effects->anchor[0] || | ||||
| rect->ymin != effects->anchor[1]) { | rect->ymin != effects->anchor[1]) { | ||||
| /* If sphere size or anchor point moves, reset TAA to avoid ghosting issue. | /* If sphere size or anchor point moves, reset TAA to avoid ghosting issue. | ||||
| * This needs to happen early because we are changing taa_current_sample. */ | * This needs to happen early because we are changing taa_current_sample. */ | ||||
| effects->sphere_size = sphere_size; | effects->sphere_size = sphere_size; | ||||
| effects->anchor[0] = rect->xmax; | effects->anchor[0] = rect->xmax; | ||||
| effects->anchor[1] = rect->ymin; | effects->anchor[1] = rect->ymin; | ||||
| EEVEE_temporal_sampling_reset(vedata); | EEVEE_temporal_sampling_reset(vedata); | ||||
| } | } | ||||
| } | } | ||||
| if (LOOK_DEV_STUDIO_LIGHT_ENABLED(v3d)) { | if (LOOK_DEV_STUDIO_LIGHT_ENABLED(v3d)) { | ||||
| StudioLight *sl = BKE_studiolight_find(v3d->shading.lookdev_light, | StudioLight *sl = BKE_studiolight_find(shading->lookdev_light, | ||||
| STUDIOLIGHT_ORIENTATIONS_MATERIAL_MODE); | STUDIOLIGHT_ORIENTATIONS_MATERIAL_MODE); | ||||
| if (sl && (sl->flag & STUDIOLIGHT_TYPE_WORLD)) { | if (sl && (sl->flag & STUDIOLIGHT_TYPE_WORLD)) { | ||||
| GPUShader *shader = EEVEE_shaders_default_studiolight_sh_get(); | GPUShader *shader = probe_render ? EEVEE_shaders_default_studiolight_sh_get() : | ||||
| struct GPUBatch *geom = DRW_cache_fullscreen_quad_get(); | EEVEE_shaders_background_studiolight_sh_get(); | ||||
| GPUTexture *tex = NULL; | |||||
| /* If one of the component is missing we start from scratch. */ | /* If one of the component is missing we start from scratch. */ | ||||
| if ((stl->lookdev_grid_data == NULL) || (stl->lookdev_cube_data == NULL) || | if ((stl->lookdev_grid_data == NULL) || (stl->lookdev_cube_data == NULL) || | ||||
| (txl->lookdev_grid_tx == NULL) || (txl->lookdev_cube_tx == NULL)) { | (txl->lookdev_grid_tx == NULL) || (txl->lookdev_cube_tx == NULL)) { | ||||
| eevee_lookdev_lightcache_delete(vedata); | eevee_lookdev_lightcache_delete(vedata); | ||||
| } | } | ||||
| if (stl->lookdev_lightcache == NULL) { | if (stl->lookdev_lightcache == NULL) { | ||||
| Show All 21 Lines | #endif | ||||
| * to the stl. */ | * to the stl. */ | ||||
| stl->lookdev_grid_data = stl->lookdev_lightcache->grid_data; | stl->lookdev_grid_data = stl->lookdev_lightcache->grid_data; | ||||
| stl->lookdev_cube_data = stl->lookdev_lightcache->cube_data; | stl->lookdev_cube_data = stl->lookdev_lightcache->cube_data; | ||||
| stl->lookdev_cube_mips = stl->lookdev_lightcache->cube_mips; | stl->lookdev_cube_mips = stl->lookdev_lightcache->cube_mips; | ||||
| txl->lookdev_grid_tx = stl->lookdev_lightcache->grid_tx.tex; | txl->lookdev_grid_tx = stl->lookdev_lightcache->grid_tx.tex; | ||||
| txl->lookdev_cube_tx = stl->lookdev_lightcache->cube_tx.tex; | txl->lookdev_cube_tx = stl->lookdev_lightcache->cube_tx.tex; | ||||
| } | } | ||||
| stl->g_data->light_cache = stl->lookdev_lightcache; | g_data->light_cache = stl->lookdev_lightcache; | ||||
| static float background_color[4]; | DRWShadingGroup *grp = *r_grp = DRW_shgroup_create(shader, pass); | ||||
| UI_GetThemeColor4fv(TH_BACK, background_color); | axis_angle_to_mat3_single(g_data->studiolight_matrix, 'Z', shading->studiolight_rot_z); | ||||
| /* XXX: Really quick conversion to avoid washed out background. | DRW_shgroup_uniform_mat3(grp, "StudioLightMatrix", g_data->studiolight_matrix); | ||||
| * Needs to be addressed properly (color managed using ocio). */ | |||||
| srgb_to_linearrgb_v4(background_color, background_color); | if (probe_render) { | ||||
| DRW_shgroup_uniform_float_copy( | |||||
| *grp = DRW_shgroup_create(shader, pass); | grp, "studioLightIntensity", shading->studiolight_intensity); | ||||
| axis_angle_to_mat3_single( | BKE_studiolight_ensure_flag(sl, STUDIOLIGHT_EQUIRECT_RADIANCE_GPUTEXTURE); | ||||
| stl->g_data->studiolight_matrix, 'Z', v3d->shading.studiolight_rot_z); | DRW_shgroup_uniform_texture(grp, "image", sl->equirect_radiance_gputexture); | ||||
| DRW_shgroup_uniform_mat3(*grp, "StudioLightMatrix", stl->g_data->studiolight_matrix); | |||||
| DRW_shgroup_uniform_float_copy(*grp, "backgroundAlpha", background_alpha); | |||||
| DRW_shgroup_uniform_float( | |||||
| *grp, "studioLightIntensity", &v3d->shading.studiolight_intensity, 1); | |||||
| DRW_shgroup_uniform_vec3(*grp, "color", background_color, 1); | |||||
| DRW_shgroup_call(*grp, geom, NULL); | |||||
| if (!pinfo) { | |||||
| /* Do not fadeout when doing probe rendering, only when drawing the background */ | /* Do not fadeout when doing probe rendering, only when drawing the background */ | ||||
| DRW_shgroup_uniform_float( | DRW_shgroup_uniform_float_copy(grp, "backgroundAlpha", 1.0f); | ||||
| *grp, "studioLightBackground", &v3d->shading.studiolight_background, 1); | |||||
| BKE_studiolight_ensure_flag(sl, STUDIOLIGHT_EQUIRECT_IRRADIANCE_GPUTEXTURE); | |||||
| tex = sl->equirect_irradiance_gputexture; | |||||
| } | } | ||||
| else { | else { | ||||
| DRW_shgroup_uniform_float_copy(*grp, "studioLightBackground", 1.0f); | float background_alpha = g_data->background_alpha * shading->studiolight_background; | ||||
| BKE_studiolight_ensure_flag(sl, STUDIOLIGHT_EQUIRECT_RADIANCE_GPUTEXTURE); | float studiolight_blur = powf(shading->studiolight_blur, 2.5f); | ||||
| tex = sl->equirect_radiance_gputexture; | DRW_shgroup_uniform_float_copy(grp, "backgroundAlpha", background_alpha); | ||||
| DRW_shgroup_uniform_float_copy(grp, "studioLightBlur", studiolight_blur); | |||||
| DRW_shgroup_uniform_texture(grp, "probeCubes", txl->lookdev_cube_tx); | |||||
| DRW_shgroup_uniform_block(grp, "probe_block", sldata->probe_ubo); | |||||
| DRW_shgroup_uniform_block(grp, "grid_block", sldata->grid_ubo); | |||||
| DRW_shgroup_uniform_block(grp, "planar_block", sldata->planar_ubo); | |||||
| DRW_shgroup_uniform_block(grp, "common_block", sldata->common_ubo); | |||||
| } | } | ||||
| DRW_shgroup_uniform_texture(*grp, "image", tex); | |||||
| DRW_shgroup_call(grp, DRW_cache_fullscreen_quad_get(), NULL); | |||||
| /* Do we need to recalc the lightprobes? */ | /* Do we need to recalc the lightprobes? */ | ||||
| if (g_data->studiolight_index != sl->index || | if (g_data->studiolight_index != sl->index || | ||||
| g_data->studiolight_rot_z != v3d->shading.studiolight_rot_z || | g_data->studiolight_rot_z != shading->studiolight_rot_z || | ||||
| g_data->studiolight_intensity != v3d->shading.studiolight_intensity || | g_data->studiolight_intensity != shading->studiolight_intensity || | ||||
| g_data->studiolight_cubemap_res != scene->eevee.gi_cubemap_resolution || | g_data->studiolight_cubemap_res != scene->eevee.gi_cubemap_resolution || | ||||
| g_data->studiolight_glossy_clamp != scene->eevee.gi_glossy_clamp || | g_data->studiolight_glossy_clamp != scene->eevee.gi_glossy_clamp || | ||||
| g_data->studiolight_filter_quality != scene->eevee.gi_filter_quality) { | g_data->studiolight_filter_quality != scene->eevee.gi_filter_quality) { | ||||
| stl->lookdev_lightcache->flag |= LIGHTCACHE_UPDATE_WORLD; | stl->lookdev_lightcache->flag |= LIGHTCACHE_UPDATE_WORLD; | ||||
| g_data->studiolight_index = sl->index; | g_data->studiolight_index = sl->index; | ||||
| g_data->studiolight_rot_z = v3d->shading.studiolight_rot_z; | g_data->studiolight_rot_z = shading->studiolight_rot_z; | ||||
| g_data->studiolight_intensity = v3d->shading.studiolight_intensity; | g_data->studiolight_intensity = shading->studiolight_intensity; | ||||
| g_data->studiolight_cubemap_res = scene->eevee.gi_cubemap_resolution; | g_data->studiolight_cubemap_res = scene->eevee.gi_cubemap_resolution; | ||||
| g_data->studiolight_glossy_clamp = scene->eevee.gi_glossy_clamp; | g_data->studiolight_glossy_clamp = scene->eevee.gi_glossy_clamp; | ||||
| g_data->studiolight_filter_quality = scene->eevee.gi_filter_quality; | g_data->studiolight_filter_quality = scene->eevee.gi_filter_quality; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 98 Lines • Show Last 20 Lines | |||||