-
Notifications
You must be signed in to change notification settings - Fork 0
/
TextureCoordinate.osl
58 lines (51 loc) · 1.97 KB
/
TextureCoordinate.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
shader TextureCoordinate(
string Coordinate_Space = "object"
[[ string widget = "mapper",
string options = "Common:common|Object:object|Shader:shader|World:world|Camera:camera|Screen:screen|Raster:raster|NDC:NDC" ]],
output point Position = 0.0,
output normal Normal = 0.0,
output normal Normal_Undistorted = 0.0
[[ string label = "Undistorted Normal" ]],
output point UV = 0.0,
output point UV_Per_Polygon = 0.0
[[ string label = "Per Polygon UV" ]],
output vector Tangent = 0.0,
output point View = 0.0,
output normal View_Normal = 0.0
[[ string label = "View Normal" ]],
output point Ray_Footprint = 0.0
[[ string label = "Ray Footprint" ]],
output vector Incident = 0.0
) {
// Same as PxrVariable
Position = transform(Coordinate_Space, P);
Normal = transform(Coordinate_Space, N);
Normal_Undistorted = transform(Coordinate_Space, Ng);
// Construct Blender-style UV coordinates from Renderman's ST coordinates
float s = 0.0, t = 0.0;
getattribute("s", s);
getattribute("t", t);
UV[0] = s;
UV[1] = t;
// Renderman's UV coordinates are per triangle for some reason
float w = 0.0;
UV_Per_Polygon[0] = u;
UV_Per_Polygon[1] = v;
getattribute("builtin", "w", w);
UV_Per_Polygon[2] = w;
// Tangent, not sure if dPdu or dPdv should be used instead
vector tn;
getattribute("builtin", "Tn", tn);
Tangent = transform(Coordinate_Space, tn);
// Ripped from Blender's source code
View = transform("world", "camera", P);
// Could be good for holograms or perspective stuff?
View_Normal = transform(Coordinate_Space, normalize(-I));
// Seems to find edges, could be good for subsurface?
float du = 0.0, dv = 0.0, dw = 0.0;
getattribute("builtin", "du", du);
getattribute("builtin", "dv", dv);
getattribute("builtin", "dw", dw);
Ray_Footprint = point(du, dv, dw);
Incident = transform(Coordinate_Space, I);
}