53 TFUNC_FLAME_SPECTRUM = 0,
57 # define TFUNC_WIDTH 256
59 static void create_flame_spectrum_texture(
float *
data)
61 # define FIRE_THRESH 7
62 # define MAX_FIRE_ALPHA 0.06f
63 # define FULL_ON_FIRE 100
65 float *spec_pixels = (
float *)
MEM_mallocN(TFUNC_WIDTH * 4 * 16 * 16 *
sizeof(
float),
70 for (
int i = 0; i < 16; i++) {
71 for (
int j = 0; j < 16; j++) {
72 for (
int k = 0; k < TFUNC_WIDTH; k++) {
73 int index = (j * TFUNC_WIDTH * 16 + i * TFUNC_WIDTH + k) * 4;
74 if (k >= FIRE_THRESH) {
75 spec_pixels[index] = (
data[k * 4]);
76 spec_pixels[index + 1] = (
data[k * 4 + 1]);
77 spec_pixels[index + 2] = (
data[k * 4 + 2]);
78 spec_pixels[index + 3] = MAX_FIRE_ALPHA *
81 (k - FIRE_THRESH) / ((
float)FULL_ON_FIRE - FIRE_THRESH));
90 memcpy(
data, spec_pixels,
sizeof(
float) * 4 * TFUNC_WIDTH);
95 # undef MAX_FIRE_ALPHA
99 static void create_color_ramp(
const struct ColorBand *coba,
float *
data)
101 for (
int i = 0; i < TFUNC_WIDTH; i++) {
109 float *
data = (
float *)
MEM_mallocN(
sizeof(
float[4]) * TFUNC_WIDTH, __func__);
112 case TFUNC_FLAME_SPECTRUM:
113 create_flame_spectrum_texture(
data);
115 case TFUNC_COLOR_RAMP:
116 create_color_ramp(coba,
data);
134 static float *rescale_3d(
const int dim[3],
135 const int final_dim[3],
137 const float *fpixels)
139 const uint w = dim[0], h = dim[1], d = dim[2];
140 const uint fw = final_dim[0], fh = final_dim[1], fd = final_dim[2];
141 const uint xf =
w / fw, yf = h / fh, zf = d / fd;
142 const uint pixel_count = fw * fh * fd;
143 float *nfpixels = (
float *)
MEM_mallocN(channels *
sizeof(
float) * pixel_count, __func__);
146 printf(
"Performance: You need to scale a 3D texture, feel the pain!\n");
148 for (
uint k = 0; k < fd; k++) {
149 for (
uint j = 0; j < fh; j++) {
150 for (
uint i = 0; i < fw; i++) {
156 uint offset = k * (fw * fh) + i * fh + j;
157 uint offset_orig = (zb) * (
w * h) + (xb)*h + (yb);
160 nfpixels[offset * 4] = fpixels[offset_orig * 4];
161 nfpixels[offset * 4 + 1] = fpixels[offset_orig * 4 + 1];
162 nfpixels[offset * 4 + 2] = fpixels[offset_orig * 4 + 2];
163 nfpixels[offset * 4 + 3] = fpixels[offset_orig * 4 + 3];
165 else if (channels == 1) {
166 nfpixels[offset] = fpixels[offset_orig];
179 static GPUTexture *create_volume_texture(
const int dim[3],
185 int final_dim[3] = {
UNPACK3(dim)};
193 "volume",
UNPACK3(final_dim), 1, texture_format, data_format,
NULL);
199 if (final_dim[0] == 1 && final_dim[1] == 1 && final_dim[2] == 1) {
203 for (
int i = 0; i < 3; i++) {
204 final_dim[i] =
max_ii(1, final_dim[i] / 2);
209 printf(
"Error: Could not create 3D texture.\n");
217 printf(
"Error: Could not allocate 3D texture and not attempting to rescale non-float data.\n");
223 float *rescaled_data = rescale_3d(dim, final_dim, channels,
data);
229 printf(
"Error: Could not allocate rescaled 3d texture!\n");
243 if (single_precision) {
323 GPUTexture *
tex = create_volume_texture(fds->
res, texture_format, data_format, field);
324 swizzle_texture_channel_single(
tex);
345 swizzle_texture_channel_single(
tex);
360 float *
data = (
float *)
MEM_callocN(
sizeof(
float) * cell_count * 4,
"smokeColorTexture");
382 float *source =
NULL;
399 swizzle_texture_channel_single(
tex);
404 float **r_velocity_x,
405 float **r_velocity_y,
406 float **r_velocity_z)
427 return *r_velocity_x && *r_velocity_y && *r_velocity_z;
487 fds->
tex_field = create_field_texture(fds,
false);
496 fds->
tex_coba = create_transfer_function(TFUNC_COLOR_RAMP, fds->
coba);
511 fds->
tex_density = create_density_texture(fds, highres);
514 fds->
tex_color = create_color_texture(fds, highres);
517 fds->
tex_flame = create_flame_texture(fds, highres);
539 if (!get_smoke_velocity_field(fds, &vel_x, &vel_y, &vel_z)) {
541 get_smoke_velocity_field(fds, &vel_x, &vel_y, &vel_z);
544 if (
ELEM(
NULL, vel_x, vel_y, vel_z)) {
571 swizzle_texture_channel_single(fds->
tex_flags);
typedef float(TangentPoint)[2]
bool BKE_colorband_evaluate(const struct ColorBand *coba, float in, float out[4])
MINLINE int max_ii(int a, int b)
MINLINE void straight_to_premul_v4(float color[4])
void blackbody_temperature_to_rgb_table(float *r_table, int width, float min, float max)
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
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
void GPU_texture_swizzle_set(GPUTexture *tex, const char swizzle[4])
void GPU_texture_update_sub(GPUTexture *tex, 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_1d(const char *name, int w, int mip_len, eGPUTextureFormat format, const float *data)
struct GPUTexture GPUTexture
void GPU_texture_free(GPUTexture *tex)
GPUTexture * GPU_texture_create_3d(const char *name, int w, int h, int d, int mip_len, eGPUTextureFormat texture_format, eGPUDataFormat data_format, const void *data)
GPUTexture * GPU_texture_create_error(int dimension, bool array)
Read Guarded memory(de)allocation.
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_free_velocity(FluidModifierData *fmd)
void DRW_smoke_free(FluidModifierData *fmd)
void(* MEM_freeN)(void *vmemh)
void *(* MEM_callocN)(size_t len, const char *str)
void *(* MEM_mallocN)(size_t len, const char *str)
float * manta_smoke_get_shadow(struct MANTA *fluid)
float * manta_smoke_get_color_g(struct MANTA *smoke)
float * manta_get_force_y(struct MANTA *fluid)
float * manta_get_phiobs_in(struct MANTA *fluid)
float * manta_smoke_get_color_b(struct MANTA *smoke)
float * manta_smoke_get_fuel(struct MANTA *smoke)
float * manta_smoke_get_heat(struct MANTA *smoke)
bool manta_noise_has_colors(struct MANTA *smoke)
float * manta_get_guide_velocity_z(struct MANTA *fluid)
float * manta_smoke_get_density(struct MANTA *smoke)
float * manta_smoke_get_color_r(struct MANTA *smoke)
float * manta_get_force_x(struct MANTA *fluid)
float * manta_get_velocity_x(struct MANTA *fluid)
float * manta_smoke_get_flame(struct MANTA *smoke)
int * manta_smoke_get_flags(struct MANTA *smoke)
float * manta_get_phi_in(struct MANTA *fluid)
float * manta_get_velocity_y(struct MANTA *fluid)
void manta_noise_get_rgba(struct MANTA *smoke, float *data, int sequential)
bool manta_noise_has_fuel(struct MANTA *smoke)
float * manta_get_phi(struct MANTA *fluid)
float * manta_get_force_z(struct MANTA *fluid)
float * manta_get_pressure(struct MANTA *fluid)
float * manta_noise_get_density(struct MANTA *smoke)
float * manta_get_guide_velocity_x(struct MANTA *fluid)
float * manta_get_phiout_in(struct MANTA *fluid)
float * manta_noise_get_flame(struct MANTA *smoke)
bool manta_smoke_has_colors(struct MANTA *smoke)
float * manta_get_velocity_z(struct MANTA *fluid)
bool manta_smoke_has_fuel(struct MANTA *smoke)
float * manta_smoke_get_react(struct MANTA *smoke)
int manta_noise_get_cells(struct MANTA *smoke)
float * manta_get_guide_velocity_y(struct MANTA *fluid)
void manta_smoke_get_rgba(struct MANTA *smoke, float *data, int sequential)
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