-
Notifications
You must be signed in to change notification settings - Fork 467
Expand file tree
/
Copy pathCamera.cs
More file actions
63 lines (53 loc) · 1.93 KB
/
Camera.cs
File metadata and controls
63 lines (53 loc) · 1.93 KB
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
namespace Editor.ShaderGraph.Nodes;
/// <summary>
/// Camera position and shit
/// </summary>
[Title( "Camera" ), Category( "Variables" ), Icon( "photo_camera" )]
public sealed class Camera : ShaderNode
{
[Output( typeof( Vector3 ) ), Title( "Position" )]
[Hide]
public static NodeResult.Func WorldPosition => ( GraphCompiler compiler ) => new( NodeResultType.Vector3, "g_vCameraPositionWs" );
[Output( typeof( Vector3 ) )]
[Hide]
public static NodeResult.Func Direction => ( GraphCompiler compiler ) => new( NodeResultType.Vector3, "g_vCameraDirWs" );
[Output( typeof( float ) )]
[Hide]
public static NodeResult.Func NearPlane => ( GraphCompiler compiler ) => new( NodeResultType.Float, "g_flNearPlane" );
[Output( typeof( float ) )]
[Hide]
public static NodeResult.Func FarPlane => ( GraphCompiler compiler ) => new( NodeResultType.Float, "g_flFarPlane" );
}
/// <summary>
/// Sample depth texture
/// </summary>
[Title( "Depth" ), Category( "Camera" )]
public sealed class Depth : ShaderNode
{
[Input( typeof( Vector2 ) ), Hide]
public NodeInput UV { get; set; }
[Output( typeof( float ) ), Hide]
public NodeResult.Func Out => ( GraphCompiler compiler ) =>
{
var result = UV.IsValid() ? compiler.Result( UV ).Cast( 2 ) :
compiler.IsVs ? "i.vPositionPs.xy" : "i.vPositionSs.xy";
return new NodeResult( NodeResultType.Float, $"Depth::Get( {result} )" );
};
}
/// <summary>
/// Sample linear depth, which is absolute coordinates away from the camera
/// </summary>
[Title( "Linear Depth" ), Category( "Camera" )]
public sealed class LinearDepth : ShaderNode
{
[Input( typeof( Vector2 ) ), Hide]
public NodeInput UV { get; set; }
[Output( typeof( float ) ), Hide]
public NodeResult.Func Out => ( GraphCompiler compiler ) =>
{
var result = UV.IsValid() ? compiler.Result( UV ).Cast( 2 ) :
compiler.IsVs ? "i.vPositionPs.xy" : "i.vPositionSs.xy";
return new NodeResult( NodeResultType.Float, $"Depth::GetLinear( {result} )" );
};
}