namespace Editor.ShaderGraph.Nodes; /// /// Vertex normal in world space /// [Title( "World Normal" ), Category( "Variables" ), Icon( "public" )] public sealed class WorldNormal : ShaderNode { [Output( typeof( Vector3 ) )] [Hide] public static NodeResult.Func Result => ( GraphCompiler compiler ) => new( 3, "i.vNormalWs", compiler.IsNotPreview ); } /// /// Vertex tangents in world space /// [Title( "World Tangent" ), Category( "Variables" ), Icon( "public" )] public sealed class WorldTangent : ShaderNode { [Output( typeof( Vector3 ) )] [Hide] public static NodeResult.Func U => ( GraphCompiler compiler ) => new( 3, "i.vTangentUWs", compiler.IsNotPreview ); [Output( typeof( Vector3 ) )] [Hide] public static NodeResult.Func V => ( GraphCompiler compiler ) => new( 3, "i.vTangentVWs", compiler.IsNotPreview ); } /// /// Whether or not the current pixel is a front-facing pixel. /// [Title( "Is Front Face" ), Category( "Variables" ), Icon( "start" )] public sealed class IsFrontFace : ShaderNode { [Output( typeof( int ) ), Title( "Result" )] [Hide] public NodeResult.Func Result => ( GraphCompiler compiler ) => { return new NodeResult( 1, compiler.IsPs ? "i.vFrontFacing" : "0", compiler.IsNotPreview ); }; } /// /// Vertex normal in object space /// [Title( "Object Space Normal" ), Category( "Variables" ), Icon( "view_in_ar" )] public sealed class ObjectSpaceNormal : ShaderNode { [Output( typeof( Vector3 ) )] [Hide] public static NodeResult.Func Result => ( GraphCompiler compiler ) => new( 3, "i.vNormalOs", compiler.IsNotPreview ); } /// /// Return the current screen position of the object /// [Title( "Screen Position" ), Category( "Variables" ), Icon( "install_desktop" )] public sealed class ScreenPosition : ShaderNode { // Note: We could make all of these constants but I don't like the situation where it can generated something like // "i.vPositionSs.xy.xy" when casting.. even though that should be valid. [Output( typeof( Vector3 ) )] [Hide] public static NodeResult.Func XYZ => ( GraphCompiler compiler ) => compiler.IsVs ? new( 3, "i.vPositionPs.xyz" ) : new( 3, "i.vPositionSs.xyz" ); [Output( typeof( Vector2 ) )] [Hide] public static NodeResult.Func XY => ( GraphCompiler compiler ) => compiler.IsVs ? new( 2, "i.vPositionPs.xy" ) : new( 2, "i.vPositionSs.xy" ); [Output( typeof( float ) )] [Hide] public static NodeResult.Func Z => ( GraphCompiler compiler ) => compiler.IsVs ? new( 1, "i.vPositionPs.z" ) : new( 1, "i.vPositionSs.z" ); [Output( typeof( float ) )] [Hide] public static NodeResult.Func W => ( GraphCompiler compiler ) => compiler.IsVs ? new( 1, "i.vPositionPs.w" ) : new( 1, "i.vPositionSs.w" ); } /// /// Return the current screen uvs of the object /// [Title( "Screen Coordinate" ), Category( "Variables" ), Icon( "tv" )] public sealed class ScreenCoordinate : ShaderNode { [Output( typeof( Vector2 ) )] [Hide] public static NodeResult.Func Result => ( GraphCompiler compiler ) => compiler.IsVs ? new( 2, "CalculateViewportUv( i.vPositionPs.xy )" ) : new( 2, "CalculateViewportUv( i.vPositionSs.xy )" ); } /// /// Return the current world space position /// [Title( "World Space Position" ), Category( "Variables" ), Icon( "public" )] public sealed class WorldPosition : ShaderNode { [Output( typeof( Vector3 ) )] [Hide] public static NodeResult.Func Result => ( GraphCompiler compiler ) => compiler.IsVs ? new( 3, "i.vPositionWs" ) : new( 3, "i.vPositionWithOffsetWs.xyz + g_vHighPrecisionLightingOffsetWs.xyz" ); } /// /// Return the current object space position of the pixel /// [Title( "Object Space Position" ), Category( "Variables" ), Icon( "view_in_ar" )] public sealed class ObjectPosition : ShaderNode { [Output( typeof( Vector3 ) )] [Hide] public static NodeResult.Func Result => ( GraphCompiler compiler ) => new( 3, "i.vPositionOs" ); } /// /// Return the current view direction of the pixel /// [Title( "View Direction" ), Category( "Variables" ), Icon( "cameraswitch" )] public sealed class ViewDirection : ShaderNode { [Output( typeof( Vector3 ) )] [Hide] public static NodeResult.Func Result => ( GraphCompiler compiler ) => compiler.IsVs ? new( 3, "CalculatePositionToCameraDirWs( i.vPositionWs )" ) : new( 3, "CalculatePositionToCameraDirWs( i.vPositionWithOffsetWs.xyz + g_vHighPrecisionLightingOffsetWs.xyz )" ); } /// /// Color of the vertex /// [Title( "Vertex Color" ), Category( "Variables" ), Icon( "format_color_fill" )] public sealed class VertexColor : ShaderNode { [Output( typeof( Vector3 ) )] [Hide] public static NodeResult.Func RGB => ( GraphCompiler compiler ) => new( 3, "i.vColor.rgb" ); [Output( typeof( float ) )] [Hide] public static NodeResult.Func Alpha => ( GraphCompiler compiler ) => new( 1, "i.vColor.a" ); } /// /// Tint of the scene object /// [Title( "Tint" ), Category( "Variables" ), Icon( "palette" )] public sealed class Tint : ShaderNode { [Hide, Output( typeof( Color ) )] public static NodeResult.Func RGBA => ( GraphCompiler compiler ) => new( 4, "i.vTintColor" ); }