Skip to content

Commit

Permalink
Merge pull request #1014 from est77/master
Browse files Browse the repository at this point in the history
Small shader lib improvements
  • Loading branch information
dictoon committed May 24, 2016
2 parents 1cc29a4 + 8c70f1f commit a642d26
Show file tree
Hide file tree
Showing 7 changed files with 2,324 additions and 97 deletions.
58 changes: 58 additions & 0 deletions sandbox/shaders/src/include/appleseed/udim.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@

//
// This source file is part of appleseed.
// Visit http://appleseedhq.net/ for additional information and resources.
//
// This software is released under the MIT license.
//
// Copyright (c) 2014-2016 The masked shader writer, The appleseedhq Organization
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//

#ifndef APPLESEED_SHADERS_UDIM_H
#define APPLESEED_SHADERS_UDIM_H

#define MARI_UDIM_NAME(i) format("%s%d%s", Filename, i + 1001, UDIMPrefix)

#define TEN_MARI_UDIM_NAMES(j) \
MARI_UDIM_NAME(10 * j + 0), \
MARI_UDIM_NAME(10 * j + 1), \
MARI_UDIM_NAME(10 * j + 2), \
MARI_UDIM_NAME(10 * j + 3), \
MARI_UDIM_NAME(10 * j + 4), \
MARI_UDIM_NAME(10 * j + 5), \
MARI_UDIM_NAME(10 * j + 6), \
MARI_UDIM_NAME(10 * j + 7), \
MARI_UDIM_NAME(10 * j + 8), \
MARI_UDIM_NAME(10 * j + 9)

#define TEN_MARI_UDIM_ROWS \
TEN_MARI_UDIM_NAMES(0), \
TEN_MARI_UDIM_NAMES(1), \
TEN_MARI_UDIM_NAMES(2), \
TEN_MARI_UDIM_NAMES(3), \
TEN_MARI_UDIM_NAMES(4), \
TEN_MARI_UDIM_NAMES(5), \
TEN_MARI_UDIM_NAMES(6), \
TEN_MARI_UDIM_NAMES(7), \
TEN_MARI_UDIM_NAMES(8), \
TEN_MARI_UDIM_NAMES(9)

