Blender  V3.3
eevee_lut_gen.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2020 Blender Foundation. */
3 
13 #include "DRW_render.h"
14 
15 #include "BLI_fileops.h"
16 #include "BLI_rand.h"
17 #include "BLI_string_utils.h"
18 
19 #include "eevee_private.h"
20 
21 #define DO_FILE_OUTPUT 0
22 
23 float *EEVEE_lut_update_ggx_brdf(int lut_size)
24 {
27  DRW_shgroup_uniform_float_copy(grp, "sampleCount", 64.0f); /* Actual sample count is squared. */
29 
30  GPUTexture *tex = DRW_texture_create_2d(lut_size, lut_size, GPU_RG16F, 0, NULL);
32  GPU_framebuffer_ensure_config(&fb,
33  {
34  GPU_ATTACHMENT_NONE,
35  GPU_ATTACHMENT_TEXTURE(tex),
36  });
38  DRW_draw_pass(pass);
39  GPU_FRAMEBUFFER_FREE_SAFE(fb);
40 
43 #if DO_FILE_OUTPUT
44  /* Content is to be put inside eevee_lut.c */
45  FILE *f = BLI_fopen("bsdf_split_sum_ggx.h", "w");
46  fprintf(f, "const float bsdf_split_sum_ggx[%d * %d * 2] = {", lut_size, lut_size);
47  for (int i = 0; i < lut_size * lut_size * 2;) {
48  fprintf(f, "\n ");
49  for (int j = 0; j < 4; j++, i += 2) {
50  fprintf(f, "%ff, %ff, ", data[i], data[i + 1]);
51  }
52  }
53  fprintf(f, "\n};\n");
54  fclose(f);
55 #endif
56 
57  return data;
58 }
59 
60 float *EEVEE_lut_update_ggx_btdf(int lut_size, int lut_depth)
61 {
62  float roughness;
65  DRW_shgroup_uniform_float_copy(grp, "sampleCount", 64.0f); /* Actual sample count is squared. */
66  DRW_shgroup_uniform_float(grp, "z", &roughness, 1);
68 
69  GPUTexture *tex = DRW_texture_create_2d_array(lut_size, lut_size, lut_depth, GPU_RG16F, 0, NULL);
71  for (int i = 0; i < lut_depth; i++) {
72  GPU_framebuffer_ensure_config(&fb,
73  {
74  GPU_ATTACHMENT_NONE,
75  GPU_ATTACHMENT_TEXTURE_LAYER(tex, i),
76  });
78  roughness = i / (lut_depth - 1.0f);
79  DRW_draw_pass(pass);
80  }
81 
82  GPU_FRAMEBUFFER_FREE_SAFE(fb);
83 
86 
87 #if DO_FILE_OUTPUT
88  /* Content is to be put inside eevee_lut.c. Don't forget to format the output. */
89  FILE *f = BLI_fopen("btdf_split_sum_ggx.h", "w");
90  fprintf(f, "const float btdf_split_sum_ggx[%d][%d * %d * 2] = {", lut_depth, lut_size, lut_size);
91  fprintf(f, "\n ");
92  int ofs = 0;
93  for (int d = 0; d < lut_depth; d++) {
94  fprintf(f, "{\n");
95  for (int i = 0; i < lut_size * lut_size * 2;) {
96  for (int j = 0; j < 4; j++, i += 2, ofs += 2) {
97  fprintf(f, "%ff, %ff, ", data[ofs], data[ofs + 1]);
98  }
99  fprintf(f, "\n ");
100  }
101  fprintf(f, "},\n");
102  }
103  fprintf(f, "};\n");
104  fclose(f);
105 #endif
106 
107  return data;
108 }
File and directory operations.
FILE * BLI_fopen(const char *filepath, const char *mode) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition: fileops.c:906
Random number functions.
@ DRW_STATE_WRITE_COLOR
Definition: DRW_render.h:303
struct GPUFrameBuffer GPUFrameBuffer
void GPU_framebuffer_bind(GPUFrameBuffer *fb)
struct GPUTexture GPUTexture
Definition: GPU_texture.h:17
void * GPU_texture_read(GPUTexture *tex, eGPUDataFormat data_format, int miplvl)
Definition: gpu_texture.cc:432
@ GPU_DATA_FLOAT
Definition: GPU_texture.h:171
void GPU_texture_free(GPUTexture *tex)
Definition: gpu_texture.cc:564
@ GPU_RG16F
Definition: GPU_texture.h:103
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:23
float * EEVEE_lut_update_ggx_btdf(int lut_size, int lut_depth)
Definition: eevee_lut_gen.c:60
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)