[Bf-blender-cvs] [0782c68] viewport_experiments: Add a library file for projection shader code, should enable us to use optimized position calculation again - relevant for both SSAO and DOF
Antony Riakiotakis
noreply at git.blender.org
Tue Oct 28 19:08:20 CET 2014
Commit: 0782c680a66e4e83030486996e7a4b0a5128bcba
Author: Antony Riakiotakis
Date: Tue Oct 28 19:07:58 2014 +0100
Branches: viewport_experiments
https://developer.blender.org/rB0782c680a66e4e83030486996e7a4b0a5128bcba
Add a library file for projection shader code, should enable us to use
optimized position calculation again - relevant for both SSAO and DOF
===================================================================
M source/blender/gpu/CMakeLists.txt
M source/blender/gpu/GPU_extensions.h
M source/blender/gpu/intern/gpu_compositing.c
M source/blender/gpu/intern/gpu_extensions.c
M source/blender/gpu/shaders/gpu_shader_fx_dof_frag.glsl
A source/blender/gpu/shaders/gpu_shader_fx_lib.glsl
M source/blender/gpu/shaders/gpu_shader_fx_ssao_frag.glsl
===================================================================
diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt
index d2551b0..555c100 100644
--- a/source/blender/gpu/CMakeLists.txt
+++ b/source/blender/gpu/CMakeLists.txt
@@ -57,6 +57,7 @@ set(SRC
intern/gpu_compositing.c
intern/gpu_renderer.c
+ shaders/gpu_shader_fx_lib.glsl
shaders/gpu_shader_fx_ssao_frag.glsl
shaders/gpu_shader_fx_dof_frag.glsl
shaders/gpu_shader_fx_vert.glsl
@@ -94,6 +95,7 @@ data_to_c_simple(shaders/gpu_shader_vsm_store_vert.glsl SRC)
data_to_c_simple(shaders/gpu_shader_fx_vert.glsl SRC)
data_to_c_simple(shaders/gpu_shader_fx_ssao_frag.glsl SRC)
data_to_c_simple(shaders/gpu_shader_fx_dof_frag.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_fx_lib.glsl SRC)
if(WITH_GAMEENGINE)
add_definitions(-DWITH_GAMEENGINE)
diff --git a/source/blender/gpu/GPU_extensions.h b/source/blender/gpu/GPU_extensions.h
index 9bff739..841fe2a 100644
--- a/source/blender/gpu/GPU_extensions.h
+++ b/source/blender/gpu/GPU_extensions.h
@@ -190,7 +190,7 @@ typedef enum GPUBuiltinShader {
} GPUBuiltinShader;
GPUShader *GPU_shader_get_builtin_shader(GPUBuiltinShader shader);
-GPUShader *GPU_shader_get_builtin_fx_shader(int effects);
+GPUShader *GPU_shader_get_builtin_fx_shader(int effects, bool persp);
void GPU_shader_free_builtin_shaders(void);
diff --git a/source/blender/gpu/intern/gpu_compositing.c b/source/blender/gpu/intern/gpu_compositing.c
index 2bd45f9..6dde144 100644
--- a/source/blender/gpu/intern/gpu_compositing.c
+++ b/source/blender/gpu/intern/gpu_compositing.c
@@ -276,9 +276,16 @@ bool GPU_initialize_fx_passes(GPUFX *fx, rcti *rect, rcti *scissor_rect, int fxf
bool GPU_fx_do_composite_pass(GPUFX *fx, struct View3D *v3d, struct RegionView3D *rv3d, struct Scene *scene) {
GPUShader *fx_shader;
int numslots = 0;
-
+ float invproj[4][4];
+ int i;
/* dimensions of screen (used in many shaders)*/
float screen_dim[2] = {fx->gbuffer_dim[0], fx->gbuffer_dim[1]};
+ /* view vectors for the corners of the view frustum. Can be used to recreate the world space position easily */
+ float viewvecs[3][4] = {
+ {-1.0f, -1.0f, -1.0f, 1.0f},
+ {1.0f, -1.0f, -1.0f, 1.0f},
+ {-1.0f, 1.0f, -1.0f, 1.0f}
+ };
if (fx->effects == 0)
return false;
@@ -295,45 +302,36 @@ bool GPU_fx_do_composite_pass(GPUFX *fx, struct View3D *v3d, struct RegionView3D
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
/* full screen FX pass */
-
+
+ /* invert the view matrix */
+ invert_m4_m4(invproj, rv3d->winmat);
+
+ /* convert the view vectors to view space */
+ for (i = 0; i < 3; i++) {
+ mul_m4_v4(invproj, viewvecs[i]);
+ /* normalized trick see http://www.derschmale.com/2014/01/26/reconstructing-positions-from-the-depth-buffer */
+ mul_v3_fl(viewvecs[i], 1.0f / viewvecs[i][3]);
+ mul_v3_fl(viewvecs[i], 1.0f / viewvecs[i][2]);
+ viewvecs[i][2] = 1.0;
+ }
+
+ /* we need to store the differences */
+ viewvecs[1][0] -= viewvecs[0][0];
+ viewvecs[1][1] = viewvecs[2][1] - viewvecs[0][1];
+
/* ssao pass */
if (fx->effects & V3D_FX_SSAO) {
- fx_shader = GPU_shader_get_builtin_fx_shader(GPU_SHADER_FX_SSAO);
+ fx_shader = GPU_shader_get_builtin_fx_shader(GPU_SHADER_FX_SSAO, rv3d->is_persp);
if (fx_shader) {
- /* view vectors for the corners of the view frustum. Can be used to recreate the world space position easily */
- float ssao_viewvecs[3][4] = {
- {-1.0f, -1.0f, -1.0f, 1.0f},
- {1.0f, -1.0f, -1.0f, 1.0f},
- {-1.0f, 1.0f, -1.0f, 1.0f}
- };
- int i;
int screendim_uniform, color_uniform, depth_uniform;
- int ssao_uniform, ssao_color_uniform, ssao_viewvecs_uniform, ssao_sample_params_uniform;
+ int ssao_uniform, ssao_color_uniform, viewvecs_uniform, ssao_sample_params_uniform;
int ssao_jitter_uniform, ssao_direction_uniform;
float ssao_params[4] = {v3d->ssao_distance_max, v3d->ssao_darkening, v3d->ssao_attenuation, 0.0f};
float sample_params[4];
- float invproj[4][4];
-
if (!init)
create_sample_directions();
- /* invert the view matrix */
- invert_m4_m4(invproj, rv3d->winmat);
-
- /* convert the view vectors to view space */
- for (i = 0; i < 3; i++) {
- mul_m4_v4(invproj, ssao_viewvecs[i]);
- /* normalized trick see http://www.derschmale.com/2014/01/26/reconstructing-positions-from-the-depth-buffer */
- mul_v3_fl(ssao_viewvecs[i], 1.0f / ssao_viewvecs[i][3]);
- mul_v3_fl(ssao_viewvecs[i], 1.0f / ssao_viewvecs[i][2]);
- ssao_viewvecs[i][2] = 1.0;
- }
-
- /* we need to store the differences */
- ssao_viewvecs[1][0] -= ssao_viewvecs[0][0];
- ssao_viewvecs[1][1] = ssao_viewvecs[2][1] - ssao_viewvecs[0][1];
-
switch (v3d->ssao_ray_sample_mode) {
case 0:
sample_params[0] = 4;
@@ -358,7 +356,7 @@ bool GPU_fx_do_composite_pass(GPUFX *fx, struct View3D *v3d, struct RegionView3D
ssao_color_uniform = GPU_shader_get_uniform(fx_shader, "ssao_color");
color_uniform = GPU_shader_get_uniform(fx_shader, "colorbuffer");
depth_uniform = GPU_shader_get_uniform(fx_shader, "depthbuffer");
- ssao_viewvecs_uniform = GPU_shader_get_uniform(fx_shader, "ssao_viewvecs");
+ viewvecs_uniform = GPU_shader_get_uniform(fx_shader, "viewvecs");
ssao_sample_params_uniform = GPU_shader_get_uniform(fx_shader, "ssao_sample_params");
ssao_jitter_uniform = GPU_shader_get_uniform(fx_shader, "jitter_tex");
ssao_direction_uniform = GPU_shader_get_uniform(fx_shader, "sample_directions");
@@ -368,7 +366,7 @@ bool GPU_fx_do_composite_pass(GPUFX *fx, struct View3D *v3d, struct RegionView3D
GPU_shader_uniform_vector(fx_shader, screendim_uniform, 2, 1, screen_dim);
GPU_shader_uniform_vector(fx_shader, ssao_uniform, 4, 1, ssao_params);
GPU_shader_uniform_vector(fx_shader, ssao_color_uniform, 4, 1, v3d->ssao_color);
- GPU_shader_uniform_vector(fx_shader, ssao_viewvecs_uniform, 4, 3, ssao_viewvecs[0]);
+ GPU_shader_uniform_vector(fx_shader, viewvecs_uniform, 4, 3, viewvecs[0]);
GPU_shader_uniform_vector(fx_shader, ssao_sample_params_uniform, 4, 1, sample_params);
GPU_shader_uniform_vector(fx_shader, ssao_direction_uniform, 2, 16, ssao_sample_directions[0]);
@@ -406,11 +404,11 @@ bool GPU_fx_do_composite_pass(GPUFX *fx, struct View3D *v3d, struct RegionView3D
/* second pass, dof */
if (fx->effects & V3D_FX_DEPTH_OF_FIELD) {
- fx_shader = GPU_shader_get_builtin_fx_shader(GPU_SHADER_FX_DEPTH_OF_FIELD);
+ fx_shader = GPU_shader_get_builtin_fx_shader(GPU_SHADER_FX_DEPTH_OF_FIELD, rv3d->is_persp);
if (fx_shader) {
- int i;
float dof_params[4];
int screendim_uniform, color_uniform, depth_uniform, dof_uniform, blurred_uniform;
+ int viewvecs_uniform;
float scale = scene->unit.system ? scene->unit.scale_length : 1.0f;
float scale_camera = 0.001f / scale;
@@ -426,11 +424,13 @@ bool GPU_fx_do_composite_pass(GPUFX *fx, struct View3D *v3d, struct RegionView3D
screendim_uniform = GPU_shader_get_uniform(fx_shader, "screendim");
color_uniform = GPU_shader_get_uniform(fx_shader, "colorbuffer");
depth_uniform = GPU_shader_get_uniform(fx_shader, "depthbuffer");
+ viewvecs_uniform = GPU_shader_get_uniform(fx_shader, "viewvecs");
GPU_shader_bind(fx_shader);
GPU_shader_uniform_vector(fx_shader, dof_uniform, 4, 1, dof_params);
GPU_shader_uniform_vector(fx_shader, screendim_uniform, 2, 1, screen_dim);
+ GPU_shader_uniform_vector(fx_shader, viewvecs_uniform, 4, 3, viewvecs[0]);
GPU_texture_bind(fx->color_buffer, numslots++);
GPU_shader_uniform_texture(fx_shader, blurred_uniform, fx->color_buffer);
diff --git a/source/blender/gpu/intern/gpu_extensions.c b/source/blender/gpu/intern/gpu_extensions.c
index bce7414..36f9023 100644
--- a/source/blender/gpu/intern/gpu_extensions.c
+++ b/source/blender/gpu/intern/gpu_extensions.c
@@ -83,12 +83,13 @@ extern char datatoc_gpu_shader_sep_gaussian_blur_frag_glsl[];
extern char datatoc_gpu_shader_fx_vert_glsl[];
extern char datatoc_gpu_shader_fx_ssao_frag_glsl[];
extern char datatoc_gpu_shader_fx_dof_frag_glsl[];
+extern char datatoc_gpu_shader_fx_lib_glsl[];
typedef struct GPUShaders {
GPUShader *vsm_store;
GPUShader *sep_gaussian_blur;
/* cache for shader fx. Those can exist in combinations so store them here */
- GPUShader *fx_shaders[MAX_FX_SHADERS];
+ GPUShader *fx_shaders[MAX_FX_SHADERS * 2];
} GPUShaders;
static struct GPUGlobal {
@@ -1563,20 +1564,29 @@ GPUShader *GPU_shader_get_builtin_shader(GPUBuiltinShader shader)
return retval;
}
-GPUShader *GPU_shader_get_builtin_fx_shader(int effects)
+GPUShader *GPU_shader_get_builtin_fx_shader(int effects, bool persp)
{
+ int offset;
+ const char *defines = NULL;
/* avoid shaders out of range */
if (effects >= MAX_FX_SHADERS)
return NULL;
- if (!GG.shaders.fx_shaders[effects]) {
+ offset = 2 * effects;
+
+ if (persp) {
+ offset += 1;
+ defines = "#define PERSP_MATRIX\n";
+ }
+
+ if (!GG.shaders.fx_shaders[offset]) {
if (effects == GPU_SHADER_FX_SSAO)
- GG.shaders.fx_shaders[effects] = GPU_shader_create(datatoc_gpu_shader_fx_vert_glsl, datatoc_gpu_shader_fx_ssao_frag_glsl, NULL, NULL);
+ GG.shaders.fx_shaders[offset] = GPU_shader_create(datatoc_gpu_shader_fx_vert_glsl, datatoc_gpu_shader_fx_ssao_frag_glsl, datatoc_gpu_shader_fx_lib_glsl, defines);
else if (effects == GPU_SHADER_FX_DEPTH_OF_FIELD)
- GG.shaders.fx_shaders[effects] = GPU_shader_create(datatoc_gpu_shader_fx_vert_glsl, datatoc_gpu_shader_fx_dof_frag_glsl, NULL, NULL);
+ GG.shaders.fx_shaders[offset] = GPU_shader_create(datatoc_gpu_shader_fx_vert_glsl, datatoc_gpu_shader_fx_dof_frag_glsl, datatoc_gpu_shader_fx_lib_glsl, defines);
}
- return GG.shaders.fx_shaders[effects];
+ return GG.shaders.fx_shaders[offset];
}
@@ -1594,7 +1604,7 @@ void GPU_shader_free_builtin_shaders(void)
GG.shaders.sep_gaussian_blur = NULL;
}
- for (i = 0; i < MAX_FX_SHADERS; i++) {
+ for (i = 0; i < 2 * MAX_FX_SHADERS; i++) {
if (GG.shaders.fx_shaders[i]) {
MEM_freeN(GG.shaders.fx_shaders[i]);
GG.shaders.fx_shaders[i] = NULL;
diff --git a/source/blender/gpu/shaders/gpu_shader_fx_dof_frag.glsl b/source/blender/gpu/shaders/gpu_shader_fx_dof_frag.glsl
index a5a6bfc..6f0521e 100644
--- a/source/blender/gpu/shaders/gpu_shader_fx_dof_frag.glsl
+++ b/sour
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list