Blender  V2.93
eevee_lut_gen.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * Copyright 2020, Blender Foundation.
17  */
18 
28 #include "DRW_render.h"
29 
30 #include "BLI_fileops.h"
31 #include "BLI_rand.h"
32 #include "BLI_string_utils.h"
33 
34 #include "eevee_private.h"
35 
36 #define DO_FILE_OUTPUT 0
37 
38 float *EEVEE_lut_update_ggx_brdf(int lut_size)
39 {
42  DRW_shgroup_uniform_float_copy(grp, "sampleCount", 64.0f); /* Actual sample count is squared. */
44 
45  GPUTexture *tex = DRW_texture_create_2d(lut_size, lut_size, GPU_RG16F, 0, NULL);
47  GPU_framebuffer_ensure_config(&fb,
48  {
49  GPU_ATTACHMENT_NONE,
50  GPU_ATTACHMENT_TEXTURE(tex),
51  });
53  DRW_draw_pass(pass);
55 
58 #if DO_FILE_OUTPUT
59  /* Content is to be put inside eevee_lut.c */
60  FILE *f = BLI_fopen("bsdf_split_sum_ggx.h", "w");
61  fprintf(f, "const float bsdf_split_sum_ggx[%d * %d * 2] = {", lut_size, lut_size);
62  for (int i = 0; i < lut_size * lut_size * 2;) {
63  fprintf(f, "\n ");
64  for (int j = 0; j < 4; j++, i += 2) {
65  fprintf(f, "%ff, %ff, ", data[i], data[i + 1]);
66  }
67  }
68  fprintf(f, "\n};\n");
69  fclose(f);
70 #endif
71 
72  return data;
73 }
74 
75 float *EEVEE_lut_update_ggx_btdf(int lut_size, int lut_depth)
76 {
77  float roughness;
80  DRW_shgroup_uniform_float_copy(grp, "sampleCount", 64.0f); /* Actual sample count is squared. */
81  DRW_shgroup_uniform_float(grp, "z", &roughness, 1);
83 
84  GPUTexture *tex = DRW_texture_create_2d_array(lut_size, lut_size, lut_depth, GPU_RG16F, 0, NULL);
86  for (int i = 0; i < lut_depth; i++) {
87  GPU_framebuffer_ensure_config(&fb,
88  {
89  GPU_ATTACHMENT_NONE,
90  GPU_ATTACHMENT_TEXTURE_LAYER(tex, i),
91  });
93  roughness = i / (lut_depth - 1.0f);
94  DRW_draw_pass(pass);
95  }
96 
98 
101 
102 #if DO_FILE_OUTPUT
103  /* Content is to be put inside eevee_lut.c. Don't forget to format the output. */
104  FILE *f = BLI_fopen("btdf_split_sum_ggx.h", "w");
105  fprintf(f, "const float btdf_split_sum_ggx[%d][%d * %d * 2] = {", lut_depth, lut_size, lut_size);
106  fprintf(f, "\n ");
107  int ofs = 0;
108  for (int d = 0; d < lut_depth; d++) {
109  fprintf(f, "{\n");
110  for (int i = 0; i < lut_size * lut_size * 2;) {
111  for (int j = 0; j < 4; j++, i += 2, ofs += 2) {
112  fprintf(f, "%ff, %ff, ", data[ofs], data[ofs + 1]);
113  }
114  fprintf(f, "\n ");
115  }
116  fprintf(f, "},\n");
117  }
118  fprintf(f, "};\n");
119  fclose(f);
120 #endif
121 
122  return data;
123 }
File and directory operations.
FILE * BLI_fopen(const char *filename, const char *mode) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition: fileops.c:1003
Random number functions.
@ DRW_STATE_WRITE_COLOR
Definition: DRW_render.h:315
struct GPUFrameBuffer GPUFrameBuffer
#define GPU_FRAMEBUFFER_FREE_SAFE(fb)
void GPU_framebuffer_bind(GPUFrameBuffer *fb)
struct GPUTexture GPUTexture
Definition: GPU_texture.h:33
void * GPU_texture_read(GPUTexture *tex, eGPUDataFormat data_format, int miplvl)
Definition: gpu_texture.cc:371
@ GPU_DATA_FLOAT
Definition: GPU_texture.h:172
void GPU_texture_free(GPUTexture *tex)
Definition: gpu_texture.cc:508
@ GPU_RG16F
Definition: GPU_texture.h:104
void DRW_shgroup_uniform_float_copy(DRWShadingGroup *shgroup, const char *name, const float value)
void DRW_shgroup_call_procedural_triangles(DRWShadingGroup *shgroup, Object *ob, uint tri_count)
DRWShadingGroup * DRW_shgroup_create(struct GPUShader *shader, DRWPass *pass)
DRWPass * DRW_pass_create(const char *name, DRWState state)
void DRW_shgroup_uniform_float(DRWShadingGroup *shgroup, const char *name, const float *value, int arraysize)
void DRW_draw_pass(DRWPass *pass)
GPUTexture * DRW_texture_create_2d_array(int w, int h, int d, eGPUTextureFormat format, DRWTextureFlag flags, const float *fpixels)
GPUTexture * DRW_texture_create_2d(int w, int h, eGPUTextureFormat format, DRWTextureFlag flags, const float *fpixels)
float * EEVEE_lut_update_ggx_brdf(int lut_size)
Definition: eevee_lut_gen.c:38
float * EEVEE_lut_update_ggx_btdf(int lut_size, int lut_depth)
Definition: eevee_lut_gen.c:75
struct GPUShader * EEVEE_shaders_ggx_lut_sh_get(void)
struct GPUShader * EEVEE_shaders_ggx_refraction_lut_sh_get(void)
BLI_INLINE float fb(float length, float L)
static const pxr::TfToken roughness("roughness", pxr::TfToken::Immortal)