diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2012-11-20 21:40:10 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2012-11-20 21:40:10 +0400 |
commit | ab1b5af08d25b5c9bdb11110e4e8b607fdea3af5 (patch) | |
tree | 633ff1f0421b0a2b770dbe67ee48471b189e0cda /intern/cycles/kernel | |
parent | a80b0915c7e0dbbe1ce0d9abfd23809f1d870f3e (diff) |
Fix cycles OSL missing support for texture mapping paramaters found in texture
properties tab.
Diffstat (limited to 'intern/cycles/kernel')
11 files changed, 97 insertions, 21 deletions
diff --git a/intern/cycles/kernel/shaders/node_brick_texture.osl b/intern/cycles/kernel/shaders/node_brick_texture.osl index 478d9457001..b1f2a35789f 100644 --- a/intern/cycles/kernel/shaders/node_brick_texture.osl +++ b/intern/cycles/kernel/shaders/node_brick_texture.osl @@ -58,6 +58,8 @@ float brick(point p, float mortar_size, float bias, } shader node_brick_texture( + int use_mapping = 0, + matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), float Offset = 0.5, int OffsetFrequency = 2, float Squash = 1.0, @@ -74,10 +76,15 @@ shader node_brick_texture( output float Fac = 0.0, output color Color = color(0.2, 0.2, 0.2)) { + point p = Vector; + + if (use_mapping) + p = transform(mapping, p); + float tint = 0.0; color Col = Color1; - Fac = brick(Vector * Scale, MortarSize, Bias, BrickWidth, RowHeight, + Fac = brick(p * Scale, MortarSize, Bias, BrickWidth, RowHeight, Offset, OffsetFrequency, Squash, SquashFrequency, tint); if (Fac != 1.0) { diff --git a/intern/cycles/kernel/shaders/node_checker_texture.osl b/intern/cycles/kernel/shaders/node_checker_texture.osl index 577caf308ff..eed56f4453a 100644 --- a/intern/cycles/kernel/shaders/node_checker_texture.osl +++ b/intern/cycles/kernel/shaders/node_checker_texture.osl @@ -40,6 +40,8 @@ float checker(point p) } shader node_checker_texture( + int use_mapping = 0, + matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), float Scale = 5.0, point Vector = P, color Color1 = color(0.8, 0.8, 0.8), @@ -47,7 +49,12 @@ shader node_checker_texture( output float Fac = 0.0, output color Color = color(0.0, 0.0, 0.0)) { - Fac = checker(Vector * Scale); + point p = Vector; + + if (use_mapping) + p = transform(mapping, p); + + Fac = checker(p * Scale); if (Fac == 1.0) { Color = Color1; } diff --git a/intern/cycles/kernel/shaders/node_environment_texture.osl b/intern/cycles/kernel/shaders/node_environment_texture.osl index a177f0ad1ad..90c7ce475ae 100644 --- a/intern/cycles/kernel/shaders/node_environment_texture.osl +++ b/intern/cycles/kernel/shaders/node_environment_texture.osl @@ -40,6 +40,8 @@ vector environment_texture_direction_to_mirrorball(vector dir) { } shader node_environment_texture( + int use_mapping = 0, + matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), vector Vector = P, string filename = "", string projection = "Equirectangular", @@ -47,16 +49,20 @@ shader node_environment_texture( output color Color = color(0.0, 0.0, 0.0), output float Alpha = 1.0) { - vector Vec = normalize(Vector); + vector p = Vector; - if (projection == "Equirectangular") { - Vec = environment_texture_direction_to_equirectangular(Vec); - } - else { - Vec = environment_texture_direction_to_mirrorball(Vec); - } + if (use_mapping) + p = transform(mapping, p); + + p = normalize(p); - Color = (color)texture(filename, Vec[0], 1.0 - Vec[1], "wrap", "periodic", "alpha", Alpha); + if (projection == "Equirectangular") + p = environment_texture_direction_to_equirectangular(p); + else + p = environment_texture_direction_to_mirrorball(p); + + /* todo: use environment for better texture filtering of equirectangular */ + Color = (color)texture(filename, p[0], 1.0 - p[1], "wrap", "periodic", "alpha", Alpha); if (color_space == "sRGB") Color = color_srgb_to_scene_linear(Color); diff --git a/intern/cycles/kernel/shaders/node_gradient_texture.osl b/intern/cycles/kernel/shaders/node_gradient_texture.osl index ae7cfa51f59..8d862dbad67 100644 --- a/intern/cycles/kernel/shaders/node_gradient_texture.osl +++ b/intern/cycles/kernel/shaders/node_gradient_texture.osl @@ -63,12 +63,19 @@ float gradient(point p, string type) } shader node_gradient_texture( + int use_mapping = 0, + matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), string Type = "Linear", point Vector = P, output float Fac = 0.0, output color Color = color(0.0, 0.0, 0.0)) { - Fac = gradient(Vector, Type); + point p = Vector; + + if (use_mapping) + p = transform(mapping, p); + + Fac = gradient(p, Type); Color = color(Fac, Fac, Fac); } diff --git a/intern/cycles/kernel/shaders/node_image_texture.osl b/intern/cycles/kernel/shaders/node_image_texture.osl index 6393605e6b5..53c4aeaeb5f 100644 --- a/intern/cycles/kernel/shaders/node_image_texture.osl +++ b/intern/cycles/kernel/shaders/node_image_texture.osl @@ -30,6 +30,8 @@ color image_texture_lookup(string filename, string color_space, float u, float v } shader node_image_texture( + int use_mapping = 0, + matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), point Vector = P, string filename = "", string color_space = "sRGB", @@ -38,8 +40,13 @@ shader node_image_texture( output color Color = color(0.0, 0.0, 0.0), output float Alpha = 1.0) { + point p = Vector; + + if (use_mapping) + p = transform(mapping, p); + if (projection == "Flat") { - Color = image_texture_lookup(filename, color_space, Vector[0], Vector[1], Alpha); + Color = image_texture_lookup(filename, color_space, p[0], p[1], Alpha); } else if (projection == "Box") { /* object space normal */ @@ -104,15 +111,15 @@ shader node_image_texture( float tmp_alpha; if (weight[0] > 0.0) { - Color += weight[0]*image_texture_lookup(filename, color_space, Vector[1], Vector[2], tmp_alpha); + Color += weight[0]*image_texture_lookup(filename, color_space, p[1], p[2], tmp_alpha); Alpha += weight[0]*tmp_alpha; } if (weight[1] > 0.0) { - Color += weight[1]*image_texture_lookup(filename, color_space, Vector[0], Vector[2], tmp_alpha); + Color += weight[1]*image_texture_lookup(filename, color_space, p[0], p[2], tmp_alpha); Alpha += weight[1]*tmp_alpha; } if (weight[2] > 0.0) { - Color += weight[2]*image_texture_lookup(filename, color_space, Vector[1], Vector[0], tmp_alpha); + Color += weight[2]*image_texture_lookup(filename, color_space, p[1], p[0], tmp_alpha); Alpha += weight[2]*tmp_alpha; } } diff --git a/intern/cycles/kernel/shaders/node_magic_texture.osl b/intern/cycles/kernel/shaders/node_magic_texture.osl index e464b83bc9e..b81a30499b2 100644 --- a/intern/cycles/kernel/shaders/node_magic_texture.osl +++ b/intern/cycles/kernel/shaders/node_magic_texture.osl @@ -93,12 +93,19 @@ color magic(point p, int n, float distortion) } shader node_magic_texture( + int use_mapping = 0, + matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), int Depth = 2, float Distortion = 5.0, float Scale = 5.0, point Vector = P, output color Color = color(0.0, 0.0, 0.0)) { - Color = magic(Vector * Scale, Depth, Distortion); + point p = Vector; + + if (use_mapping) + p = transform(mapping, p); + + Color = magic(p * Scale, Depth, Distortion); } diff --git a/intern/cycles/kernel/shaders/node_musgrave_texture.osl b/intern/cycles/kernel/shaders/node_musgrave_texture.osl index 71461b8fd79..afdbca27a3f 100644 --- a/intern/cycles/kernel/shaders/node_musgrave_texture.osl +++ b/intern/cycles/kernel/shaders/node_musgrave_texture.osl @@ -187,6 +187,8 @@ float noise_musgrave_ridged_multi_fractal(point p, string basis, float H, /* Shader */ shader node_musgrave_texture( + int use_mapping = 0, + matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), string Type = "fBM", float Dimension = 2.0, float Lacunarity = 1.0, @@ -204,7 +206,12 @@ shader node_musgrave_texture( string Basis = "Perlin"; float intensity = 1.0; - point p = Vector * Scale; + point p = Vector; + + if (use_mapping) + p = transform(mapping, p); + + p = p * Scale; if (Type == "Multifractal") Fac = intensity * noise_musgrave_multi_fractal(p, Basis, dimension, lacunarity, octaves); diff --git a/intern/cycles/kernel/shaders/node_noise_texture.osl b/intern/cycles/kernel/shaders/node_noise_texture.osl index 227b2bf8cea..0a379491781 100644 --- a/intern/cycles/kernel/shaders/node_noise_texture.osl +++ b/intern/cycles/kernel/shaders/node_noise_texture.osl @@ -43,6 +43,8 @@ float noise(point p, string basis, float distortion, float detail, float fac, co } shader node_noise_texture( + int use_mapping = 0, + matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), float Distortion = 0.0, float Scale = 5.0, float Detail = 2.0, @@ -50,7 +52,12 @@ shader node_noise_texture( output float Fac = 0.0, output color Color = color(0.2, 0.2, 0.2)) { + point p = Vector; + + if (use_mapping) + p = transform(mapping, p); + string Basis = "Perlin"; - Fac = noise(Vector * Scale, Basis, Distortion, Detail, Fac, Color); + Fac = noise(p * Scale, Basis, Distortion, Detail, Fac, Color); } diff --git a/intern/cycles/kernel/shaders/node_sky_texture.osl b/intern/cycles/kernel/shaders/node_sky_texture.osl index 98986ba1d65..24a63c78458 100644 --- a/intern/cycles/kernel/shaders/node_sky_texture.osl +++ b/intern/cycles/kernel/shaders/node_sky_texture.osl @@ -149,14 +149,21 @@ void precompute_sunsky(vector dir, float turbidity, output KernelSunSky sunsky) } shader node_sky_texture( + int use_mapping = 0, + matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), vector Vector = P, vector sun_direction = vector(0, 0, 1), float turbidity = 2.2, output color Color = color(0.0, 0.0, 0.0)) { + vector p = Vector; + + if (use_mapping) + p = transform(mapping, p); + KernelSunSky sunsky; precompute_sunsky(sun_direction, turbidity, sunsky); - Color = sky_xyz_radiance(sunsky, Vector); + Color = sky_xyz_radiance(sunsky, p); } diff --git a/intern/cycles/kernel/shaders/node_voronoi_texture.osl b/intern/cycles/kernel/shaders/node_voronoi_texture.osl index a44df00a267..43f8ecc666a 100644 --- a/intern/cycles/kernel/shaders/node_voronoi_texture.osl +++ b/intern/cycles/kernel/shaders/node_voronoi_texture.osl @@ -22,17 +22,24 @@ /* Voronoi */ shader node_voronoi_texture( + int use_mapping = 0, + matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), string Coloring = "Intensity", float Scale = 5.0, point Vector = P, output float Fac = 0.0, output color Color = color(0.0, 0.0, 0.0)) { + point p = Vector; + + if (use_mapping) + p = transform(mapping, p); + /* compute distance and point coordinate of 4 nearest neighbours */ float da[4]; point pa[4]; - voronoi(Vector * Scale, "Distance Squared", 1.0, da, pa); + voronoi(p * Scale, "Distance Squared", 1.0, da, pa); /* Colored output */ if (Coloring == "Intensity") { diff --git a/intern/cycles/kernel/shaders/node_wave_texture.osl b/intern/cycles/kernel/shaders/node_wave_texture.osl index 79b8a8885d1..6648cd06278 100644 --- a/intern/cycles/kernel/shaders/node_wave_texture.osl +++ b/intern/cycles/kernel/shaders/node_wave_texture.osl @@ -46,6 +46,8 @@ float wave(point p, float scale, string type, float detail, float distortion, fl } shader node_wave_texture( + int use_mapping = 0, + matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), string Type = "Bands", float Scale = 5.0, float Distortion = 0.0, @@ -55,7 +57,12 @@ shader node_wave_texture( output float Fac = 0.0, output color Color = color (0.0, 0.0, 0.0)) { - Fac = wave(Vector, Scale, Type, Detail, Distortion, DetailScale); + point p = Vector; + + if (use_mapping) + p = transform(mapping, p); + + Fac = wave(p, Scale, Type, Detail, Distortion, DetailScale); Color = color(Fac, Fac, Fac); } |