diff --git a/CMakeLists.txt b/CMakeLists.txt index e54992a35..b1d9d0fdf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -288,7 +288,8 @@ TESTSUITE ( and-or-not-synonyms aastep arithmetic array array-derivs array-range struct-nested struct-nested-assign struct-nested-deep ternary testshade-expr - texture-alpha texture-blur texture-connected-options + texture-alpha texture-aniso + texture-blur texture-connected-options texture-derivs texture-errormsg texture-firstchannel texture-interp texture-missingcolor texture-simple diff --git a/src/doc/languagespec.tex b/src/doc/languagespec.tex index 75b3b851a..a1814abe5 100644 --- a/src/doc/languagespec.tex +++ b/src/doc/languagespec.tex @@ -4135,6 +4135,16 @@ \section{Texture} \apiend \vspace{-16pt} +\apiitem{"anisotropic", } +\vspace{12pt} +Sets the maximum anisotropic ratio allowed. This parameter may not be +supported by all renderers, and may have different default values (it is +supported with a default of 32 for renderers that use OpenImageIO's texture +system). +\NEW % 1.10 +\apiend +\vspace{-16pt} + \apiend \apiitem{\emph{type} \textbf{texture3d} (string filename, point p, \pl) \\ diff --git a/src/liboslexec/builtindecl.h b/src/liboslexec/builtindecl.h index 16c50f43f..6f5c72be8 100644 --- a/src/liboslexec/builtindecl.h +++ b/src/liboslexec/builtindecl.h @@ -381,6 +381,7 @@ DECL (osl_texture_set_fill, "xXf") DECL (osl_texture_set_time, "xXf") DECL (osl_texture_set_interp, "xXs") DECL (osl_texture_set_interp_code, "xXi") +DECL (osl_texture_set_anisotropic, "xXi") DECL (osl_texture_set_subimage, "xXi") DECL (osl_texture_set_subimagename, "xXs") DECL (osl_texture_set_missingcolor_arena, "xXX") diff --git a/src/liboslexec/llvm_gen.cpp b/src/liboslexec/llvm_gen.cpp index 678ac8d5f..079da44fd 100644 --- a/src/liboslexec/llvm_gen.cpp +++ b/src/liboslexec/llvm_gen.cpp @@ -2082,7 +2082,7 @@ llvm_gen_texture_options (BackendLLVM &rop, int opnum, bool sblur_set = false, tblur_set = false, rblur_set = false; bool swrap_set = false, twrap_set = false, rwrap_set = false; bool firstchannel_set = false, fill_set = false, interp_set = false; - bool time_set = false, subimage_set = false; + bool time_set = false, subimage_set = false, anisotropic_set = false; Opcode &op (rop.inst()->ops()[opnum]); for (int a = first_optional_arg; a < op.nargs(); ++a) { @@ -2196,6 +2196,7 @@ llvm_gen_texture_options (BackendLLVM &rop, int opnum, PARAM_FLOAT (fill) PARAM_FLOAT (time) + PARAM_INT (anisotropic) PARAM_INT (firstchannel) PARAM_INT (subimage) diff --git a/src/liboslexec/optexture.cpp b/src/liboslexec/optexture.cpp index 4c1ac4f3a..588b65336 100644 --- a/src/liboslexec/optexture.cpp +++ b/src/liboslexec/optexture.cpp @@ -180,6 +180,14 @@ osl_texture_set_time (void *opt, float x) ((TextureOpt *)opt)->time = x; } +OSL_SHADEOP void +osl_texture_set_anisotropic (void *opt, int x) +{ + ((TextureOpt *)opt)->anisotropic = x; +} + + + inline int tex_interp_to_code (ustring modename) { diff --git a/testsuite/texture-aniso/ref/out.tif b/testsuite/texture-aniso/ref/out.tif new file mode 100644 index 000000000..179bf6647 Binary files /dev/null and b/testsuite/texture-aniso/ref/out.tif differ diff --git a/testsuite/texture-aniso/ref/out.txt b/testsuite/texture-aniso/ref/out.txt new file mode 100644 index 000000000..ca187e51d --- /dev/null +++ b/testsuite/texture-aniso/ref/out.txt @@ -0,0 +1,3 @@ +Compiled test.osl -> test.oso + +Output Cout to out.tif diff --git a/testsuite/texture-aniso/run.py b/testsuite/texture-aniso/run.py new file mode 100755 index 000000000..d651636c3 --- /dev/null +++ b/testsuite/texture-aniso/run.py @@ -0,0 +1,4 @@ +#!/usr/bin/env python + +command += testshade("-g 128 128 --center -od uint8 -o Cout out.tif test") +outputs = [ "out.txt", "out.tif" ] diff --git a/testsuite/texture-aniso/test.osl b/testsuite/texture-aniso/test.osl new file mode 100644 index 000000000..31aa1f961 --- /dev/null +++ b/testsuite/texture-aniso/test.osl @@ -0,0 +1,18 @@ +shader +test (string texturename = "../common/textures/mandrill.tif", + float swirl = 16, + output color Cout = 0) +{ + int aniso = (u >= v) ? 2 : 256; + + float s1 = -1 + 2*u; + float t1 = -1 + 2*v; + + float r = hypot (s1, t1); + + float s1Rot = s1*cos(swirl*r) - t1*sin(swirl*r); + float t1Rot = s1*sin(swirl*r) + t1*cos(swirl*r); + Cout = (color) texture(texturename, s1Rot, t1Rot, + "wrap", "periodic", + "anisotropic", aniso); +}