#endif
6 changes: 3 additions & 3 deletions sandbox/shaders/src/surface/as_subsurface_surface.osl
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ shader as_subsurface_surface
float min = 0
]],
color Color = 1.0,
string Profile = "normalized_diffusion"
string Profile = "better_dipole"
[[
string widget = "popup",
string options = "normalized_diffusion|standard_dipole|better_dipole|directional_dipole"
]],
float Radius = 0.1,
float RadiusScale = 1.0,
color Radius = 1.0,
float RadiusScale = 0.1,
float Ior = 1.3,
int MaxSubsurfaceRayDepth = 2
[[
Expand Down
36 changes: 33 additions & 3 deletions sandbox/shaders/src/texture2d/as_color_texture.osl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
// THE SOFTWARE.
//

#include "appleseed/udim.h"

shader as_color_texture
(
float U = u,
Expand All @@ -34,6 +36,12 @@ shader as_color_texture
[[
string widget = "filename"
]],
string UDIM = "off"
[[
string widget = "popup",
string options = "off|mari"
]],
string UDIMPrefix = ".tx",
string UWrap = "periodic"
[[
string widget = "popup",
Expand Down Expand Up @@ -63,10 +71,32 @@ shader as_color_texture
output float AlphaOut = 1.0
)
{
string mari_filenames[100] = {TEN_MARI_UDIM_ROWS};

string tx_filename = "";
float uu;
float vv;

if (UDIM == "mari")
{
int utile = int(U);
int vtile = int(V);
int offset = 10 * vtile + utile;
tx_filename = mari_filenames[offset];
uu = U - utile;
vv = V - vtile;
}
else
{
tx_filename = Filename;
uu = U;
vv = V;
}

ColorOut = texture(
Filename,
U,
V,
tx_filename,
uu,
vv,
"swidth", UWidth,
"twidth", VWidth,
"sblur", UBlur,
Expand Down
36 changes: 33 additions & 3 deletions sandbox/shaders/src/texture2d/as_scalar_texture.osl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
// THE SOFTWARE.
//

#include "appleseed/udim.h"

shader as_scalar_texture
(
float U = u,
Expand All @@ -34,6 +36,12 @@ shader as_scalar_texture
[[
string widget = "filename"
]],
string UDIM = "off"
[[
string widget = "popup",
string options = "off|mari"
]],
string UDIMPrefix = ".tx",
string UWrap = "periodic"
[[
string widget = "popup",
Expand Down Expand Up @@ -66,10 +74,32 @@ shader as_scalar_texture
output float FloatOut = 0
)
{
string mari_filenames[100] = {TEN_MARI_UDIM_ROWS};

string tx_filename = "";
float uu;
float vv;

if (UDIM == "mari")
{
int utile = int(U);
int vtile = int(V);
int offset = 10 * vtile + utile;
tx_filename = mari_filenames[offset];
uu = U - utile;
vv = V - vtile;
}
else
{
tx_filename = Filename;
uu = U;
vv = V;
}

color c = texture(
Filename,
U,
V,
tx_filename,
uu,
vv,
"swidth", UWidth,
"twidth", VWidth,
"sblur", UBlur,
Expand Down
48 changes: 23 additions & 25 deletions sandbox/shaders/surface/as_subsurface_surface.oso
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
OpenShadingLanguage 1.00
# Compiled by oslc 1.6.9
shader as_subsurface_surface %meta{string,help,"Subsurface surface shader"}
param vector Normal 0 0 0 %read{7,10} %write{0,0} %initexpr
param float Reflectance 0.80000001 %meta{float,min,0} %read{8,11} %write{2147483647,-1}
param color Color 1 1 1 %read{7,11} %write{2147483647,-1}
param string Profile "normalized_diffusion" %meta{string,widget,"popup"} %meta{string,options,"normalized_diffusion|standard_dipole|better_dipole|directional_dipole"} %read{7,7} %write{2147483647,-1}
param float Radius 0.1 %read{4,4} %write{2147483647,-1}
param float RadiusScale 1 %read{4,4} %write{2147483647,-1}
param float Ior 1.3 %read{7,7} %write{2147483647,-1}
param vector Normal 0 0 0 %read{6,9} %write{0,0} %initexpr
param float Reflectance 0.80000001 %meta{float,min,0} %read{7,10} %write{2147483647,-1}
param color Color 1 1 1 %read{6,10} %write{2147483647,-1}
param string Profile "better_dipole" %meta{string,widget,"popup"} %meta{string,options,"normalized_diffusion|standard_dipole|better_dipole|directional_dipole"} %read{6,6} %write{2147483647,-1}
param color Radius 1 1 1 %read{4,4} %write{2147483647,-1}
param float RadiusScale 0.1 %read{4,4} %write{2147483647,-1}
param float Ior 1.3 %read{6,6} %write{2147483647,-1}
param int MaxSubsurfaceRayDepth 2 %meta{string,help,"Replace subsurface by diffuse when ray depth is greater."} %meta{int,min,0} %read{2,2} %write{2147483647,-1}
oparam closure color BSSRDF %read{2147483647,-1} %write{8,12}
oparam closure color BSSRDF %read{2147483647,-1} %write{7,11}
global normal N %read{0,0} %write{2147483647,-1}
local int RayDepth %read{2,2} %write{1,1}
temp int $tmp1 %read{2147483647,-1} %write{1,1}
const string $const1 "path:ray_depth" %read{1,1} %write{2147483647,-1}
temp int $tmp2 %read{3,3} %write{2,2}
temp closure color $tmp3 %read{8,8} %write{7,7}
temp float $tmp4 %read{5,5} %write{4,4}
temp color $tmp5 %read{7,7} %write{5,5}
const string $const2 "as_subsurface" %read{6,7} %write{2147483647,-1}
const float $const3 0 %read{7,10} %write{2147483647,-1}
temp closure color $tmp6 %read{12,12} %write{10,10}
const string $const4 "diffuse" %read{9,9} %write{2147483647,-1}
const string $const6 "oren_nayar" %read{10,10} %write{2147483647,-1}
temp color $tmp7 %read{12,12} %write{11,11}
temp closure color $tmp3 %read{7,7} %write{6,6}
temp color $tmp4 %read{6,6} %write{4,4}
const string $const2 "as_subsurface" %read{5,6} %write{2147483647,-1}
const float $const3 0 %read{6,9} %write{2147483647,-1}
temp closure color $tmp5 %read{11,11} %write{9,9}
const string $const4 "diffuse" %read{8,8} %write{2147483647,-1}
const string $const6 "oren_nayar" %read{9,9} %write{2147483647,-1}
temp color $tmp6 %read{11,11} %write{10,10}
code Normal
# ./surface/as_subsurface_surface.osl:34
# vector Normal = N,
Expand All @@ -35,28 +34,27 @@ code ___main___
# ./surface/as_subsurface_surface.osl:58
# if (RayDepth <= MaxSubsurfaceRayDepth)
le $tmp2 RayDepth MaxSubsurfaceRayDepth %line{58} %argrw{"wrr"}
if $tmp2 9 13 %argrw{"r"}
if $tmp2 8 12 %argrw{"r"}
# ./surface/as_subsurface_surface.osl:64
# Radius * RadiusScale,
mul $tmp4 Radius RadiusScale %line{64} %argrw{"wrr"}
# ./surface/as_subsurface_surface.osl:65
# Ior);
assign $tmp5 $tmp4 %line{65} %argrw{"wr"}
functioncall $const2 8 %argrw{"r"}
functioncall $const2 7 %line{65} %argrw{"r"}
# /home/est/Devel/appleseedhq/appleseed/sandbox/shaders/stdosl.h:612
# }
closure $tmp3 $const2 Profile Normal Color $tmp5 Ior $const3 %filename{"/home/est/Devel/appleseedhq/appleseed/sandbox/shaders/stdosl.h"} %line{612} %argrw{"wrrrrrrr"}
closure $tmp3 $const2 Profile Normal Color $tmp4 Ior $const3 %filename{"/home/est/Devel/appleseedhq/appleseed/sandbox/shaders/stdosl.h"} %line{612} %argrw{"wrrrrrrr"}
# ./surface/as_subsurface_surface.osl:65
# Ior);
mul BSSRDF $tmp3 Reflectance %filename{"./surface/as_subsurface_surface.osl"} %line{65} %argrw{"wrr"}
# ./surface/as_subsurface_surface.osl:68
# BSSRDF = Reflectance * Color * diffuse(Normal);
functioncall $const4 11 %line{68} %argrw{"r"}
functioncall $const4 10 %line{68} %argrw{"r"}
# /home/est/Devel/appleseedhq/appleseed/sandbox/shaders/stdosl.h:658
# }
closure $tmp6 $const6 Normal $const3 %filename{"/home/est/Devel/appleseedhq/appleseed/sandbox/shaders/stdosl.h"} %line{658} %argrw{"wrrr"}
closure $tmp5 $const6 Normal $const3 %filename{"/home/est/Devel/appleseedhq/appleseed/sandbox/shaders/stdosl.h"} %line{658} %argrw{"wrrr"}
# ./surface/as_subsurface_surface.osl:68
# BSSRDF = Reflectance * Color * diffuse(Normal);
mul $tmp7 Reflectance Color %filename{"./surface/as_subsurface_surface.osl"} %line{68} %argrw{"wrr"}
mul BSSRDF $tmp6 $tmp7 %argrw{"wrr"}
mul $tmp6 Reflectance Color %filename{"./surface/as_subsurface_surface.osl"} %line{68} %argrw{"wrr"}
mul BSSRDF $tmp5 $tmp6 %argrw{"wrr"}
end

0 comments on commit a642d26

Please sign in to comment.