Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/kernel/osl/shaders/node_environment_texture.osl
| Context not available. | |||||
| return vector(u, v, 0.0); | return vector(u, v, 0.0); | ||||
| } | } | ||||
| void environment_texture_cubemap_xyz_to_uv( | |||||
| vector dir, output float u, output float v, output float max_axis, output int index) | |||||
| { | |||||
| float abs_x = abs(dir.x); | |||||
| float abs_y = abs(dir.y); | |||||
| float abs_z = abs(dir.z); | |||||
| int is_x_positive = dir.x > 0.0 ? 1 : 0; | |||||
| int is_y_positive = dir.y > 0.0 ? 1 : 0; | |||||
| int is_z_positive = dir.z > 0.0 ? 1 : 0; | |||||
| if (is_x_positive && abs_x >= abs_y && abs_x >= abs_z) { | |||||
| max_axis = abs_x; | |||||
| u = dir.y; | |||||
| v = dir.z; | |||||
| index = 0; | |||||
| } | |||||
| if (!is_x_positive && abs_x >= abs_y && abs_x >= abs_z) { | |||||
| max_axis = abs_x; | |||||
| u = -dir.y; | |||||
| v = dir.z; | |||||
| index = 1; | |||||
| } | |||||
| if (is_y_positive && abs_y >= abs_x && abs_y >= abs_z) { | |||||
| max_axis = abs_y; | |||||
| u = -dir.x; | |||||
| v = dir.z; | |||||
| index = 2; | |||||
| } | |||||
| if (!is_y_positive && abs_y >= abs_x && abs_y >= abs_z) { | |||||
| max_axis = abs_y; | |||||
| u = dir.x; | |||||
| v = dir.z; | |||||
| index = 3; | |||||
| } | |||||
| if (is_z_positive && abs_z >= abs_x && abs_z >= abs_y) { | |||||
| max_axis = abs_z; | |||||
| u = dir.x; | |||||
| v = dir.y; | |||||
| index = 4; | |||||
| } | |||||
| if (!is_z_positive && abs_z >= abs_x && abs_z >= abs_y) { | |||||
| max_axis = abs_z; | |||||
| u = dir.x; | |||||
| v = dir.y; | |||||
| index = 5; | |||||
| } | |||||
| } | |||||
| vector environment_texture_cubemap_cross_horizontal(float uc, float vc, float max_axis, int index) | |||||
| { | |||||
| float u = 0.125 * (uc / max_axis + 1.0); | |||||
| float v = 0.166667 * (vc / max_axis + 1.0); | |||||
| if (index == 0) { | |||||
| u += 0.5; | |||||
| v += 0.333333; | |||||
| } | |||||
| else if (index == 1) { | |||||
| v += 0.333333; | |||||
| } | |||||
| else if (index == 2) { | |||||
| u += 0.75; | |||||
| v += 0.333333; | |||||
| } | |||||
| else if (index == 3) { | |||||
| u += 0.25; | |||||
| v += 0.333333; | |||||
| } | |||||
| else if (index == 4) { | |||||
| u += 0.25; | |||||
| v += 0.666666; | |||||
| } | |||||
| else if (index == 5) { | |||||
| u += 0.25; | |||||
| v = 0.333333 - v; | |||||
| } | |||||
| return vector(u, v, 0.0); | |||||
| } | |||||
| vector environment_texture_cubemap_stripe_horizontal(float uc, float vc, float max_axis, int index) | |||||
| { | |||||
| float u = 0.083333 * (uc / max_axis + 1.0); | |||||
| float v = 0.5 * (vc / max_axis + 1.0); | |||||
| if (index == 1) | |||||
| u += 0.166666; | |||||
| else if (index == 2) | |||||
| u += 0.166666 * 5; | |||||
| else if (index == 3) | |||||
| u += 0.166666 * 4; | |||||
| else if (index == 4) | |||||
| u += 0.166666 * 2; | |||||
| else if (index == 5) { | |||||
| u += 0.166666 * 3; | |||||
| v = 1.0 - v; | |||||
| } | |||||
| return vector(u, v, 0.0); | |||||
| } | |||||
| vector environment_texture_cubemap_stripe_vertical(float uc, float vc, float max_axis, int index) | |||||
| { | |||||
| float u = 0.5 * (uc / max_axis + 1.0); | |||||
| float v = 0.083333 * (vc / max_axis + 1.0); | |||||
| if (index == 0) | |||||
| v += 0.166666 * 5; | |||||
| else if (index == 1) | |||||
| v += 0.166666 * 4; | |||||
| else if (index == 3) | |||||
| v += 0.166666; | |||||
| else if (index == 4) | |||||
| v += 0.166666 * 3; | |||||
| else if (index == 5) | |||||
| v = 0.166666 * 3 - v; | |||||
| return vector(u, v, 0.0); | |||||
| } | |||||
| vector environment_texture_direction_to_cubemap(vector dir, string cubemap_layout) | |||||
| { | |||||
| float max_axis = 0.0; | |||||
| float uc = 0.0; | |||||
| float vc = 0.0; | |||||
| int index = -1; | |||||
| environment_texture_cubemap_xyz_to_uv(dir, uc, vc, max_axis, index); | |||||
| if (cubemap_layout == "cross_horizontal") | |||||
| return environment_texture_cubemap_cross_horizontal(uc, vc, max_axis, index); | |||||
| else if (cubemap_layout == "stripe_horizontal") | |||||
| return environment_texture_cubemap_stripe_horizontal(uc, vc, max_axis, index); | |||||
| else | |||||
| return environment_texture_cubemap_stripe_vertical(uc, vc, max_axis, index); | |||||
| } | |||||
| shader node_environment_texture( | shader node_environment_texture( | ||||
| int use_mapping = 0, | int use_mapping = 0, | ||||
| matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), | matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), | ||||
| vector Vector = P, | vector Vector = P, | ||||
| string filename = "", | string filename = "", | ||||
| string projection = "equirectangular", | string projection = "equirectangular", | ||||
| string cubemap_layout = "cross_horizontal", | |||||
| string interpolation = "linear", | string interpolation = "linear", | ||||
| int compress_as_srgb = 0, | int compress_as_srgb = 0, | ||||
| int ignore_alpha = 0, | int ignore_alpha = 0, | ||||
| Context not available. | |||||
| if (projection == "equirectangular") | if (projection == "equirectangular") | ||||
| p = environment_texture_direction_to_equirectangular(p); | p = environment_texture_direction_to_equirectangular(p); | ||||
| else | else if (projection == "mirror_ball") | ||||
| p = environment_texture_direction_to_mirrorball(p); | p = environment_texture_direction_to_mirrorball(p); | ||||
| else | |||||
| p = environment_texture_direction_to_cubemap(p, cubemap_layout); | |||||
| /* todo: use environment for better texture filtering of equirectangular */ | /* todo: use environment for better texture filtering of equirectangular */ | ||||
| Color = (color)texture( | Color = (color)texture( | ||||
| Context not available. | |||||