44 TFUNC_FLAME_SPECTRUM = 0,
48# define TFUNC_WIDTH 256
50static void create_flame_spectrum_texture(
float *
data)
53# define MAX_FIRE_ALPHA 0.06f
54# define FULL_ON_FIRE 100
61 for (
int i = 0; i < 16; i++) {
62 for (
int j = 0; j < 16; j++) {
63 for (
int k = 0; k < TFUNC_WIDTH; k++) {
64 int index = (j * TFUNC_WIDTH * 16 + i * TFUNC_WIDTH + k) * 4;
65 if (k >= FIRE_THRESH) {
67 spec_pixels[
index + 1] = (
data[k * 4 + 1]);
68 spec_pixels[
index + 2] = (
data[k * 4 + 2]);
69 spec_pixels[
index + 3] = MAX_FIRE_ALPHA *
72 (k - FIRE_THRESH) / (
float(FULL_ON_FIRE) - FIRE_THRESH));
81 memcpy(
data, spec_pixels,
sizeof(
float) * 4 * TFUNC_WIDTH);
83 MEM_delete(spec_pixels);
90static void create_color_ramp(
const ColorBand *coba,
float *
data)
92 for (
int i = 0; i < TFUNC_WIDTH; i++) {
103 case TFUNC_FLAME_SPECTRUM:
104 create_flame_spectrum_texture(
data);
106 case TFUNC_COLOR_RAMP:
107 create_color_ramp(coba,
data);
114 gpu::TextureFormat::SRGBA_8_8_8_8,
123static void swizzle_texture_channel_single(
gpu::Texture *tex)
130static float *rescale_3d(
const int dim[3],
131 const int final_dim[3],
133 const float *fpixels)
135 const uint w = dim[0], h = dim[1], d = dim[2];
136 const uint fw = final_dim[0], fh = final_dim[1], fd = final_dim[2];
137 const uint xf =
w / fw, yf = h / fh, zf = d / fd;
138 const uint pixel_count = fw * fh * fd;
142 printf(
"Performance: You need to scale a 3D texture, feel the pain!\n");
144 for (
uint k = 0; k < fd; k++) {
145 for (
uint j = 0; j < fh; j++) {
146 for (
uint i = 0; i < fw; i++) {
152 uint offset = k * (fw * fh) + i * fh + j;
153 uint offset_orig = (zb) * (
w * h) + (xb)*h + (yb);
156 nfpixels[offset * 4] = fpixels[offset_orig * 4];
157 nfpixels[offset * 4 + 1] = fpixels[offset_orig * 4 + 1];
158 nfpixels[offset * 4 + 2] = fpixels[offset_orig * 4 + 2];
159 nfpixels[offset * 4 + 3] = fpixels[offset_orig * 4 + 3];
161 else if (channels == 1) {
162 nfpixels[offset] = fpixels[offset_orig];
175static gpu::Texture *create_volume_texture(
const int dim[3],
183 if (
data ==
nullptr) {
191 if (tex !=
nullptr) {
195 if (final_dim[0] == 1 && final_dim[1] == 1 && final_dim[2] == 1) {
199 for (
int i = 0; i < 3; i++) {
200 final_dim[i] =
max_ii(1, final_dim[i] / 2);
204 if (tex ==
nullptr) {
205 printf(
"Error: Could not create 3D texture.\n");
208 else if (
int3(dim) == final_dim) {
213 printf(
"Error: Could not allocate 3D texture and not attempting to rescale non-float data.\n");
218 int channels =
ELEM(texture_format,
219 gpu::TextureFormat::UNORM_8,
220 gpu::TextureFormat::SFLOAT_16,
221 gpu::TextureFormat::SFLOAT_32) ?
224 float *rescaled_data = rescale_3d(dim, final_dim, channels,
static_cast<const float *
>(
data));
227 MEM_delete(rescaled_data);
230 printf(
"Error: Could not allocate rescaled 3d texture!\n");
240 void *field =
nullptr;
244 if (single_precision) {
245 texture_format = gpu::TextureFormat::SFLOAT_32;
248 switch (fds->coba_field) {
293 texture_format = gpu::TextureFormat::SFLOAT_16;
297 texture_format = gpu::TextureFormat::SFLOAT_16;
301 texture_format = gpu::TextureFormat::SFLOAT_16;
305 texture_format = gpu::TextureFormat::SFLOAT_16;
310 texture_format = gpu::TextureFormat::UINT_8;
314 texture_format = gpu::TextureFormat::SFLOAT_16;
320 if (field ==
nullptr) {
324 gpu::Texture *tex = create_volume_texture(fds->res, texture_format, data_format, field);
325 swizzle_texture_channel_single(tex);
331 int *dim = (highres) ? fds->res_noise : fds->res;
341 if (
data ==
nullptr) {
347 swizzle_texture_channel_single(tex);
361 int *dim = (highres) ? fds->res_noise : fds->res;
364 if (
data ==
nullptr) {
385 float *source =
nullptr;
388 int *dim = (highres) ? fds->res_noise : fds->res;
403 swizzle_texture_channel_single(tex);
408 float **r_velocity_x,
409 float **r_velocity_y,
410 float **r_velocity_z)
412 const char vector_field = fds->vector_field;
431 return *r_velocity_x && *r_velocity_y && *r_velocity_z;
451 fds->
tex_field = create_field_texture(fds,
false);
462 fds->
tex_coba = create_transfer_function(TFUNC_COLOR_RAMP, fds->
coba);
478 fds->
tex_density = create_density_texture(fds, highres);
482 fds->
tex_color = create_color_texture(fds, highres);
486 fds->
tex_flame = create_flame_texture(fds, highres);
490 fds->
tex_flame_coba = create_transfer_function(TFUNC_FLAME_SPECTRUM,
nullptr);
495 gpu::TextureFormat::UNORM_8,
511 float *vel_x =
nullptr, *vel_y =
nullptr, *vel_z =
nullptr;
513 if (!get_smoke_velocity_field(fds, &vel_x, &vel_y, &vel_z)) {
515 get_smoke_velocity_field(fds, &vel_x, &vel_y, &vel_z);
518 if (
ELEM(
nullptr, vel_x, vel_y, vel_z)) {
526 gpu::TextureFormat::SFLOAT_16,
532 gpu::TextureFormat::SFLOAT_16,
538 gpu::TextureFormat::SFLOAT_16,
561 swizzle_texture_channel_single(fds->
tex_flags);
#define GPU_TEXTURE_FREE_SAFE(texture)
Read Blender memory allocation and freeing.
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
@ FLUID_DOMAIN_FIELD_COLOR_G
@ FLUID_DOMAIN_FIELD_FLAGS
@ FLUID_DOMAIN_FIELD_FUEL
@ FLUID_DOMAIN_FIELD_FORCE_Y
@ FLUID_DOMAIN_FIELD_PHI_OBSTACLE
@ FLUID_DOMAIN_FIELD_REACT
@ FLUID_DOMAIN_FIELD_PHI_IN
@ FLUID_DOMAIN_FIELD_FLAME
@ FLUID_DOMAIN_FIELD_COLOR_B
@ FLUID_DOMAIN_FIELD_PRESSURE
@ FLUID_DOMAIN_FIELD_VELOCITY_Z
@ FLUID_DOMAIN_FIELD_FORCE_X
@ FLUID_DOMAIN_FIELD_FORCE_Z
@ FLUID_DOMAIN_FIELD_DENSITY
@ FLUID_DOMAIN_FIELD_VELOCITY_Y
@ FLUID_DOMAIN_FIELD_COLOR_R
@ FLUID_DOMAIN_FIELD_VELOCITY_X
@ FLUID_DOMAIN_FIELD_PHI_OUT
@ FLUID_DOMAIN_FIELD_HEAT
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void DRW_fluid_ensure_flags(FluidModifierData *fmd)
gpu::Texture * GPU_texture_create_1d(const char *name, int width, int mip_len, gpu::TextureFormat format, eGPUTextureUsage usage, const float *data)
float * manta_get_guide_velocity_x(struct MANTA *fluid)
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
float * manta_smoke_get_react(struct MANTA *smoke)
float * manta_smoke_get_shadow(struct MANTA *smoke)
void DRW_smoke_ensure_coba_field(FluidModifierData *fmd)
float * manta_get_force_x(struct MANTA *fluid)
void manta_smoke_get_rgba(struct MANTA *smoke, float *data, int sequential)
float * manta_get_phiout_in(struct MANTA *fluid)
float * manta_get_phi_in(struct MANTA *fluid)
float * manta_smoke_get_heat(struct MANTA *smoke)
MINLINE int max_ii(int a, int b)
bool BKE_colorband_evaluate(const ColorBand *coba, float in, float out[4])
@ FLUID_DOMAIN_VECTOR_FIELD_VELOCITY
@ FLUID_DOMAIN_VECTOR_FIELD_FORCE
@ FLUID_DOMAIN_VECTOR_FIELD_GUIDE_VELOCITY
float * manta_noise_get_density(struct MANTA *smoke)
float * manta_get_pressure(struct MANTA *fluid)
float * manta_get_guide_velocity_y(struct MANTA *fluid)
bool manta_smoke_has_colors(struct MANTA *smoke)
MINLINE void zero_v4(float r[4])
void GPU_texture_update_sub(gpu::Texture *texture, eGPUDataFormat data_format, const void *pixels, int offset_x, int offset_y, int offset_z, int width, int height, int depth, uint unpack_row_length=0)
float * manta_get_velocity_z(struct MANTA *fluid)
VecBase< int32_t, 3 > int3
float * manta_get_force_z(struct MANTA *fluid)
@ GPU_TEXTURE_USAGE_SHADER_READ
BMesh const char void * data
float * manta_smoke_get_color_r(struct MANTA *smoke)
void GPU_texture_swizzle_set(gpu::Texture *texture, const char swizzle[4])
void DRW_smoke_ensure_velocity(FluidModifierData *fmd)
gpu::Texture * GPU_texture_create_3d(const char *name, int width, int height, int depth, int mip_len, gpu::TextureFormat format, eGPUTextureUsage usage, const void *data)
LinkData * BLI_genericNodeN(void *data)
float * manta_get_force_y(struct MANTA *fluid)
void DRW_smoke_ensure(FluidModifierData *fmd, int highres)
bool manta_smoke_has_fuel(struct MANTA *smoke)
float * manta_smoke_get_fuel(struct MANTA *smoke)
float * manta_smoke_get_density(struct MANTA *smoke)
int * manta_smoke_get_flags(struct MANTA *smoke)
float * manta_get_guide_velocity_z(struct MANTA *fluid)
float * manta_noise_get_flame(struct MANTA *smoke)
void DRW_smoke_exit(DRWData *drw_data)
float * manta_get_phi(struct MANTA *fluid)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
void IMB_colormanagement_blackbody_temperature_to_rgb_table(float *r_table, int width, float min, float max)
void GPU_texture_free(gpu::Texture *texture)
float * manta_smoke_get_flame(struct MANTA *smoke)
float * manta_get_phiobs_in(struct MANTA *fluid)
void manta_noise_get_rgba(struct MANTA *smoke, float *data, int sequential)
float * manta_get_velocity_x(struct MANTA *fluid)
gpu::Texture * GPU_texture_create_error(int dimension, bool array)
bool manta_noise_has_fuel(struct MANTA *smoke)
float * manta_get_velocity_y(struct MANTA *fluid)
float * manta_smoke_get_color_b(struct MANTA *smoke)
void DRW_fluid_ensure_range_field(FluidModifierData *fmd)
MINLINE void straight_to_premul_v4(float color[4])
float * manta_smoke_get_color_g(struct MANTA *smoke)
void DRW_smoke_begin_sync(DRWData *drw_data)
int manta_noise_get_cells(struct MANTA *smoke)
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
bool manta_noise_has_colors(struct MANTA *smoke)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
ListBaseT< LinkData > smoke_textures
gpu::Texture * tex_range_field
gpu::Texture * tex_velocity_z
eFluidDomain_CobaField coba_field
gpu::Texture * tex_density
gpu::Texture * tex_velocity_x
gpu::Texture * tex_velocity_y
FLUID_DisplayVectorField vector_field
gpu::Texture * tex_shadow
gpu::Texture * tex_flame_coba
struct FluidDomainSettings * domain