Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose optional "anisotropic" parameter to the texture funtions in OSL. #823

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions src/doc/languagespec.tex
Original file line number Diff line number Diff line change
Expand Up @@ -4135,6 +4135,16 @@ \section{Texture}
\apiend
\vspace{-16pt}

\apiitem{"anisotropic", <int>}
\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) \\
Expand Down
1 change: 1 addition & 0 deletions src/liboslexec/builtindecl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
3 changes: 2 additions & 1 deletion src/liboslexec/llvm_gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)

Expand Down
8 changes: 8 additions & 0 deletions src/liboslexec/optexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
Binary file added testsuite/texture-aniso/ref/out.tif
Binary file not shown.
3 changes: 3 additions & 0 deletions testsuite/texture-aniso/ref/out.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Compiled test.osl -> test.oso

Output Cout to out.tif
4 changes: 4 additions & 0 deletions testsuite/texture-aniso/run.py
Original file line number Diff line number Diff line change
@@ -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" ]
18 changes: 18 additions & 0 deletions testsuite/texture-aniso/test.osl
Original file line number Diff line number Diff line change
@@ -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);
}