Files
sbox-public/game/editor/ShaderGraph/Code/Nodes/Camera.cs
s&box team 71f266059a Open source release
This commit imports the C# engine code and game files, excluding C++ source code.

[Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
2025-11-24 09:05:18 +00:00

64 lines
1.8 KiB
C#

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( 3, "g_vCameraPositionWs" );
[Output( typeof( Vector3 ) )]
[Hide]
public static NodeResult.Func Direction => ( GraphCompiler compiler ) => new( 3, "g_vCameraDirWs" );
[Output( typeof( float ) )]
[Hide]
public static NodeResult.Func NearPlane => ( GraphCompiler compiler ) => new( 1, "g_flNearPlane" );
[Output( typeof( float ) )]
[Hide]
public static NodeResult.Func FarPlane => ( GraphCompiler compiler ) => new( 1, "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( 1, $"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( 1, $"Depth::GetLinear( {result} )" );
};
}