[Bf-blender-cvs] [619d977e1a5] blender2.8: GPULamp: Move GPU_frambuffer_blur to GPU_lamp.c

Clément Foucault noreply at git.blender.org
Sun Mar 25 21:33:18 CEST 2018


Commit: 619d977e1a5922fd3f11cf2867c9e9cc1aa54ad7
Author: Clément Foucault
Date:   Sun Mar 25 04:34:36 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB619d977e1a5922fd3f11cf2867c9e9cc1aa54ad7

GPULamp: Move GPU_frambuffer_blur to GPU_lamp.c

This is a bit useless because gpu lamps are only used by the game engine
and it is planned to be "remove" in some way.

Doing this to clean gpu_framebuffer.c.

===================================================================

M	source/blender/gpu/GPU_framebuffer.h
M	source/blender/gpu/intern/gpu_framebuffer.c
M	source/blender/gpu/intern/gpu_lamp.c
M	source/blender/gpu/shaders/gpu_shader_sep_gaussian_blur_vert.glsl

===================================================================

diff --git a/source/blender/gpu/GPU_framebuffer.h b/source/blender/gpu/GPU_framebuffer.h
index 16a2fdd3c28..83fac2456a4 100644
--- a/source/blender/gpu/GPU_framebuffer.h
+++ b/source/blender/gpu/GPU_framebuffer.h
@@ -69,9 +69,6 @@ void GPU_framebuffer_bind_no_save(GPUFrameBuffer *fb, int slot);
 bool GPU_framebuffer_bound(GPUFrameBuffer *fb);
 
 void GPU_framebuffer_restore(void);
-void GPU_framebuffer_blur(
-        GPUFrameBuffer *fb, struct GPUTexture *tex,
-        GPUFrameBuffer *blurfb, struct GPUTexture *blurtex);
 
 void GPU_framebuffer_blit(
         GPUFrameBuffer *fb_read, int read_slot,
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);
diff --git a/source/blender/gpu/shaders/gpu_shader_sep_gaussian_blur_vert.glsl b/source/blender/gpu/shaders/gpu_shader_sep_gaussian_blur_vert.glsl
index 1319e386c65..fca39852c2a 100644
--- a/source/blender/gpu/shaders/gpu_shader_sep_gaussian_blur_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_sep_gaussian_blur_vert.glsl
@@ -1,12 +1,14 @@
 
-uniform mat4 ModelViewProjectionMatrix;
-
-in vec2 pos;
-in vec2 uvs;
 out vec2 texCoord_interp;
 
 void main()
 {
-	gl_Position = ModelViewProjectionMatrix * vec4(pos, 0.0, 1.0);
-	texCoord_interp = uvs;
+	const vec4 vert[3] = vec4[3](
+		vec3(-1.0, -1.0,  0.0,  0.0),
+		vec3( 3.0, -1.0,  2.0,  0.0),
+		vec3(-1.0,  3.0,  0.0,  2.0)
+	);
+
+	gl_Position = vec4(vert[gl_VertexID].xy, 0.0, 1.0);
+	texCoord_interp = vert[gl_VertexID].zw;
 }



More information about the Bf-blender-cvs mailing list