42 TFUNC_FLAME_SPECTRUM = 0,
46 # define TFUNC_WIDTH 256
48 static void create_flame_spectrum_texture(
float *
data)
50 # define FIRE_THRESH 7
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) {
64 spec_pixels[index] = (
data[k * 4]);
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);
84 # undef MAX_FIRE_ALPHA
88 static void create_color_ramp(
const struct ColorBand *coba,
float *
data)
90 for (
int i = 0; i < TFUNC_WIDTH; i++) {
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);
123 static float *rescale_3d(
const int dim[3],
124 const int final_dim[3],
126 const float *fpixels)
128 const uint w = dim[0], h = dim[1],
d = dim[2];
129 const uint fw = final_dim[0], fh = final_dim[1], fd = final_dim[2];
130 const uint xf =
w / fw, yf = h / fh, zf =
d / fd;
131 const uint pixel_count = fw * fh * fd;
135 printf(
"Performance: You need to scale a 3D texture, feel the pain!\n");
137 for (
uint k = 0; k < fd; k++) {
138 for (
uint j = 0; j < fh; j++) {
139 for (
uint i = 0; i < fw; i++) {
146 uint offset_orig = (zb) * (
w * h) + (xb)*h + (yb);
149 nfpixels[
offset * 4] = fpixels[offset_orig * 4];
150 nfpixels[
offset * 4 + 1] = fpixels[offset_orig * 4 + 1];
151 nfpixels[
offset * 4 + 2] = fpixels[offset_orig * 4 + 2];
152 nfpixels[
offset * 4 + 3] = fpixels[offset_orig * 4 + 3];
155 nfpixels[
offset] = fpixels[offset_orig];
168 static GPUTexture *create_volume_texture(
const int dim[3],
174 int final_dim[3] = {
UNPACK3(dim)};
182 "volume",
UNPACK3(final_dim), 1, texture_format, data_format,
NULL);
188 if (final_dim[0] == 1 && final_dim[1] == 1 && final_dim[2] == 1) {
192 for (
int i = 0; i < 3; i++) {
193 final_dim[i] =
max_ii(1, final_dim[i] / 2);
198 printf(
"Error: Could not create 3D texture.\n");
206 printf(
"Error: Could not allocate 3D texture and not attempting to rescale non-float data.\n");
212 float *rescaled_data = rescale_3d(dim, final_dim,
channels,
data);
218 printf(
"Error: Could not allocate rescaled 3d texture!\n");
232 if (single_precision) {
312 GPUTexture *
tex = create_volume_texture(fds->
res, texture_format, data_format, field);
313 swizzle_texture_channel_single(
tex);
334 swizzle_texture_channel_single(
tex);
349 float *
data = (
float *)
MEM_callocN(
sizeof(
float) * cell_count * 4,
"smokeColorTexture");
371 float *source =
NULL;
388 swizzle_texture_channel_single(
tex);
393 float **r_velocity_x,
394 float **r_velocity_y,
395 float **r_velocity_z)
416 return *r_velocity_x && *r_velocity_y && *r_velocity_z;
436 fds->
tex_field = create_field_texture(fds,
false);
446 fds->
tex_coba = create_transfer_function(TFUNC_COLOR_RAMP, fds->
coba);
462 fds->
tex_density = create_density_texture(fds, highres);
466 fds->
tex_color = create_color_texture(fds, highres);
470 fds->
tex_flame = create_flame_texture(fds, highres);
495 if (!get_smoke_velocity_field(fds, &vel_x, &vel_y, &vel_z)) {
497 get_smoke_velocity_field(fds, &vel_x, &vel_y, &vel_z);
500 if (
ELEM(
NULL, vel_x, vel_y, vel_z)) {
531 swizzle_texture_channel_single(fds->
tex_flags);
typedef float(TangentPoint)[2]
bool BKE_colorband_evaluate(const struct ColorBand *coba, float in, float out[4])
#define LISTBASE_FOREACH(type, var, list)
BLI_INLINE void BLI_listbase_clear(struct ListBase *lb)
struct LinkData * BLI_genericNodeN(void *data)
void void BLI_freelistN(struct ListBase *listbase) ATTR_NONNULL(1)
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
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
_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)
#define GPU_TEXTURE_FREE_SAFE(texture)
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)
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 Bright Control the brightness and contrast of the input color Vector Map an input vectors to used to fine tune the interpolation of the input 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 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)
depth_tx normal_tx diffuse_light_tx specular_light_tx volume_light_tx environment_tx ambient_occlusion_tx aov_value_tx GPU_R32F
ccl_gpu_kernel_postfix ccl_global float int int int int float bool int offset
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