Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/engines/gpencil/gpencil_shader_fx.c
| Show First 20 Lines • Show All 113 Lines • ▼ Show 20 Lines | static void GPENCIL_dof_nearfar(Object *camera, float coc, float nearfar[2]) | ||||
| const DRWContextState *draw_ctx = DRW_context_state_get(); | const DRWContextState *draw_ctx = DRW_context_state_get(); | ||||
| Scene *scene = draw_ctx->scene; | Scene *scene = draw_ctx->scene; | ||||
| Camera *cam = (Camera *)camera->data; | Camera *cam = (Camera *)camera->data; | ||||
| float fstop = cam->dof.aperture_fstop; | float fstop = cam->dof.aperture_fstop; | ||||
| float focus_dist = BKE_camera_object_dof_distance(camera); | float focus_dist = BKE_camera_object_dof_distance(camera); | ||||
| float focal_len = cam->lens; | float focal_len = cam->lens; | ||||
| /* This is factor that converts to the scene scale. focal length and sensor are expressed in mm | const float scale_camera = 0.001f; | ||||
| * unit.scale_length is how many meters per blender unit we have. We want to convert to blender | |||||
| * units though because the shader reads coordinates in world space, which is in blender units. | |||||
| * Note however that focus_distance is already in blender units and shall not be scaled here | |||||
| * (see T48157). */ | |||||
| float scale = (scene->unit.system) ? scene->unit.scale_length : 1.0f; | |||||
| float scale_camera = 0.001f / scale; | |||||
| /* we want radius here for the aperture number */ | /* we want radius here for the aperture number */ | ||||
| float aperture_scaled = 0.5f * scale_camera * focal_len / fstop; | float aperture_scaled = 0.5f * scale_camera * focal_len / fstop; | ||||
| float focal_len_scaled = scale_camera * focal_len; | float focal_len_scaled = scale_camera * focal_len; | ||||
| float hyperfocal = (focal_len_scaled * focal_len_scaled) / (aperture_scaled * coc); | float hyperfocal = (focal_len_scaled * focal_len_scaled) / (aperture_scaled * coc); | ||||
| nearfar[0] = (hyperfocal * focus_dist) / (hyperfocal + focal_len); | nearfar[0] = (hyperfocal * focus_dist) / (hyperfocal + focal_len); | ||||
| nearfar[1] = (hyperfocal * focus_dist) / (hyperfocal - focal_len); | nearfar[1] = (hyperfocal * focus_dist) / (hyperfocal - focal_len); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 947 Lines • Show Last 20 Lines | |||||