diff options
Diffstat (limited to 'intern/cycles/kernel/shaders')
18 files changed, 185 insertions, 50 deletions
diff --git a/intern/cycles/kernel/shaders/CMakeLists.txt b/intern/cycles/kernel/shaders/CMakeLists.txt index 4f5a97c1bb6..f7fec62fd6d 100644 --- a/intern/cycles/kernel/shaders/CMakeLists.txt +++ b/intern/cycles/kernel/shaders/CMakeLists.txt @@ -89,7 +89,7 @@ foreach(_file ${SRC_OSL}) list(APPEND SRC_OSO ${_OSO_FILE} ) - + unset(_OSL_FILE) unset(_OSO_FILE) endforeach() diff --git a/intern/cycles/kernel/shaders/SConscript b/intern/cycles/kernel/shaders/SConscript new file mode 100644 index 00000000000..36b86d7b4f6 --- /dev/null +++ b/intern/cycles/kernel/shaders/SConscript @@ -0,0 +1,42 @@ +#!/usr/bin/python +import sys +import os +import Blender as B + +def normpath(path): + return os.path.abspath(os.path.normpath(path)) + +Import ('env') + +oso_files = [] + +if env['WITH_BF_CYCLES_OSL']: + shaders = env.Clone() + + # osl compiler + osl_compiler = File(env.subst(env['BF_OSL_COMPILER'])).abspath + + # build directory + root_build_dir = normpath(env['BF_BUILDDIR']) + build_dir = os.path.join(root_build_dir, 'intern/cycles/kernel/shaders') + + # source directories and files + source_dir = Dir('.').srcnode().path + + # dependencies + dependencies = shaders.Glob('*.h') + + for f in os.listdir(source_dir): + if f.endswith('.osl'): + osl_file = os.path.join(source_dir, f) + oso_file = os.path.join(build_dir, f.replace('.osl', '.oso')) + + command = "%s -O2 -I%s -o %s %s" % (osl_compiler, source_dir, oso_file, osl_file) + + shaders.Command(oso_file, f, command) + shaders.Depends(oso_file, [f] + dependencies) + + oso_files.append(oso_file) + + +Return('oso_files') diff --git a/intern/cycles/kernel/shaders/node_ambient_occlusion.osl b/intern/cycles/kernel/shaders/node_ambient_occlusion.osl index 57a06f35461..b9423344e73 100644 --- a/intern/cycles/kernel/shaders/node_ambient_occlusion.osl +++ b/intern/cycles/kernel/shaders/node_ambient_occlusion.osl @@ -19,6 +19,7 @@ #include "stdosl.h" shader node_ambient_occlusion( + normal NormalIn = N, color Color = color(0.8, 0.8, 0.8), output closure color AO = ambient_occlusion()) { 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_brightness.osl b/intern/cycles/kernel/shaders/node_brightness.osl index 8e9f5c9c796..b263d815566 100644 --- a/intern/cycles/kernel/shaders/node_brightness.osl +++ b/intern/cycles/kernel/shaders/node_brightness.osl @@ -20,32 +20,15 @@ shader node_brightness( color ColorIn = color(0.8, 0.8, 0.8), - float Brightness = 0.0, + float Bright = 0.0, float Contrast = 0.0, output color ColorOut = color(0.8, 0.8, 0.8)) { - float delta = Contrast * (1.0 / 200.0); - float a = 1.0 - delta * 2.0; - float b; + float a = 1.0 + Contrast; + float b = Bright - Contrast*0.5; - /* input value is a percentage */ - float bright_factor = Brightness / 100.0; - - /* - * The algorithm is by Werner D. Streidt - * (http://visca.com/ffactory/archives/5-99/msg00021.html) - * Extracted of OpenCV demhist.c - */ - - if (Contrast > 0.0) { - a = (a < 0.0 ? 1.0 / a : 0.0); - b = a * (bright_factor - delta); - } - else { - delta *= -1.0; - b = a * (bright_factor + delta); - } - - ColorOut = a * ColorIn + b; + ColorOut[0] = max(a*ColorIn[0] + b, 0.0); + ColorOut[1] = max(a*ColorIn[1] + b, 0.0); + ColorOut[2] = max(a*ColorIn[2] + b, 0.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 bad62e56ab4..4367f7f4994 100644 --- a/intern/cycles/kernel/shaders/node_environment_texture.osl +++ b/intern/cycles/kernel/shaders/node_environment_texture.osl @@ -19,14 +19,52 @@ #include "stdosl.h" #include "node_color.h" +vector environment_texture_direction_to_equirectangular(vector dir) +{ + float u = -atan2(dir[1], dir[0])/(2.0*M_PI) + 0.5; + float v = atan2(dir[2], hypot(dir[0], dir[1]))/M_PI + 0.5; + + return vector(u, v, 0.0); +} + +vector environment_texture_direction_to_mirrorball(vector dir) +{ + dir[1] -= 1.0; + + float div = 2.0*sqrt(max(-0.5*dir[1], 0.0)); + if(div > 0.0) + dir /= div; + + float u = 0.5*(dir[0] + 1.0); + float v = 0.5*(dir[2] + 1.0); + + return vector(u, v, 0.0); +} + 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", string color_space = "sRGB", output color Color = color(0.0, 0.0, 0.0), output float Alpha = 1.0) { - Color = (color)environment(filename, Vector, "alpha", Alpha); + vector p = Vector; + + if (use_mapping) + p = transform(mapping, p); + + p = normalize(p); + + 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_hsv.osl b/intern/cycles/kernel/shaders/node_hsv.osl index 8fd7a1612e8..0f4bedfb0f8 100644 --- a/intern/cycles/kernel/shaders/node_hsv.osl +++ b/intern/cycles/kernel/shaders/node_hsv.osl @@ -27,7 +27,6 @@ shader node_hsv( color ColorIn = color(0.0, 0.0, 0.0), output color ColorOut = color(0.0, 0.0, 0.0)) { - float t = clamp(Fac, 0.0, 1.0); color Color = rgb_to_hsv(ColorIn); // remember: fmod doesn't work for negative numbers @@ -38,6 +37,6 @@ shader node_hsv( Color = hsv_to_rgb(Color); - ColorOut = mix(Color, ColorIn, t); + ColorOut = mix(ColorIn, Color, 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 932fb1e2f17..24a63c78458 100644 --- a/intern/cycles/kernel/shaders/node_sky_texture.osl +++ b/intern/cycles/kernel/shaders/node_sky_texture.osl @@ -43,9 +43,9 @@ color xyY_to_xyz(float x, float y, float Y) color xyz_to_rgb(float x, float y, float z) { - return color(3.240479 * x + -1.537150 * y + -0.498535 * z, - -0.969256 * x + 1.875991 * y + 0.041556 * z, - 0.055648 * x + -0.204043 * y + 1.057311 * z); + return color( 3.240479 * x + -1.537150 * y + -0.498535 * z, + -0.969256 * x + 1.875991 * y + 0.041556 * z, + 0.055648 * x + -0.204043 * y + 1.057311 * z); } float sky_angle_between(float thetav, float phiv, float theta, float phi) @@ -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_texture_coordinate.osl b/intern/cycles/kernel/shaders/node_texture_coordinate.osl index 791838dfffe..37460bcfc98 100644 --- a/intern/cycles/kernel/shaders/node_texture_coordinate.osl +++ b/intern/cycles/kernel/shaders/node_texture_coordinate.osl @@ -56,7 +56,7 @@ shader node_texture_coordinate( Camera = transform("camera", P); Window = transform("NDC", P); Normal = transform("world", "object", NormalIn); - Reflection = reflect(I, NormalIn); + Reflection = -reflect(I, NormalIn); } if (bump_offset == "dx") { @@ -77,5 +77,7 @@ shader node_texture_coordinate( Camera += Dy(Camera); Window += Dy(Window); } + + Window[2] = 0.0; } 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_ward_bsdf.osl b/intern/cycles/kernel/shaders/node_ward_bsdf.osl index e5c6f0ad705..82ce15ab9b6 100644 --- a/intern/cycles/kernel/shaders/node_ward_bsdf.osl +++ b/intern/cycles/kernel/shaders/node_ward_bsdf.osl @@ -30,20 +30,20 @@ shader node_ward_bsdf( /* rotate tangent around normal */ vector T = Tangent; - if(Rotation != 0.0) + if (Rotation != 0.0) T = rotate(T, Rotation*2.0*M_PI, point(0.0, 0.0, 0.0), Normal); /* compute roughness */ float RoughnessU, RoughnessV; float aniso = clamp(Anisotropy, -0.99, 0.99); - if(aniso < 0.0) { - RoughnessU = Roughness/(1.0 + aniso); - RoughnessV = Roughness*(1.0 + aniso); + if (aniso < 0.0) { + RoughnessU = Roughness / (1.0 + aniso); + RoughnessV = Roughness * (1.0 + aniso); } else { - RoughnessU = Roughness*(1.0 - aniso); - RoughnessV = Roughness/(1.0 - aniso); + RoughnessU = Roughness * (1.0 - aniso); + RoughnessV = Roughness / (1.0 - aniso); } BSDF = Color * ward(Normal, T, RoughnessU, RoughnessV); 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); } |