This repository has been archived by the owner on Nov 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandomUVW.osl
147 lines (73 loc) · 2.35 KB
/
randomUVW.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
shader randomUVW
(
output color Col = 1,
float Object_ID = 0,
//rotate
float Rotate = 0,
float Rotate_Step = 0,
float Rotate_Varience = 0,
//scale
vector Scale = 1,
float Uniform_Scale = 1,
vector Scale_Varience = 0,
float Uniform_Scale_Varience = 0,
//offset
vector Offset = 0,
vector Offset_Varience = 0,
//extra
int Mirror = 0,
float Seed = 1 ,
int Single_Object = 0,
vector Repeat_UVW = 1
)
{
float ID = Object_ID;
float fu = 0;
float fv = 0;
float uu = u*Repeat_UVW[0];
float vv = v*Repeat_UVW[1];
if(Single_Object !=0 )
{
fu = floor(uu);
fv = floor(vv);
ID = fu+fv;
}
float myU = uu - (0.5 + fu);
float myV = vv - (0.5 + fv);
//scale
float Srandf = cos(ID*Uniform_Scale_Varience*354+Seed)*Uniform_Scale_Varience;
float SrandfU = cos(ID*Scale_Varience[0]*144+Seed)*Scale_Varience[0];
float SrandfV = cos(ID*Scale_Varience[1]*475+Seed)*Scale_Varience[1];
myU -= myU * (SrandfU + Srandf + Scale[0] + Uniform_Scale - 2);
myV -= myV * (SrandfV + Srandf + Scale[1] + Uniform_Scale - 2);
//rotate
int Rrandi = int(cos(ID*14104)*6514+Seed+1);
float Rrandf = cos(ID*Rotate_Varience*454)*Rotate_Varience;
float final_rotate = radians(Rotate_Step * Rrandi + Rrandf + Rotate);
//final_rotate = M_PI_2*4;
float u1 = cos(final_rotate) * myU - sin(final_rotate) * myV;
float v1 = sin(final_rotate) * myU + cos(final_rotate) * myV;
myU = u1 + 0.5 + fu;
myV = v1 + 0.5 + fv;
//offset
float PrandfU = cos(ID*Offset_Varience[0]*157+Seed)*Offset_Varience[0];
float PrandfV = cos(ID*Offset_Varience[1]*452+Seed)*Offset_Varience[1];
myU += (PrandfU + Offset[0]) * 0.1;
myV += (PrandfV + Offset[1]) * 0.1;
//repeat
if(Mirror == 0)
{
myU = mod(myU,1.0);
myV = mod(myV,1.0);
}
else
{
int tempU = int(myU);
int tempV = int(myV);
if(tempU%2 == 0) myU = mod(myU,1.0);
else myU = 1.0 - mod(myU,1.0);
if(tempV%2 == 0) myV = mod(myV,1.0);
else myV = 1.0 - mod(myV,1.0);
}
Col = color(myU,myV, 0);
}