20 #include "../node_shader_util.h"
26 {
SOCK_VECTOR,
N_(
"Vector"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f,
PROP_NONE,
SOCK_HIDE_VALUE},
31 {
SOCK_RGBA,
N_(
"Color"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f,
PROP_NONE,
SOCK_NO_INTERNAL_LINK},
40 tex->sun_direction[0] = 0.0f;
41 tex->sun_direction[1] = 0.0f;
42 tex->sun_direction[2] = 1.0f;
43 tex->turbidity = 2.2f;
44 tex->ground_albedo = 0.3f;
47 tex->sun_intensity = 1.0f;
49 tex->sun_rotation = 0.0f;
51 tex->air_density = 1.0f;
52 tex->dust_density = 1.0f;
53 tex->ozone_density = 1.0f;
65 float r[3],
g[3],
b[3];
70 float ctheta =
cosf(theta);
71 float cgamma =
cosf(gamma);
73 return (1.0 + lam[0] *
expf(lam[1] / ctheta)) *
74 (1.0 + lam[2] *
expf(lam[3] * gamma) + lam[4] * cgamma * cgamma);
79 float theta = sun_angles[0];
80 float theta2 = theta * theta;
81 float theta3 = theta2 * theta;
84 float chi = (4.0f / 9.0f -
T / 120.0f) * (
M_PI - 2.0f * theta);
86 sunsky->
radiance[0] = (4.0453f *
T - 4.9710f) *
tanf(chi) - 0.2155f *
T + 2.4192f;
89 sunsky->
radiance[1] = (0.00166f * theta3 - 0.00375f * theta2 + 0.00209f * theta) *
T2 +
90 (-0.02903f * theta3 + 0.06377f * theta2 - 0.03202f * theta + 0.00394f) *
92 (0.11693f * theta3 - 0.21196f * theta2 + 0.06052f * theta + 0.25886f);
94 sunsky->
radiance[2] = (0.00275f * theta3 - 0.00610f * theta2 + 0.00317f * theta) *
T2 +
95 (-0.04214f * theta3 + 0.08970f * theta2 - 0.04153f * theta + 0.00516f) *
97 (0.15346f * theta3 - 0.26756f * theta2 + 0.06670f * theta + 0.26688f);
99 sunsky->
config_Y[0] = (0.1787f *
T - 1.4630f);
100 sunsky->
config_Y[1] = (-0.3554f *
T + 0.4275f);
101 sunsky->
config_Y[2] = (-0.0227f *
T + 5.3251f);
102 sunsky->
config_Y[3] = (0.1206f *
T - 2.5771f);
103 sunsky->
config_Y[4] = (-0.0670f *
T + 0.3703f);
105 sunsky->
config_x[0] = (-0.0193f *
T - 0.2592f);
106 sunsky->
config_x[1] = (-0.0665f *
T + 0.0008f);
107 sunsky->
config_x[2] = (-0.0004f *
T + 0.2125f);
108 sunsky->
config_x[3] = (-0.0641f *
T - 0.8989f);
109 sunsky->
config_x[4] = (-0.0033f *
T + 0.0452f);
111 sunsky->
config_y[0] = (-0.0167f *
T - 0.2608f);
112 sunsky->
config_y[1] = (-0.0950f *
T + 0.0092f);
113 sunsky->
config_y[2] = (-0.0079f *
T + 0.2102f);
114 sunsky->
config_y[3] = (-0.0441f *
T - 1.6537f);
115 sunsky->
config_y[4] = (-0.0109f *
T + 0.0529f);
146 sun_angles[0] =
acosf(
tex->sun_direction[2]);
147 sun_angles[1] =
atan2f(
tex->sun_direction[0],
tex->sun_direction[1]);
149 if (
tex->sky_model == 0) {
157 "node_tex_sky_preetham",
173 if (
tex->sky_model == 1) {
175 sun_angles[0] = fmin(
M_PI_2, sun_angles[0]);
177 tex->turbidity,
tex->ground_albedo, fmax(0.0,
M_PI_2 - sun_angles[0]));
179 float config_x07[8], config_y07[8], config_z07[8], config_xyz8[3];
180 for (
int i = 0; i < 8; ++i) {
182 config_y07[i] = (
float)sky_state->
configs[1][i];
185 for (
int i = 0; i < 3; ++i) {
189 for (
int i = 0; i < 3; i++) {
197 "node_tex_sky_hosekwilkie",
typedef float(TangentPoint)[2]
void node_type_gpu(struct bNodeType *ntype, NodeGPUExecFunction gpu_fn)
void nodeSetSocketAvailability(struct bNodeSocket *sock, bool is_available)
void node_type_socket_templates(struct bNodeType *ntype, struct bNodeSocketTemplate *inputs, struct bNodeSocketTemplate *outputs)
void node_type_update(struct bNodeType *ntype, void(*updatefunc)(struct bNodeTree *ntree, struct bNode *node))
void node_type_init(struct bNodeType *ntype, void(*initfunc)(struct bNodeTree *ntree, struct bNode *node))
void node_type_size_preset(struct bNodeType *ntype, eNodeSizePreset size)
void node_type_storage(struct bNodeType *ntype, const char *storagename, void(*freefunc)(struct bNode *node), void(*copyfunc)(struct bNodeTree *dest_ntree, struct bNode *dest_node, const struct bNode *src_node))
struct bNodeSocket * nodeFindSocket(const struct bNode *node, eNodeSocketInOut in_out, const char *identifier)
#define NODE_CLASS_TEXTURE
void nodeRegisterType(struct bNodeType *ntype)
void BKE_texture_mapping_default(struct TexMapping *texmap, int type)
void BKE_texture_colormapping_default(struct ColorMapping *colormap)
#define TEXMAP_TYPE_POINT
GPUNodeLink * GPU_uniform(const float *num)
bool GPU_stack_link(GPUMaterial *mat, struct bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
const float * IMB_colormangement_get_xyz_to_rgb(void)
Group RGB to Bright Vector Camera Vector Combine Material Light Line Style Layer Add Ambient Diffuse Glossy Refraction Transparent Toon Principled Hair Volume Principled Light Particle Volume Image SH_NODE_TEX_SKY
CCL_NAMESPACE_BEGIN ccl_device float3 xyz_to_rgb(KernelGlobals *kg, float3 xyz)
void *(* MEM_callocN)(size_t len, const char *str)
static float sky_perez_function(const float *lam, float theta, float gamma)
static void node_shader_update_sky(bNodeTree *UNUSED(ntree), bNode *node)
static bNodeSocketTemplate sh_node_tex_sky_out[]
static void get_XYZ_to_RGB_for_gpu(XYZ_to_RGB *data)
struct XYZ_to_RGB XYZ_to_RGB
static void node_shader_init_tex_sky(bNodeTree *UNUSED(ntree), bNode *node)
static void sky_precompute_old(SkyModelPreetham *sunsky, const float sun_angles[], float turbidity)
static int node_shader_gpu_tex_sky(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static bNodeSocketTemplate sh_node_tex_sky_in[]
struct SkyModelPreetham SkyModelPreetham
void register_node_type_sh_tex_sky(void)
void node_shader_gpu_tex_mapping(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *UNUSED(out))
void sh_node_type_base(struct bNodeType *ntype, int type, const char *name, short nclass, short flag)
void node_shader_gpu_default_tex_coord(GPUMaterial *mat, bNode *node, GPUNodeLink **link)
void node_copy_standard_storage(bNodeTree *UNUSED(dest_ntree), bNode *dest_node, const bNode *src_node)
void node_free_standard_storage(bNode *node)
void SKY_arhosekskymodelstate_free(SKY_ArHosekSkyModelState *state)
SKY_ArHosekSkyModelState * SKY_arhosek_xyz_skymodelstate_alloc_init(const double turbidity, const double albedo, const double elevation)
SKY_ArHosekSkyModelConfiguration configs[11]
Compact definition of a node socket.