42 TFUNC_FLAME_SPECTRUM = 0,
46# define TFUNC_WIDTH 256
48static void create_flame_spectrum_texture(
float *
data)
51# define MAX_FIRE_ALPHA 0.06f
52# define FULL_ON_FIRE 100
54 float *spec_pixels = (
float *)
MEM_mallocN(TFUNC_WIDTH * 4 * 16 * 16 *
sizeof(
float),
59 for (
int i = 0; i < 16; i++) {
60 for (
int j = 0; j < 16; j++) {
61 for (
int k = 0; k < TFUNC_WIDTH; k++) {
62 int index = (j * TFUNC_WIDTH * 16 + i * TFUNC_WIDTH + k) * 4;
63 if (k >= FIRE_THRESH) {
65 spec_pixels[
index + 1] = (
data[k * 4 + 1]);
66 spec_pixels[
index + 2] = (
data[k * 4 + 2]);
67 spec_pixels[
index + 3] = MAX_FIRE_ALPHA *
70 (k - FIRE_THRESH) / (
float(FULL_ON_FIRE) - FIRE_THRESH));
79 memcpy(
data, spec_pixels,
sizeof(
float) * 4 * TFUNC_WIDTH);
88static void create_color_ramp(
const ColorBand *coba,
float *
data)
90 for (
int i = 0; i < TFUNC_WIDTH; i++) {
96static GPUTexture *create_transfer_function(
int type,
const ColorBand *coba)
98 float *
data = (
float *)
MEM_mallocN(
sizeof(
float[4]) * TFUNC_WIDTH, __func__);
101 case TFUNC_FLAME_SPECTRUM:
102 create_flame_spectrum_texture(
data);
104 case TFUNC_COLOR_RAMP:
105 create_color_ramp(coba,
data);
117static void swizzle_texture_channel_single(GPUTexture *tex)
124static float *rescale_3d(
const int dim[3],
125 const int final_dim[3],
127 const float *fpixels)
129 const uint w = dim[0], h = dim[1], d = dim[2];
130 const uint fw = final_dim[0], fh = final_dim[1], fd = final_dim[2];
131 const uint xf =
w / fw, yf = h / fh, zf = d / fd;
132 const uint pixel_count = fw * fh * fd;
136 printf(
"Performance: You need to scale a 3D texture, feel the pain!\n");
138 for (
uint k = 0; k < fd; k++) {
139 for (
uint j = 0; j < fh; j++) {
140 for (
uint i = 0; i < fw; i++) {
146 uint offset = k * (fw * fh) + i * fh + j;
147 uint offset_orig = (zb) * (
w * h) + (xb)*h + (yb);
150 nfpixels[offset * 4] = fpixels[offset_orig * 4];
151 nfpixels[offset * 4 + 1] = fpixels[offset_orig * 4 + 1];
152 nfpixels[offset * 4 + 2] = fpixels[offset_orig * 4 + 2];
153 nfpixels[offset * 4 + 3] = fpixels[offset_orig * 4 + 3];
156 nfpixels[offset] = fpixels[offset_orig];
169static GPUTexture *create_volume_texture(
const int dim[3],
174 GPUTexture *tex =
nullptr;
175 int final_dim[3] = {
UNPACK3(dim)};
177 if (
data ==
nullptr) {
185 if (tex !=
nullptr) {
189 if (final_dim[0] == 1 && final_dim[1] == 1 && final_dim[2] == 1) {
193 for (
int i = 0; i < 3; i++) {
194 final_dim[i] =
max_ii(1, final_dim[i] / 2);
198 if (tex ==
nullptr) {
199 printf(
"Error: Could not create 3D texture.\n");
207 printf(
"Error: Could not allocate 3D texture and not attempting to rescale non-float data.\n");
213 float *rescaled_data = rescale_3d(dim, final_dim,
channels,
static_cast<const float *
>(
data));
219 printf(
"Error: Could not allocate rescaled 3d texture!\n");
229 void *field =
nullptr;
233 if (single_precision) {
309 if (field ==
nullptr) {
313 GPUTexture *tex = create_volume_texture(fds->
res, texture_format, data_format, field);
314 swizzle_texture_channel_single(tex);
320 int *dim = (highres) ? fds->
res_noise : fds->res;
330 if (
data ==
nullptr) {
335 swizzle_texture_channel_single(tex);
349 int *dim = (highres) ? fds->
res_noise : fds->res;
350 float *
data = (
float *)
MEM_callocN(
sizeof(
float) * cell_count * 4,
"smokeColorTexture");
352 if (
data ==
nullptr) {
372 float *source =
nullptr;
375 int *dim = (highres) ? fds->
res_noise : fds->res;
389 swizzle_texture_channel_single(tex);
394 float **r_velocity_x,
395 float **r_velocity_y,
396 float **r_velocity_z)
417 return *r_velocity_x && *r_velocity_y && *r_velocity_z;
437 fds->
tex_field = create_field_texture(fds,
false);
448 fds->
tex_coba = create_transfer_function(TFUNC_COLOR_RAMP, fds->
coba);
464 fds->
tex_density = create_density_texture(fds, highres);
468 fds->
tex_color = create_color_texture(fds, highres);
472 fds->
tex_flame = create_flame_texture(fds, highres);
476 fds->
tex_flame_coba = create_transfer_function(TFUNC_FLAME_SPECTRUM,
nullptr);
495 float *vel_x =
nullptr, *vel_y =
nullptr, *vel_z =
nullptr;
497 if (!get_smoke_velocity_field(fds, &vel_x, &vel_y, &vel_z)) {
499 get_smoke_velocity_field(fds, &vel_x, &vel_y, &vel_z);
502 if (
ELEM(
nullptr, vel_x, vel_y, vel_z)) {
533 swizzle_texture_channel_single(fds->
tex_flags);
bool BKE_colorband_evaluate(const ColorBand *coba, float in, float out[4])
#define LISTBASE_FOREACH(type, var, list)
BLI_INLINE void BLI_listbase_clear(struct ListBase *lb)
void void BLI_freelistN(struct ListBase *listbase) ATTR_NONNULL(1)
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
struct LinkData * BLI_genericNodeN(void *data)
MINLINE int max_ii(int a, int b)
MINLINE void straight_to_premul_v4(float color[4])
MINLINE bool equals_v3v3_int(const int v1[3], const int v2[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void zero_v4(float r[4])
@ FLUID_DOMAIN_FIELD_COLOR_B
@ FLUID_DOMAIN_FIELD_FLAME
@ FLUID_DOMAIN_FIELD_REACT
@ FLUID_DOMAIN_FIELD_PHI_OUT
@ FLUID_DOMAIN_FIELD_FORCE_Z
@ FLUID_DOMAIN_FIELD_PHI_OBSTACLE
@ FLUID_DOMAIN_FIELD_FLAGS
@ FLUID_DOMAIN_FIELD_VELOCITY_Z
@ FLUID_DOMAIN_FIELD_FORCE_Y
@ FLUID_DOMAIN_FIELD_PRESSURE
@ FLUID_DOMAIN_FIELD_VELOCITY_X
@ FLUID_DOMAIN_FIELD_DENSITY
@ FLUID_DOMAIN_FIELD_VELOCITY_Y
@ FLUID_DOMAIN_FIELD_PHI_IN
@ FLUID_DOMAIN_FIELD_HEAT
@ FLUID_DOMAIN_FIELD_COLOR_G
@ FLUID_DOMAIN_FIELD_FORCE_X
@ FLUID_DOMAIN_FIELD_FUEL
@ FLUID_DOMAIN_FIELD_COLOR_R
@ FLUID_DOMAIN_VECTOR_FIELD_FORCE
@ FLUID_DOMAIN_VECTOR_FIELD_VELOCITY
@ FLUID_DOMAIN_VECTOR_FIELD_GUIDE_VELOCITY
GPUTexture * GPU_texture_create_1d(const char *name, int width, int mip_len, eGPUTextureFormat format, eGPUTextureUsage usage, const float *data)
void GPU_texture_free(GPUTexture *texture)
GPUTexture * GPU_texture_create_error(int dimension, bool array)
@ GPU_TEXTURE_USAGE_SHADER_READ
void GPU_texture_update_sub(GPUTexture *texture, eGPUDataFormat data_format, const void *pixels, int offset_x, int offset_y, int offset_z, int width, int height, int depth)
GPUTexture * GPU_texture_create_3d(const char *name, int width, int height, int depth, int mip_len, eGPUTextureFormat format, eGPUTextureUsage usage, const void *data)
#define GPU_TEXTURE_FREE_SAFE(texture)
void GPU_texture_swizzle_set(GPUTexture *texture, const char swizzle[4])
void IMB_colormanagement_blackbody_temperature_to_rgb_table(float *r_table, int width, float min, float max)
Read Guarded memory(de)allocation.
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Brightness Control the brightness and contrast of the input color Vector Map input vector components with curves Camera Retrieve information about the camera and how it relates to the current shading point s position Clamp a value between a minimum and a maximum Vector Perform vector math operation Invert Invert a producing a negative Combine Generate a color from its and blue channels(Deprecated)") DefNode(ShaderNode
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
void DRW_fluid_ensure_flags(FluidModifierData *fmd)
void DRW_smoke_ensure_coba_field(FluidModifierData *fmd)
void DRW_fluid_ensure_range_field(FluidModifierData *fmd)
void DRW_smoke_ensure(FluidModifierData *fmd, int highres)
void DRW_smoke_ensure_velocity(FluidModifierData *fmd)
void DRW_smoke_exit(DRWData *drw_data)
void DRW_smoke_init(DRWData *drw_data)
draw_view in_light_buf[] float
RAYTRACE_GROUP_SIZE additional_info("eevee_shared", "eevee_gbuffer_data", "eevee_global_ubo", "eevee_sampling_data", "eevee_utility_texture", "eevee_hiz_data", "draw_view") .specialization_constant(Type RAYTRACE_GROUP_SIZE in_sh_0_tx in_sh_2_tx screen_normal_tx GPU_RGBA8
void *(* MEM_mallocN)(size_t len, const char *str)
void MEM_freeN(void *vmemh)
void *(* MEM_callocN)(size_t len, const char *str)
float * manta_noise_get_density(struct MANTA *smoke)
float * manta_smoke_get_color_r(struct MANTA *smoke)
float * manta_get_force_z(struct MANTA *fluid)
bool manta_noise_has_colors(struct MANTA *smoke)
float * manta_get_force_y(struct MANTA *fluid)
float * manta_get_guide_velocity_y(struct MANTA *fluid)
float * manta_smoke_get_react(struct MANTA *smoke)
float * manta_smoke_get_shadow(struct MANTA *fluid)
float * manta_get_guide_velocity_z(struct MANTA *fluid)
float * manta_get_guide_velocity_x(struct MANTA *fluid)
void manta_noise_get_rgba(struct MANTA *smoke, float *data, int sequential)
float * manta_get_velocity_y(struct MANTA *fluid)
bool manta_noise_has_fuel(struct MANTA *smoke)
float * manta_get_force_x(struct MANTA *fluid)
float * manta_smoke_get_density(struct MANTA *smoke)
float * manta_get_phi(struct MANTA *fluid)
float * manta_get_phi_in(struct MANTA *fluid)
float * manta_get_velocity_z(struct MANTA *fluid)
bool manta_smoke_has_colors(struct MANTA *smoke)
float * manta_get_phiout_in(struct MANTA *fluid)
float * manta_get_phiobs_in(struct MANTA *fluid)
int * manta_smoke_get_flags(struct MANTA *smoke)
float * manta_get_velocity_x(struct MANTA *fluid)
bool manta_smoke_has_fuel(struct MANTA *smoke)
float * manta_get_pressure(struct MANTA *fluid)
float * manta_smoke_get_color_g(struct MANTA *smoke)
int manta_noise_get_cells(struct MANTA *smoke)
float * manta_smoke_get_heat(struct MANTA *smoke)
float * manta_smoke_get_color_b(struct MANTA *smoke)
void manta_smoke_get_rgba(struct MANTA *smoke, float *data, int sequential)
float * manta_smoke_get_fuel(struct MANTA *smoke)
float * manta_smoke_get_flame(struct MANTA *smoke)
float * manta_noise_get_flame(struct MANTA *smoke)
struct GPUTexture * tex_density
struct GPUTexture * tex_range_field
struct GPUTexture * tex_velocity_x
struct GPUTexture * tex_color
struct GPUTexture * tex_velocity_y
struct GPUTexture * tex_field
struct GPUTexture * tex_velocity_z
struct GPUTexture * tex_shadow
struct GPUTexture * tex_flags
struct GPUTexture * tex_coba
struct GPUTexture * tex_flame
struct GPUTexture * tex_flame_coba
struct FluidDomainSettings * domain