-
Notifications
You must be signed in to change notification settings - Fork 43
/
TextureNoTile.osl
115 lines (98 loc) · 4.16 KB
/
TextureNoTile.osl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// Non-Tiling Texture Shader
// TextureNoTile.osl, by Zap Andersson
// Modified: 2020-03-28
// Copyright 2020 Autodesk Inc, All rights reserved. This file is licensed under Apache 2.0 license
// https://github.com/ADN-DevTech/3dsMax-OSL-Shaders/blob/master/LICENSE.txt
// Modified by Saul Espinosa for Redshift OSL Support 2020-12-28
float sum( color col ) { return col[0]+col[1]+col[2]; }
color textureNoTile( string FileName, point UV, float GradientScale, float Offset, float Rescale, float Rotate, int LevelCount, int Debug, int Seed )
{
float k = noise("uperlin", UV / GradientScale, Seed);
float l = k*LevelCount + UV[1] / GradientScale;
float i = floor( l );
float f = l - i;
vector offa = cellnoise(i + 0.0, Seed) * vector(Offset, Offset, 1.0);
vector offb = cellnoise(i + 1.0, Seed) * vector(Offset, Offset, 1.0);
float sca = 1.0 / (1.0 + (offa[2] - 0.5) * Rescale);
float scb = 1.0 / (1.0 + (offb[2] - 0.5) * Rescale);
float rota = offa[2] * Rotate;
float rotb = offb[2] * Rotate;
point rotA = rotate(UV, rota, vector(0.5,0.5,0), vector(0.5,0.5,1.0));
point rotB = rotate(UV, rotb, vector(0.5,0.5,0), vector(0.5,0.5,1.0));
color cola = texture(FileName, rotA[0] * sca + offa[0], 1.0 - (rotA[1] * sca + offa[1]), "wrap", "periodic" );
color colb = texture(FileName, rotB[0] * scb + offb[0], 1.0 - (rotB[1] * scb + offb[1]), "wrap", "periodic" );
if (Debug)
{
cola = offa;
colb = offb;
}
return mix( cola, colb, smoothstep(0.1,0.9,f-0.1*sum(cola-colb)) );
}
shader NoTile
[[ string help = "Non-Tiling Bitmap Lookup, based on an OpenGL Technique",
string label = "Non-Tiling Bitmap Lookup",
string URL = "http://www.iquilezles.org/www/articles/texturerepetition/texturerepetition.htm" ]]
(
// Texture Input
point uvw = point(u,v,0)
[[ string label= "UV Coordinate",
string help = "The 2D coordiante at which the texture is looked up." ]],
string Filename = "" [[ string widget="filename", string page = "Image" ]],
string fileColorSpace = "" [[string label = "ColorSpace", string widget = "colorspace", string page = "Image"]],
float gainMul = 1
[[ string label = "Gain",
string page = "Image",
float softmin = 0,
float softmax = 10,
float slidermin = 0,
float slidermax = 10,
float sensitivity = 0.001 ]],
// Noise Options
float GradientScale = 2.0
[[ float min = 0,
float max = 25,
string page = "Noise"
]],
float Offset = 1.0
[[ float min = 0,
float max = 25,
string page = "Noise"
]],
float Rescale = 0.0
[[ float min = 0,
float max = 25,
string page = "Noise"
]],
float Rotate = 0.0
[[ float min = -180,
float max = 180,
string page = "Noise"
]],
int LevelCount = 8
[[ int min = 0,
int max = 25,
string page = "Noise"
]],
int Seed = 0
[[ int min = 0,
int max = 100,
string page = "Noise"
]],
int Debug = 0
[[ string widget = "checkBox",
string help = "Shows the regions that are being mixed", string page = "Utility" ]],
int Bypass = 0
[[ string widget = "checkBox",
string help = "Turns the effect off, to compare", string page = "Utility" ]],
output color outColor = 0
)
{
int s = Seed;
point Pos = select(vector(u,v,0), uvw, isconnected(uvw));
if (Bypass)
color Col = texture(Filename, Pos[0], 1.0 - Pos[1], "wrap", "periodic");
else
Col = textureNoTile( Filename, Pos, GradientScale, Offset, Rescale, Rotate, LevelCount, Debug, s );
color textureSampleRAW = transformc("ACEScg", "scene-linear Rec.709-sRGB", Col);
outColor = transformc(fileColorSpace, "ACEScg", textureSampleRAW) * gainMul;
}