Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/engines/eevee/eevee_effects.c
| Context not available. | |||||
| #define ENABLE_EFFECT_MOTION_BLUR 1 | #define ENABLE_EFFECT_MOTION_BLUR 1 | ||||
| #define ENABLE_EFFECT_BLOOM 1 | #define ENABLE_EFFECT_BLOOM 1 | ||||
| #define ENABLE_EFFECT_DOF 1 | #define ENABLE_EFFECT_DOF 1 | ||||
| #define ENABLE_EFFECT_FXAA 1 | |||||
| static struct { | static struct { | ||||
| /* Motion Blur */ | /* Motion Blur */ | ||||
| Context not available. | |||||
| struct GPUShader *dof_downsample_sh; | struct GPUShader *dof_downsample_sh; | ||||
| struct GPUShader *dof_scatter_sh; | struct GPUShader *dof_scatter_sh; | ||||
| struct GPUShader *dof_resolve_sh; | struct GPUShader *dof_resolve_sh; | ||||
| /* FXAA */ | |||||
| struct GPUShader *fxaa_sh[3]; | |||||
| float rcp_dim[2]; | |||||
| } e_data = {NULL}; /* Engine data */ | } e_data = {NULL}; /* Engine data */ | ||||
| extern char datatoc_effect_motion_blur_frag_glsl[]; | extern char datatoc_effect_motion_blur_frag_glsl[]; | ||||
| Context not available. | |||||
| extern char datatoc_effect_dof_geom_glsl[]; | extern char datatoc_effect_dof_geom_glsl[]; | ||||
| extern char datatoc_effect_dof_frag_glsl[]; | extern char datatoc_effect_dof_frag_glsl[]; | ||||
| extern char datatoc_tonemap_frag_glsl[]; | extern char datatoc_tonemap_frag_glsl[]; | ||||
| extern char datatoc_effect_fxaa_frag_glsl[]; | |||||
| static void eevee_motion_blur_camera_get_matrix_at_time( | static void eevee_motion_blur_camera_get_matrix_at_time( | ||||
| Scene *scene, ARegion *ar, RegionView3D *rv3d, View3D *v3d, Object *camera, float time, float r_mat[4][4]) | Scene *scene, ARegion *ar, RegionView3D *rv3d, View3D *v3d, Object *camera, float time, float r_mat[4][4]) | ||||
| Context not available. | |||||
| const float *viewport_size = DRW_viewport_size_get(); | const float *viewport_size = DRW_viewport_size_get(); | ||||
| e_data.rcp_dim[0] = 1/viewport_size[0]; | |||||
| e_data.rcp_dim[1] = 1/viewport_size[1]; | |||||
| if (!e_data.motion_blur_sh) { | if (!e_data.motion_blur_sh) { | ||||
| e_data.motion_blur_sh = DRW_shader_create_fullscreen(datatoc_effect_motion_blur_frag_glsl, NULL); | e_data.motion_blur_sh = DRW_shader_create_fullscreen(datatoc_effect_motion_blur_frag_glsl, NULL); | ||||
| } | } | ||||
| Context not available. | |||||
| "#define HIGH_QUALITY\n"); | "#define HIGH_QUALITY\n"); | ||||
| } | } | ||||
| if (!e_data.fxaa_sh[0]) { | |||||
| e_data.fxaa_sh[0] = DRW_shader_create_fullscreen(datatoc_effect_fxaa_frag_glsl, | |||||
| "#define FXAA_GATHER4_ALPHA 0\n" | |||||
| "#define FXAA_QUALITY__PRESET 39\n"); | |||||
| e_data.fxaa_sh[1] = DRW_shader_create_fullscreen(datatoc_effect_fxaa_frag_glsl, | |||||
| "#define FXAA_GATHER4_ALPHA 0\n" | |||||
| "#define BL_FXAA_PAINT_DIFFERENCE 1\n" | |||||
| "#define FXAA_QUALITY__PRESET 39\n"); | |||||
| e_data.fxaa_sh[2] = DRW_shader_create_fullscreen(datatoc_effect_fxaa_frag_glsl, | |||||
| "#define FXAA_GATHER4_ALPHA 0\n" | |||||
| "#define BL_FXAA_PAINT_CANDIDATES 1\n" | |||||
| "#define FXAA_QUALITY__PRESET 39\n"); | |||||
| } | |||||
| if (!stl->effects) { | if (!stl->effects) { | ||||
| stl->effects = MEM_callocN(sizeof(EEVEE_EffectsInfo), "EEVEE_EffectsInfo"); | stl->effects = MEM_callocN(sizeof(EEVEE_EffectsInfo), "EEVEE_EffectsInfo"); | ||||
| } | } | ||||
| Context not available. | |||||
| } | } | ||||
| #endif /* ENABLE_EFFECT_DOF */ | #endif /* ENABLE_EFFECT_DOF */ | ||||
| #ifdef ENABLE_EFFECT_FXAA | |||||
| if (BKE_collection_engine_property_value_get_bool(props, "fxaa_enable")) { | |||||
| enabled_effects |= EFFECT_FXAA; | |||||
| DRWFboTexture tex_fxaa_input = {&txl->fxaa_input_tex, DRW_TEX_RGBA_8, DRW_TEX_FILTER}; | |||||
| DRW_framebuffer_init(&fbl->fxaa_input_fb, &draw_engine_eevee_type, viewport_size[0], viewport_size[1], &tex_fxaa_input, 1); | |||||
| } | |||||
| effects->fxaa_shader_option = BKE_collection_engine_property_value_get_int(props, "fxaa_shader_option"); | |||||
| effects->fxaa_tuning_parameters[0] = BKE_collection_engine_property_value_get_float(props, "fxaa_subpix"); | |||||
| effects->fxaa_tuning_parameters[1] = BKE_collection_engine_property_value_get_float(props, "fxaa_edge_threshold"); | |||||
| effects->fxaa_tuning_parameters[2] = BKE_collection_engine_property_value_get_float(props, "fxaa_edge_threshold_min"); | |||||
| #endif /* ENABLE_EFFECT_FXAA */ | |||||
| effects->enabled_effects = enabled_effects; | effects->enabled_effects = enabled_effects; | ||||
| /* Only allocate if at least one effect is activated */ | /* Only allocate if at least one effect is activated */ | ||||
| Context not available. | |||||
| EEVEE_TextureList *txl = vedata->txl; | EEVEE_TextureList *txl = vedata->txl; | ||||
| EEVEE_EffectsInfo *effects = stl->effects; | EEVEE_EffectsInfo *effects = stl->effects; | ||||
| DefaultTextureList *dtxl = DRW_viewport_texture_list_get(); | DefaultTextureList *dtxl = DRW_viewport_texture_list_get(); | ||||
| const float *viewport_size = DRW_viewport_size_get(); | |||||
| struct Batch *quad = DRW_cache_fullscreen_quad_get(); | struct Batch *quad = DRW_cache_fullscreen_quad_get(); | ||||
| Context not available. | |||||
| /* This create an empty batch of N triangles to be positioned | /* This create an empty batch of N triangles to be positioned | ||||
| * by the vertex shader 0.4ms against 6ms with instancing */ | * by the vertex shader 0.4ms against 6ms with instancing */ | ||||
| const float *viewport_size = DRW_viewport_size_get(); | |||||
| const int sprite_ct = ((int)viewport_size[0]/2) * ((int)viewport_size[1]/2); /* brackets matters */ | const int sprite_ct = ((int)viewport_size[0]/2) * ((int)viewport_size[1]/2); /* brackets matters */ | ||||
| grp = DRW_shgroup_empty_tri_batch_create(e_data.dof_scatter_sh, psl->dof_scatter, sprite_ct); | grp = DRW_shgroup_empty_tri_batch_create(e_data.dof_scatter_sh, psl->dof_scatter, sprite_ct); | ||||
| Context not available. | |||||
| DRW_shgroup_uniform_vec3(grp, "dofParams", effects->dof_params, 1); | DRW_shgroup_uniform_vec3(grp, "dofParams", effects->dof_params, 1); | ||||
| DRW_shgroup_call_add(grp, quad, NULL); | DRW_shgroup_call_add(grp, quad, NULL); | ||||
| } | } | ||||
| /* FXAA */ | |||||
| { | |||||
LazyDodo: What's going on with the braces here? | |||||
cmrAuthorUnsubmitted Not Done Inline ActionsThey're blocks. They scope the local variables (eg, grp). cmr: They're blocks. They scope the local variables (eg, `grp`). | |||||
| psl->fxaa_pass = DRW_pass_create("FXAA", DRW_STATE_WRITE_COLOR); | |||||
| DRWShadingGroup *grp = DRW_shgroup_create(e_data.fxaa_sh[effects->fxaa_shader_option], psl->fxaa_pass); | |||||
| DRW_shgroup_uniform_buffer(grp, "colorBuffer", &txl->fxaa_input_tex); | |||||
| DRW_shgroup_uniform_vec2(grp, "rcpDimensions", e_data.rcp_dim, 1); | |||||
| DRW_shgroup_uniform_vec3(grp, "TuningParameters", effects->fxaa_tuning_parameters, 1); | |||||
| DRW_shgroup_call_add(grp, quad, NULL); | |||||
| } | |||||
| } | } | ||||
| #define SWAP_BUFFERS() { \ | #define SWAP_BUFFERS() { \ | ||||
| Context not available. | |||||
| SWAP_BUFFERS(); | SWAP_BUFFERS(); | ||||
| } | } | ||||
| /* Restore default framebuffer */ | /* Restore default framebuffer */ | ||||
| DRW_framebuffer_texture_attach(dfbl->default_fb, dtxl->depth, 0, 0); | DRW_framebuffer_texture_attach(dfbl->default_fb, dtxl->depth, 0, 0); | ||||
| DRW_framebuffer_bind(dfbl->default_fb); | |||||
| if ((effects->enabled_effects & EFFECT_FXAA) != 0) { | |||||
| DRW_framebuffer_bind(fbl->fxaa_input_fb); | |||||
| } else { | |||||
| DRW_framebuffer_bind(dfbl->default_fb); | |||||
| } | |||||
| /* Tonemapping */ | /* Tonemapping */ | ||||
| DRW_transform_to_display(effects->source_buffer); | DRW_transform_to_display(effects->source_buffer); | ||||
| /* FXAA is explicitly after tonemapping! */ | |||||
| if ((effects->enabled_effects & EFFECT_FXAA) != 0) { | |||||
| DRW_framebuffer_bind(dfbl->default_fb); | |||||
| DRW_draw_pass(psl->fxaa_pass); | |||||
| } | |||||
| } | } | ||||
| void EEVEE_effects_free(void) | void EEVEE_effects_free(void) | ||||
| Context not available. | |||||
| DRW_SHADER_FREE_SAFE(e_data.dof_downsample_sh); | DRW_SHADER_FREE_SAFE(e_data.dof_downsample_sh); | ||||
| DRW_SHADER_FREE_SAFE(e_data.dof_scatter_sh); | DRW_SHADER_FREE_SAFE(e_data.dof_scatter_sh); | ||||
| DRW_SHADER_FREE_SAFE(e_data.dof_resolve_sh); | DRW_SHADER_FREE_SAFE(e_data.dof_resolve_sh); | ||||
| DRW_SHADER_FREE_SAFE(e_data.fxaa_sh[0]); | |||||
| DRW_SHADER_FREE_SAFE(e_data.fxaa_sh[1]); | |||||
| DRW_SHADER_FREE_SAFE(e_data.fxaa_sh[2]); | |||||
| DRW_SHADER_FREE_SAFE(e_data.bloom_blit_sh[0]); | DRW_SHADER_FREE_SAFE(e_data.bloom_blit_sh[0]); | ||||
| DRW_SHADER_FREE_SAFE(e_data.bloom_downsample_sh[0]); | DRW_SHADER_FREE_SAFE(e_data.bloom_downsample_sh[0]); | ||||
| Context not available. | |||||
| DRW_SHADER_FREE_SAFE(e_data.bloom_downsample_sh[1]); | DRW_SHADER_FREE_SAFE(e_data.bloom_downsample_sh[1]); | ||||
| DRW_SHADER_FREE_SAFE(e_data.bloom_upsample_sh[1]); | DRW_SHADER_FREE_SAFE(e_data.bloom_upsample_sh[1]); | ||||
| DRW_SHADER_FREE_SAFE(e_data.bloom_resolve_sh[1]); | DRW_SHADER_FREE_SAFE(e_data.bloom_resolve_sh[1]); | ||||
| } | } | ||||
| No newline at end of file | |||||
| Context not available. | |||||
What's going on with the braces here?