[Bf-blender-cvs] [28f2717] viewport_experiments: Cleanup for compositing, move to c++ WIP node abstractions for compositing system.
Antony Riakiotakis
noreply at git.blender.org
Tue Feb 3 19:28:31 CET 2015
Commit: 28f271736be094bc66339dbdb5cdc64f4fbf9f3d
Author: Antony Riakiotakis
Date: Tue Jan 27 10:26:24 2015 +0100
Branches: viewport_experiments
https://developer.blender.org/rB28f271736be094bc66339dbdb5cdc64f4fbf9f3d
Cleanup for compositing, move to c++ WIP node abstractions for compositing system.
===================================================================
M source/blender/gpu/CMakeLists.txt
M source/blender/gpu/GPU_compositing.h
M source/blender/gpu/GPU_extensions.h
M source/blender/gpu/intern/gpu_codegen.c
D source/blender/gpu/intern/gpu_compositing.c
A source/blender/gpu/intern/gpu_compositing.cpp
===================================================================
diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt
index bb598aa..cc74459 100644
--- a/source/blender/gpu/CMakeLists.txt
+++ b/source/blender/gpu/CMakeLists.txt
@@ -54,7 +54,7 @@ set(SRC
intern/gpu_material.c
intern/gpu_simple_shader.c
intern/gpu_select.c
- intern/gpu_compositing.c
+ intern/gpu_compositing.cpp
intern/gpu_renderer.c
shaders/gpu_shader_fx_lib.glsl
diff --git a/source/blender/gpu/GPU_compositing.h b/source/blender/gpu/GPU_compositing.h
index d219256..dc997b3 100644
--- a/source/blender/gpu/GPU_compositing.h
+++ b/source/blender/gpu/GPU_compositing.h
@@ -32,6 +32,10 @@
#ifndef __GPU_COMPOSITING_H__
#define __GPU_COMPOSITING_H__
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/* opaque handle for framebuffer compositing effects (defined in gpu_compositing.c )*/
typedef struct GPUFX GPUFX;
@@ -77,4 +81,8 @@ bool GPU_initialize_fx_passes(GPUFX *fx, struct rcti *rect, rcti *scissor_rect,
/* do compositing on the fx passes that have been initialized */
bool GPU_fx_do_composite_pass(GPUFX *fx, float projmat[4][4], bool is_persp, struct Scene *scene, struct GPUOffScreen *ofs);
+#ifdef __cplusplus
+}
+#endif
+
#endif // __GPU_COMPOSITING_H__
diff --git a/source/blender/gpu/GPU_extensions.h b/source/blender/gpu/GPU_extensions.h
index 42f8a95..99813e9 100644
--- a/source/blender/gpu/GPU_extensions.h
+++ b/source/blender/gpu/GPU_extensions.h
@@ -108,7 +108,7 @@ int GPU_type_matches(GPUDeviceType device, GPUOSType os, GPUDriverType driver);
*/
typedef enum GPUHDRType {
- GPU_HDR_NONE = 0,
+ GPU_HDR_NONE = 0,
GPU_HDR_HALF_FLOAT = 1,
GPU_HDR_FULL_FLOAT = (1 << 1),
} GPUHDRType;
diff --git a/source/blender/gpu/intern/gpu_codegen.c b/source/blender/gpu/intern/gpu_codegen.c
index 633b323..645513b 100644
--- a/source/blender/gpu/intern/gpu_codegen.c
+++ b/source/blender/gpu/intern/gpu_codegen.c
@@ -964,7 +964,7 @@ static void gpu_node_input_link(GPUNode *node, GPUNodeLink *link, int type)
input->textype = type;
//input->tex = GPU_texture_create_2D(link->texturesize, link->texturesize, link->ptr2, NULL);
- input->tex = GPU_texture_create_2D(link->texturesize, 1, link->ptr1, false, NULL);
+ input->tex = GPU_texture_create_2D(link->texturesize, 1, link->ptr1, GPU_HDR_NONE, NULL);
input->textarget = GL_TEXTURE_2D;
MEM_freeN(link->ptr1);
diff --git a/source/blender/gpu/intern/gpu_compositing.c b/source/blender/gpu/intern/gpu_compositing.cpp
similarity index 91%
rename from source/blender/gpu/intern/gpu_compositing.c
rename to source/blender/gpu/intern/gpu_compositing.cpp
index e46183f..2097454 100644
--- a/source/blender/gpu/intern/gpu_compositing.c
+++ b/source/blender/gpu/intern/gpu_compositing.cpp
@@ -34,7 +34,12 @@
#include "BLI_sys_types.h"
#include "BLI_rect.h"
#include "BLI_math.h"
+#include "BLI_listbase.h"
+#include "BLI_linklist.h"
+
+extern "C" {
#include "BLI_rand.h"
+}
#include "BLI_listbase.h"
#include "DNA_vec_types.h"
@@ -109,58 +114,170 @@ struct GPUFX {
bool restore_stencil;
};
+/* concentric mapping, see "A Low Distortion Map Between Disk and Square" and
+ * http://psgraphics.blogspot.nl/2011/01/improved-code-for-concentric-map.html */
+static GPUTexture * create_concentric_sample_texture(int side)
+{
+ GPUTexture *tex;
+ float midpoint = 0.5f * (side - 1);
+ float *texels = (float *)MEM_mallocN(sizeof(float) * 2 * side * side, "concentric_tex");
+ int i, j;
-/* compositing link between compostiting stages, */
-typedef struct GPUCompositingLink {
- GPUTexture *texture;
- char *inslot;
- char *outslot;
- int flag;
-} GPUCompositingLink;
+ for (i = 0; i < side; i++) {
+ for (j = 0; j < side; j++) {
+ int index = (i * side + j) * 2;
+ float a = 1.0f - i / midpoint;
+ float b = 1.0f - j / midpoint;
+ float phi, r;
+ if (a * a > b * b) {
+ r = a;
+ phi = (M_PI_4) * (b / a);
+ }
+ else {
+ r = b;
+ phi = M_PI_2 - (M_PI_4) * (a / b);
+ }
+ texels[index] = r * cos(phi);
+ texels[index + 1] = r * sin(phi);
+ }
+ }
-/* compositing node - it's different than material nodes because outputs are buffers - inputs can be
- * uniforms or other beasts inputs*/
-typedef struct GPUCompositingNode {
- GPUShader *shader;
- int w, h;
- ListBase inputs;
- ListBase outputs;
-} GPUCompositingNode;
+ tex = GPU_texture_create_1D_procedural(side * side, texels, NULL);
+ MEM_freeN(texels);
+ return tex;
+}
+/* compositing node - it's different than material nodes because outputs are buffers - inputs can be
+ * uniforms or other types. outputs are always textures */
+class GPUCompositingNode {
+ private:
+ GPUShader *shader;
+ int w, h;
+ ListBase inputs;
+ ListBase outputs;
+
+ public:
+ GPUCompositingNode(GPUShader *shader, int w, int h);
+ ~GPUCompositingNode();
+ float getWidth() {return w;}
+ float getHeight() {return h;}
+ void setShader(GPUShader *sh) {shader = sh;}
+};
-static GPUCompositingNode *gpu_compositing_node_new(GPUShader *shader, int w, int h)
+GPUCompositingNode::GPUCompositingNode(GPUShader *shader, int w, int h)
{
- GPUCompositingNode *node = MEM_callocN(sizeof(GPUCompositingNode), "GPUCompositingNode");
- node->w = w;
- node->h = h;
- node->shader = shader;
-
- return node;
+ this->w = w;
+ this->h = h;
+ this->shader = shader;
}
-static void gpu_compositing_nodes_link(GPUCompositingNode *nodei, GPUCompositingNode *nodeo, char *input, char *output)
-{
- GPUCompositingLink *link = MEM_callocN(sizeof(GPUCompositingLink), "GPUCompositingNode");
-
- link->inslot = input;
- link->outslot = output;
+GPUCompositingNode::~GPUCompositingNode() {
+ GPU_shader_free(shader);
+ BLI_freelistN(&inputs);
+ BLI_freelistN(&outputs);
+}
+
+/* compositing link between compostiting stages, */
+class GPUCompositingLink {
+ private:
+ GPUTexture *intexture;
+ char *outslot;
+ int flag;
- BLI_addhead(&nodei->inputs, BLI_genericNodeN(link));
- BLI_addhead(&nodeo->outputs, BLI_genericNodeN(link));
+ public:
+ GPUCompositingLink(GPUCompositingNode *nodei, GPUCompositingNode *nodeo, int inslot, char *output);
+ ~GPUCompositingLink();
+};
+
+GPUCompositingLink::GPUCompositingLink(GPUCompositingNode *nodei, GPUCompositingNode *nodeo, int inslot, char *output)
+{
+ this->intexture = intexture;
+ this->outslot = output;
}
+class GPUEffect {
+ protected:
+ ListBase nodes;
+
+ public:
+ virtual ~GPUEffect() {}
+
+ // prepare or cleanup nodes accorging to new effect parameters
+ virtual void prepare(GPUFXOptions *options, int w, int h) = 0;
+ // queue the effect nodes for execution
+ virtual void queue() = 0;
+ //checks if effect has been initialized with sane inputs
+ virtual bool checkvalid() = 0;
+ virtual void cleanup() = 0;
+};
+
+class GPUDOFEffect : public GPUEffect {
+ public:
+ GPUDOFEffect();
+ ~GPUDOFEffect();
+};
+
+class GPUSSAOEffect : public GPUEffect {
+ private:
+ GPUShader *shader_persp;
+ GPUShader *shader_ortho;
+ GPUTexture *concentric_samples_tex;
+ int num_samples;
+ /* old target dimensions */
+ int oldx, oldy;
+
+ public:
+ GPUSSAOEffect();
+ ~GPUSSAOEffect() {cleanup();}
+
+ // prepare or cleanup nodes accorging to new effect parameters
+ void prepare(GPUFXOptions *options, int w, int h);
+ // queue the effect nodes for execution
+ void queue(){}
+ bool checkvalid() {return true;}
+ void cleanup(){}
+};
-static void gpu_compositing_node_free(GPUCompositingNode *node)
+GPUSSAOEffect::GPUSSAOEffect()
{
- BLI_freelistN(&node->inputs);
- BLI_freelistN(&node->outputs);
+ /* compile shaders here */
+ shader_persp = GPU_shader_get_builtin_fx_shader(GPU_SHADER_FX_SSAO, true);
+ shader_ortho = GPU_shader_get_builtin_fx_shader(GPU_SHADER_FX_SSAO, false);
}
+void GPUSSAOEffect::prepare(GPUFXOptions *options, int UNUSED(w), int UNUSED(h))
+{
+ if (options->ssao_options) {
+ if (options->ssao_options->ssao_num_samples != num_samples || !concentric_samples_tex) {
+ if (options->ssao_options->ssao_num_samples < 1)
+ options->ssao_options->ssao_num_samples = 1;
+
+ num_samples = options->ssao_options->ssao_num_samples;
+
+ if (concentric_samples_tex) {
+ GPU_texture_free(concentric_samples_tex);
+ }
+
+ concentric_samples_tex = create_concentric_sample_texture(num_samples);
+ }
+ }
+ else {
+ if (concentric_samples_tex) {
+ GPU_texture_free(concentric_samples_tex);
+ concentric_samples_tex = NULL;
+ }
+ }
+}
+
+/* manages resources and data flow between nodes */
+class GPUCompositorManager {
+
+};
/* generate a new FX compositor */
GPUFX *GPU_create_fx_compositor(void)
{
- GPUFX *fx = MEM_callocN(sizeof(GPUFX), "GPUFX compositor");
+ GPUFX *fx = (GPUFX *)MEM_callocN(sizeof(GPUFX), "GPUFX compositor");
return fx;
}
@@ -264,38 +381,6 @@ static GPUTexture * create_jitter_texture(void)
return GPU_texture_create_2D_procedural(64, 64, &jitter[0][0], NULL);
}
-/* concentric mapping, see*/
-static GPUTexture * create_concentric_sample_texture(int side)
-{
- GPUTexture *tex;
- float midpoint = 0.5f * (side - 1);
- float *texels = MEM_mallocN(sizeof(float) * 2 * side * side, "concentric_tex");
- int i, j;
-
- for (i = 0; i < side; i++) {
- for (j = 0; j < side; j++) {
- int index = (i * side + j) * 2;
- float a = 1.0f - i / midpoint;
- float b = 1.0f - j / midpoint;
- float phi, r;
- if (a * a > b * b) {
- r = a;
- phi = (M_PI_4) * (b / a);
- }
- else {
- r = b;
- phi = M_PI_2 - (M_PI_4) * (a / b);
- }
- texels[index] = r * cos(phi);
- texels[index + 1] = r * sin(phi);
- }
- }
-
- tex = GPU_texture_create_1D_procedural(side * side, texels, NULL);
- MEM_freeN(texels);
- return tex;
-}
-
bool GPU_initialize_fx_passes(GPUFX *fx, rcti *rect, rcti *scissor_rect, int fxflags, GPUFXOptions *options)
{
More information about the Bf-blender-cvs
mailing list