Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClément Foucault <foucault.clem@gmail.com>2018-08-10 16:13:39 +0300
committerClément Foucault <foucault.clem@gmail.com>2018-08-10 17:16:35 +0300
commitbf6a22ed6f6bbe7db3e7796e83d32e071aae93cc (patch)
treeaefa8c3e594d9d9fd761e12c0a825f199853b596 /source/blender/gpu/intern/gpu_material.c
parentc9bd61b37240ad000ae7ac4d49801e4afe3565b0 (diff)
GPUMaterial: Group all colorband texture together
This lower the use of texture samplers slots and let users use more real textures in their shaders. This patch also make the ramp texture 16 bit floating point. Meaning you can now use value greater than one in your color ramps. With the limit of 128 colorband per shader (a color band being either a color ramp, a wavelength node or a curve node (and maybe wavelength node in the future)). Only drawback with the current implementation is that it does not remove colorband from pruned GPUNodes but it shouldn't really matter in practice. This should fix T56010
Diffstat (limited to 'source/blender/gpu/intern/gpu_material.c')
-rw-r--r--source/blender/gpu/intern/gpu_material.c61
1 files changed, 57 insertions, 4 deletions
diff --git a/source/blender/gpu/intern/gpu_material.c b/source/blender/gpu/intern/gpu_material.c
index 69c3a3a73ba..b03df2c643c 100644
--- a/source/blender/gpu/intern/gpu_material.c
+++ b/source/blender/gpu/intern/gpu_material.c
@@ -63,6 +63,12 @@
#endif
/* Structs */
+#define MAX_COLOR_BAND 128
+
+typedef struct GPUColorBandBuilder {
+ float pixels[MAX_COLOR_BAND][CM_TABLE + 1][4];
+ int current_layer;
+} GPUColorBandBuilder;
struct GPUMaterial {
Scene *scene; /* DEPRECATED was only usefull for lamps */
@@ -125,6 +131,9 @@ struct GPUMaterial {
float sss_sharpness;
bool sss_dirty;
+ GPUTexture *coba_tex; /* 1D Texture array containing all color bands. */
+ GPUColorBandBuilder *coba_builder;
+
#ifndef NDEBUG
char name[64];
#endif
@@ -138,6 +147,47 @@ enum {
/* Functions */
+/* Returns the adress of the future pointer to coba_tex */
+GPUTexture **gpu_material_ramp_texture_row_set(GPUMaterial *mat, int size, float *pixels, float *row)
+{
+ /* In order to put all the colorbands into one 1D array texture,
+ * we need them to be the same size. */
+ BLI_assert(size == CM_TABLE + 1);
+
+ if (mat->coba_builder == NULL) {
+ mat->coba_builder = MEM_mallocN(sizeof(GPUColorBandBuilder), "GPUColorBandBuilder");
+ mat->coba_builder->current_layer = 0;
+ }
+
+ int layer = mat->coba_builder->current_layer;
+ *row = (float)layer;
+
+ if (*row == MAX_COLOR_BAND) {
+ printf("Too many color band in shader! Remove some Curve, Black Body or Color Ramp Node.\n");
+ }
+ else {
+ float *dst = (float *)mat->coba_builder->pixels[layer];
+ memcpy(dst, pixels, sizeof(float) * (CM_TABLE + 1) * 4);
+ mat->coba_builder->current_layer += 1;
+ }
+
+ return &mat->coba_tex;
+}
+
+static void gpu_material_ramp_texture_build(GPUMaterial *mat)
+{
+ if (mat->coba_builder == NULL)
+ return;
+
+ GPUColorBandBuilder *builder = mat->coba_builder;
+
+ mat->coba_tex = GPU_texture_create_1D_array(CM_TABLE + 1, builder->current_layer, GPU_RGBA16F,
+ (float *)builder->pixels, NULL);
+
+ MEM_freeN(builder);
+ mat->coba_builder = NULL;
+}
+
static void gpu_material_free_single(GPUMaterial *material)
{
/* Cancel / wait any pending lazy compilation. */
@@ -146,20 +196,21 @@ static void gpu_material_free_single(GPUMaterial *material)
GPU_pass_free_nodes(&material->nodes);
GPU_inputs_free(&material->inputs);
- if (material->pass)
+ if (material->pass != NULL) {
GPU_pass_release(material->pass);
-
+ }
if (material->ubo != NULL) {
GPU_uniformbuffer_free(material->ubo);
}
-
if (material->sss_tex_profile != NULL) {
GPU_texture_free(material->sss_tex_profile);
}
-
if (material->sss_profile != NULL) {
GPU_uniformbuffer_free(material->sss_profile);
}
+ if (material->coba_tex != NULL) {
+ GPU_texture_free(material->coba_tex);
+ }
}
void GPU_material_free(ListBase *gpumaterial)
@@ -622,6 +673,8 @@ GPUMaterial *GPU_material_from_nodetree(
bNodeTree *localtree = ntreeLocalize(ntree);
ntreeGPUMaterialNodes(localtree, mat, &has_surface_output, &has_volume_output);
+ gpu_material_ramp_texture_build(mat);
+
if (has_surface_output) {
mat->domain |= GPU_DOMAIN_SURFACE;
}