diff options
Diffstat (limited to 'intern/cycles/kernel/shaders/node_image_texture.osl')
-rw-r--r-- | intern/cycles/kernel/shaders/node_image_texture.osl | 53 |
1 files changed, 51 insertions, 2 deletions
diff --git a/intern/cycles/kernel/shaders/node_image_texture.osl b/intern/cycles/kernel/shaders/node_image_texture.osl index 18b5fb4b31f..526a87525cd 100644 --- a/intern/cycles/kernel/shaders/node_image_texture.osl +++ b/intern/cycles/kernel/shaders/node_image_texture.osl @@ -11,12 +11,50 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and - * limitations under the License + * limitations under the License. */ #include "stdosl.h" #include "node_color.h" +point texco_remap_square(point co) +{ + return (co - point(0.5, 0.5, 0.5)) * 2.0; +} + +point map_to_tube(vector dir) +{ + float u, v; + v = (dir[2] + 1.0) * 0.5; + float len = sqrt(dir[0]*dir[0] + dir[1]*dir[1]); + if (len > 0.0) { + u = (1.0 - (atan2(dir[0] / len, dir[1] / len) / M_PI)) * 0.5; + } + else { + v = u = 0.0; /* To avoid un-initialized variables. */ + } + return point(u, v, 0.0); +} + +point map_to_sphere(vector dir) +{ + float len = length(dir); + float v, u; + if(len > 0.0) { + if(dir[0] == 0.0 && dir[1] == 0.0) { + u = 0.0; /* Othwise domain error. */ + } + else { + u = (1.0 - atan2(dir[0], dir[1]) / M_PI) / 2.0; + } + v = 1.0 - acos(dir[2] / len) / M_PI; + } + else { + v = u = 0.0; /* To avoid un-initialized variables. */ + } + return point(u, v, 0.0); +} + color image_texture_lookup(string filename, string color_space, float u, float v, output float Alpha, int use_alpha, int is_float, string interpolation) { color rgb = (color)texture(filename, u, 1.0 - v, "wrap", "periodic", "interp", interpolation, "alpha", Alpha); @@ -136,5 +174,16 @@ shader node_image_texture( Alpha += weight[2] * tmp_alpha; } } + else if (projection == "Sphere") { + point projected = map_to_sphere(texco_remap_square(p)); + Color = image_texture_lookup(filename, color_space, + projected[0], projected[1], + Alpha, use_alpha, is_float, interpolation); + } + else if (projection == "Tube") { + point projected = map_to_tube(texco_remap_square(p)); + Color = image_texture_lookup(filename, color_space, + projected[0], projected[1], + Alpha, use_alpha, is_float, interpolation); + } } - |