Changeset View
Changeset View
Standalone View
Standalone View
source/blender/gpu/intern/gpu_compositing.c
| Show First 20 Lines • Show All 393 Lines • ▼ Show 20 Lines | bool GPU_fx_compositor_initialize_passes( | ||||
| /* disable effects if no options passed for them */ | /* disable effects if no options passed for them */ | ||||
| if (!fx_settings->dof) { | if (!fx_settings->dof) { | ||||
| fx_flag &= ~GPU_FX_FLAG_DOF; | fx_flag &= ~GPU_FX_FLAG_DOF; | ||||
| } | } | ||||
| if (!fx_settings->ssao || fx_settings->ssao->samples < 1) { | if (!fx_settings->ssao || fx_settings->ssao->samples < 1) { | ||||
| fx_flag &= ~GPU_FX_FLAG_SSAO; | fx_flag &= ~GPU_FX_FLAG_SSAO; | ||||
| } | } | ||||
| if (!fx_settings->lensdist) { | |||||
| fx_flag &= ~GPU_FX_FLAG_LensDist; | |||||
| } | |||||
| if (!fx_flag) { | if (!fx_flag) { | ||||
| cleanup_fx_gl_data(fx, true); | cleanup_fx_gl_data(fx, true); | ||||
| return false; | return false; | ||||
| } | } | ||||
| /* scissor is missing when drawing offscreen, in that case, dimensions match exactly. In opposite case | /* scissor is missing when drawing offscreen, in that case, dimensions match exactly. In opposite case | ||||
| * add one to match viewport dimensions */ | * add one to match viewport dimensions */ | ||||
| if (scissor_rect) { | if (scissor_rect) { | ||||
| w++; | w++; | ||||
| h++; | h++; | ||||
| } | } | ||||
| fx->num_passes = 0; | fx->num_passes = 0; | ||||
| /* dof really needs a ping-pong buffer to work */ | /* dof really needs a ping-pong buffer to work */ | ||||
| if (fx_flag & GPU_FX_FLAG_DOF) | if (fx_flag & GPU_FX_FLAG_DOF) | ||||
| num_passes++; | num_passes++; | ||||
| if (fx_flag & GPU_FX_FLAG_SSAO) | if (fx_flag & GPU_FX_FLAG_SSAO) | ||||
| num_passes++; | num_passes++; | ||||
| if (fx_flag & GPU_FX_FLAG_LensDist) | |||||
| num_passes++; | |||||
| if (!fx->gbuffer) { | if (!fx->gbuffer) { | ||||
| fx->gbuffer = GPU_framebuffer_create(); | fx->gbuffer = GPU_framebuffer_create(); | ||||
| if (!fx->gbuffer) { | if (!fx->gbuffer) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 285 Lines • ▼ Show 20 Lines | void GPU_fx_compositor_XRay_resolve(GPUFX *fx) | ||||
| glBindBuffer(GL_ARRAY_BUFFER, 0); | glBindBuffer(GL_ARRAY_BUFFER, 0); | ||||
| glDisableClientState(GL_VERTEX_ARRAY); | glDisableClientState(GL_VERTEX_ARRAY); | ||||
| glDisableClientState(GL_TEXTURE_COORD_ARRAY); | glDisableClientState(GL_TEXTURE_COORD_ARRAY); | ||||
| glPopAttrib(); | glPopAttrib(); | ||||
| } | } | ||||
| bool GPU_fx_do_composite_pass( | bool GPU_fx_do_composite_pass( | ||||
| GPUFX *fx, float projmat[4][4], bool is_persp, | GPUFX *fx, float projmat[4][4], bool is_persp, | ||||
| struct Scene *scene, struct GPUOffScreen *ofs) | struct Scene *scene, struct GPUOffScreen *ofs, | ||||
| bool is_left, void *hmd_distortion_params) | |||||
| { | { | ||||
| GPUTexture *src, *target; | GPUTexture *src, *target; | ||||
| int numslots = 0; | int numslots = 0; | ||||
| float invproj[4][4]; | float invproj[4][4]; | ||||
| int i; | int i; | ||||
| float dfdyfac[2]; | float dfdyfac[2]; | ||||
| /* number of passes left. when there are no more passes, the result is passed to the frambuffer */ | /* number of passes left. when there are no more passes, the result is passed to the frambuffer */ | ||||
| int passes_left = fx->num_passes; | int passes_left = fx->num_passes; | ||||
| ▲ Show 20 Lines • Show All 546 Lines • ▼ Show 20 Lines | else { | ||||
| } | } | ||||
| SWAP(GPUTexture *, target, src); | SWAP(GPUTexture *, target, src); | ||||
| numslots = 0; | numslots = 0; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* third pass, Lens Distortion */ | |||||
| if (fx->effects & GPU_FX_FLAG_LensDist) { | |||||
| GPUShader *lensdist_shader = GPU_shader_get_builtin_fx_shader(GPU_SHADER_FX_LENS_DISTORTION, is_persp); | |||||
| if (lensdist_shader && hmd_distortion_params) { | |||||
| struct OpenHMDDistortionParameters { | |||||
| float viewport_scale[2]; | |||||
| float distortion_coeffs[4]; | |||||
| float aberr_scale[3]; | |||||
| float sep; | |||||
| float left_lens_center[2]; | |||||
| float right_lens_center[2]; | |||||
| }; | |||||
| struct OpenHMDDistortionParameters* distparams = (struct OpenHMDDistortionParameters*)hmd_distortion_params; | |||||
| distparams->left_lens_center[0] = distparams->viewport_scale[0] - distparams->sep/2.0f; | |||||
| distparams->right_lens_center[0] = distparams->sep/2.0f; | |||||
| //asume calibration was for lens view to which ever edge of screen is further away from lens center | |||||
| float warp_scale = (distparams->left_lens_center[0] > distparams->right_lens_center[0]) ? distparams->left_lens_center[0] : distparams->right_lens_center[0]; | |||||
| const int color_uniform = GPU_shader_get_uniform(lensdist_shader, "warpTexture"); | |||||
| const int viewport_scale = GPU_shader_get_uniform(lensdist_shader, "ViewportScale"); | |||||
| const int lens_center_f = GPU_shader_get_uniform(lensdist_shader, "LensCenter"); | |||||
| const int warp_scale_f = GPU_shader_get_uniform(lensdist_shader, "WarpScale"); | |||||
| const int HmdWarpParam_f = GPU_shader_get_uniform(lensdist_shader, "HmdWarpParam"); | |||||
| const int aberr_f = GPU_shader_get_uniform(lensdist_shader, "aberr"); | |||||
| GPU_shader_bind(lensdist_shader); | |||||
| if (is_left) | |||||
| GPU_shader_uniform_vector(lensdist_shader, lens_center_f, 2, 1, distparams->left_lens_center); | |||||
| else | |||||
| GPU_shader_uniform_vector(lensdist_shader, lens_center_f, 2, 1, distparams->right_lens_center); | |||||
| GPU_shader_uniform_vector(lensdist_shader, viewport_scale, 2, 1, distparams->viewport_scale); | |||||
| GPU_shader_uniform_float(lensdist_shader, warp_scale_f, warp_scale); | |||||
| GPU_shader_uniform_vector(lensdist_shader, HmdWarpParam_f, 4, 1, distparams->distortion_coeffs); | |||||
| GPU_shader_uniform_vector(lensdist_shader, aberr_f, 3, 1, distparams->aberr_scale); | |||||
| GPU_texture_bind(src, numslots++); | |||||
| GPU_shader_uniform_texture(lensdist_shader, color_uniform, src); | |||||
| /* draw */ | |||||
| gpu_fx_bind_render_target(&passes_left, fx, ofs, target); | |||||
| glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); | |||||
| /* disable bindings */ | |||||
| GPU_texture_unbind(src); | |||||
| /* may not be attached, in that case this just returns */ | |||||
| if (target) { | |||||
| GPU_framebuffer_texture_detach(target); | |||||
| if (ofs) { | |||||
| GPU_offscreen_bind(ofs, false); | |||||
| } | |||||
| else { | |||||
| GPU_framebuffer_restore(); | |||||
| } | |||||
| } | |||||
| /* swap here, after src/target have been unbound */ | |||||
| SWAP(GPUTexture *, target, src); | |||||
| numslots = 0; | |||||
| } | |||||
| } | |||||
| glDisableClientState(GL_VERTEX_ARRAY); | glDisableClientState(GL_VERTEX_ARRAY); | ||||
| glDisableClientState(GL_TEXTURE_COORD_ARRAY); | glDisableClientState(GL_TEXTURE_COORD_ARRAY); | ||||
| glBindBuffer(GL_ARRAY_BUFFER, 0); | glBindBuffer(GL_ARRAY_BUFFER, 0); | ||||
| GPU_shader_unbind(); | GPU_shader_unbind(); | ||||
| return true; | return true; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 162 Lines • Show Last 20 Lines | |||||