diff options
Diffstat (limited to 'source/blender/gpu/intern')
-rw-r--r-- | source/blender/gpu/intern/gpu_framebuffer.c | 79 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_lamp.c | 36 |
2 files changed, 34 insertions, 81 deletions
diff --git a/source/blender/gpu/intern/gpu_framebuffer.c b/source/blender/gpu/intern/gpu_framebuffer.c index b68badc7a3b..a267d9cf1ee 100644 --- a/source/blender/gpu/intern/gpu_framebuffer.c +++ b/source/blender/gpu/intern/gpu_framebuffer.c @@ -439,85 +439,6 @@ void GPU_framebuffer_restore(void) } } -void GPU_framebuffer_blur( - GPUFrameBuffer *fb, GPUTexture *tex, - GPUFrameBuffer *blurfb, GPUTexture *blurtex) -{ - const float fullscreencos[4][2] = {{-1.0f, -1.0f}, {1.0f, -1.0f}, {-1.0f, 1.0f}, {1.0f, 1.0f}}; - const float fullscreenuvs[4][2] = {{0.0f, 0.0f}, {1.0f, 0.0f}, {0.0f, 1.0f}, {1.0f, 1.0f}}; - - static Gwn_VertFormat format = {0}; - static Gwn_VertBuf vbo = {{0}}; - static Gwn_Batch batch = {{0}}; - - const float scaleh[2] = {1.0f / GPU_texture_width(blurtex), 0.0f}; - const float scalev[2] = {0.0f, 1.0f / GPU_texture_height(tex)}; - - GPUShader *blur_shader = GPU_shader_get_builtin_shader(GPU_SHADER_SEP_GAUSSIAN_BLUR); - - if (!blur_shader) - return; - - /* Preparing to draw quad */ - if (format.attrib_ct == 0) { - unsigned int i = 0; - /* Vertex format */ - unsigned int pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT); - unsigned int uvs = GWN_vertformat_attr_add(&format, "uvs", GWN_COMP_F32, 2, GWN_FETCH_FLOAT); - - /* Vertices */ - GWN_vertbuf_init_with_format(&vbo, &format); - GWN_vertbuf_data_alloc(&vbo, 36); - - for (int j = 0; j < 3; ++j) { - GWN_vertbuf_attr_set(&vbo, uvs, i, fullscreenuvs[j]); - GWN_vertbuf_attr_set(&vbo, pos, i++, fullscreencos[j]); - } - for (int j = 1; j < 4; ++j) { - GWN_vertbuf_attr_set(&vbo, uvs, i, fullscreenuvs[j]); - GWN_vertbuf_attr_set(&vbo, pos, i++, fullscreencos[j]); - } - - GWN_batch_init(&batch, GL_TRIANGLES, &vbo, NULL); - } - - glDisable(GL_DEPTH_TEST); - - /* Blurring horizontally */ - /* We do the bind ourselves rather than using GPU_framebuffer_texture_bind() to avoid - * pushing unnecessary matrices onto the OpenGL stack. */ - glBindFramebuffer(GL_FRAMEBUFFER, blurfb->object); - glDrawBuffer(GL_COLOR_ATTACHMENT0); - - /* avoid warnings from texture binding */ - g_currentfb = blurfb->object; - - glViewport(0, 0, GPU_texture_width(blurtex), GPU_texture_height(blurtex)); - - GPU_texture_bind(tex, 0); - - GWN_batch_program_set_builtin(&batch, GPU_SHADER_SEP_GAUSSIAN_BLUR); - GWN_batch_uniform_2f(&batch, "ScaleU", scaleh[0], scaleh[1]); - GWN_batch_uniform_1i(&batch, "textureSource", GL_TEXTURE0); - GWN_batch_draw(&batch); - - /* Blurring vertically */ - glBindFramebuffer(GL_FRAMEBUFFER, fb->object); - glDrawBuffer(GL_COLOR_ATTACHMENT0); - - g_currentfb = fb->object; - - glViewport(0, 0, GPU_texture_width(tex), GPU_texture_height(tex)); - - GPU_texture_bind(blurtex, 0); - - /* Hack to make the following uniform stick */ - GWN_batch_program_set_builtin(&batch, GPU_SHADER_SEP_GAUSSIAN_BLUR); - GWN_batch_uniform_2f(&batch, "ScaleU", scalev[0], scalev[1]); - GWN_batch_uniform_1i(&batch, "textureSource", GL_TEXTURE0); - GWN_batch_draw(&batch); -} - void GPU_framebuffer_blit( GPUFrameBuffer *fb_read, int read_slot, GPUFrameBuffer *fb_write, int write_slot, bool use_depth, bool use_stencil) diff --git a/source/blender/gpu/intern/gpu_lamp.c b/source/blender/gpu/intern/gpu_lamp.c index 3c49c057b49..ffdb433bacf 100644 --- a/source/blender/gpu/intern/gpu_lamp.c +++ b/source/blender/gpu/intern/gpu_lamp.c @@ -49,6 +49,7 @@ #include "GPU_material.h" #include "GPU_shader.h" #include "GPU_texture.h" +#include "GPU_batch.h" #include "gpu_lamp_private.h" @@ -333,7 +334,6 @@ GPULamp *GPU_lamp_from_blender(Scene *scene, Object *ob, Object *par) return lamp; } - GPU_framebuffer_texture_unbind(lamp->blurfb, lamp->blurtex); } else { lamp->tex = GPU_texture_create_depth(lamp->size, lamp->size, NULL); @@ -447,11 +447,43 @@ void GPU_lamp_shadow_buffer_bind(GPULamp *lamp, float viewmat[4][4], int *winsiz *winsize = lamp->size; } +static void gpu_lamp_shadow_blur(GPULamp *lamp) +{ + const float scaleh[2] = {1.0f / GPU_texture_width(lamp->blurtex), 0.0f}; + const float scalev[2] = {0.0f, 1.0f / GPU_texture_height(lamp->tex)}; + + GPUShader *blur_shader = GPU_shader_get_builtin_shader(GPU_SHADER_SEP_GAUSSIAN_BLUR); + + if (!blur_shader) + return; + + int tex_loc = GPU_shader_get_uniform(blur_shader, "textureSource"); + int scale_loc = GPU_shader_get_uniform(blur_shader, "ScaleU"); + + glDisable(GL_DEPTH_TEST); + + GPU_shader_bind(blur_shader); + + /* Blurring horizontally */ + GPU_framebuffer_bind(lamp->blurfb); + GPU_texture_bind(lamp->tex, 0); + GPU_shader_uniform_vector(blur_shader, scale_loc, 2, 1, scaleh); + GPU_shader_uniform_texture(blur_shader, tex_loc, lamp->tex); + GWN_draw_primitive(GL_TRIANGLES, 3); + + /* Blurring vertically */ + GPU_framebuffer_bind(lamp->fb); + GPU_texture_bind(lamp->blurtex, 0); + GPU_shader_uniform_vector(blur_shader, scale_loc, 2, 1, scalev); + GPU_shader_uniform_texture(blur_shader, tex_loc, lamp->blurtex); + GWN_draw_primitive(GL_TRIANGLES, 3); +} + void GPU_lamp_shadow_buffer_unbind(GPULamp *lamp) { if (lamp->la->shadowmap_type == LA_SHADMAP_VARIANCE) { GPU_shader_unbind(); - GPU_framebuffer_blur(lamp->fb, lamp->tex, lamp->blurfb, lamp->blurtex); + gpu_lamp_shadow_blur(lamp); } GPU_framebuffer_texture_unbind(lamp->fb, lamp->tex); |