58void DofPass::setup_samples()
61 for (
int i = 0; i <= kernel_radius_; i++) {
62 for (
int j = -kernel_radius_; j <= kernel_radius_; j++) {
63 for (
int k = -kernel_radius_; k <= kernel_radius_; k++) {
64 if (
abs(j) > i ||
abs(k) > i) {
67 if (
abs(j) < i &&
abs(k) < i) {
92 samples_buf_.push_update();
101 coc_halfres_tx_.free();
108 half_res = {
max_ii(half_res.x, 1),
max_ii(half_res.y, 1)};
111 source_tx_.ensure_2d(
GPU_RGBA16F, half_res, usage,
nullptr, 3);
112 source_tx_.ensure_mip_views();
113 source_tx_.filter_mode(
true);
114 coc_halfres_tx_.ensure_2d(
GPU_RG8, half_res, usage,
nullptr, 3);
115 coc_halfres_tx_.ensure_mip_views();
116 coc_halfres_tx_.filter_mode(
true);
121 float fstop =
camera->dof.aperture_fstop;
124 float focal_len =
camera->lens;
127 const float scale_camera = 0.001f;
129 float aperture = 0.5f * scale_camera * focal_len / fstop;
130 float focal_len_scaled = scale_camera * focal_len;
131 float sensor_scaled = scale_camera * sensor;
134 sensor_scaled *= rv3d->viewcamtexcofac[0];
137 aperture_size_ = aperture *
fabsf(focal_len_scaled / (focus_dist - focal_len_scaled));
138 distance_ = -focus_dist;
139 invsensor_size_ = scene_state.
resolution.x / sensor_scaled;
141 near_ = -
camera->clip_start;
144 float blades =
camera->dof.aperture_blades;
145 float rotation =
camera->dof.aperture_rotation;
146 float ratio = 1.0f /
camera->dof.aperture_ratio;
148 if (blades_ != blades || rotation_ != rotation || ratio_ != ratio) {
150 rotation_ = rotation;
167 down_ps_.bind_texture(
"sceneColorTex", &resources.
color_tx);
168 down_ps_.bind_texture(
"sceneDepthTex", &resources.
depth_tx);
170 down_ps_.push_constant(
"dofParams",
float3(aperture_size_, distance_, invsensor_size_));
171 down_ps_.push_constant(
"nearFar",
float2(near_, far_));
177 down2_ps_.bind_texture(
"sceneColorTex", &source_tx_, sampler_state);
178 down2_ps_.bind_texture(
"inputCocTex", &coc_halfres_tx_, sampler_state);
184 blur_ps_.bind_ubo(
"samples", samples_buf_);
185 blur_ps_.bind_texture(
"noiseTex", resources.
jitter_tx);
186 blur_ps_.bind_texture(
"inputCocTex", &coc_halfres_tx_, sampler_state);
187 blur_ps_.bind_texture(
"halfResColorTex", &source_tx_, sampler_state);
189 blur_ps_.push_constant(
"noiseOffset", offset_);
195 blur2_ps_.bind_texture(
"inputCocTex", &coc_halfres_tx_, sampler_state);
196 blur2_ps_.bind_texture(
"blurTex", &blur_tx_);
203 resolve_ps_.bind_texture(
"halfResColorTex", &source_tx_, sampler_state);
204 resolve_ps_.bind_texture(
"sceneDepthTex", &resources.
depth_tx);
206 resolve_ps_.push_constant(
"dofParams",
float3(aperture_size_, distance_, invsensor_size_));
207 resolve_ps_.push_constant(
"nearFar",
float2(near_, far_));
226 downsample_fb_.bind();
229 struct CallbackData {
234 CallbackData callback_data = {manager,
view, down2_ps_};
236 auto downsample_level = [](
void *callback_data,
int ) {
237 CallbackData *cd =
static_cast<CallbackData *
>(callback_data);
238 cd->manager.submit(cd->pass, cd->view);
242 downsample_fb_, 2, downsample_level,
static_cast<void *
>(&callback_data));
Camera data-block and utility functions.
float BKE_camera_sensor_size(int sensor_fit, float sensor_x, float sensor_y)
float BKE_camera_object_dof_distance(const struct Object *ob)
MINLINE int max_ii(int a, int b)
#define GPU_ATTACHMENT_TEXTURE(_texture)
#define GPU_ATTACHMENT_NONE
void GPU_framebuffer_recursive_downsample(GPUFrameBuffer *framebuffer, int max_level, void(*per_level_callback)(void *user_data, int level), void *user_data)
@ GPU_TEXTURE_USAGE_SHADER_READ
@ GPU_TEXTURE_USAGE_ATTACHMENT
@ GPU_SAMPLER_FILTERING_MIPMAP
@ GPU_SAMPLER_FILTERING_LINEAR
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Gabor Generate Gabor noise Gradient Generate interpolated color and intensity values based on the input vector Magic Generate a psychedelic color texture Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks Texture Retrieve multiple types of texture coordinates nTypically used as inputs for texture nodes Vector Convert a or normal between camera
void submit(PassSimple &pass, View &view)
void sync(SceneResources &resources)
void draw(Manager &manager, View &view, SceneResources &resources, int2 resolution)
void init(const SceneState &scene_state)
static ShaderCache & get()
const float * DRW_viewport_invert_size_get()
const DRWContextState * DRW_context_state_get()
void DRW_stats_group_start(const char *name)
void DRW_stats_group_end()
draw_view in_light_buf[] float
detail::Pass< command::DrawCommandBuf > PassSimple
T cos(const AngleRadianBase< T > &a)
T sin(const AngleRadianBase< T > &a)
static void square_to_circle(float x, float y, float &r, float &T)
VecBase< float, 4 > float4
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
VecBase< float, 3 > float3