namespace Editor.ShaderGraph.Nodes; /// /// Calculates a Fresnel term. /// [Title( "Fresnel" ), Category( "Effects" )] public sealed class Fresnel : ShaderNode { /// /// Normal at the point being shaded. /// [Input( typeof( Vector3 ) )] [Hide] public NodeInput Normal { get; set; } /// /// Direction of the viewer's eye. /// [Input( typeof( Vector3 ) )] [Hide] public NodeInput Direction { get; set; } /// /// Power that controls the strength of the Fresnel effect. /// [Input( typeof( float ) )] [Hide] public NodeInput Power { get; set; } /// /// Default value for when Power input is missing. /// [InputDefault( nameof( Power ) )] public float DefaultPower { get; set; } = 10.0f; [Output( typeof( float ) )] [Hide] public NodeResult.Func Result => ( GraphCompiler compiler ) => { var power = compiler.ResultOrDefault( Power, DefaultPower ).Cast( 1 ); var normal = Normal.IsValid ? compiler.Result( Normal ).Cast( 3 ) : "i.vNormalWs"; var direction = Direction.IsValid ? compiler.Result( Direction ).Cast( 3 ) : $"CalculatePositionToCameraDirWs( {(compiler.IsVs ? "i.vPositionWs.xyz" : "i.vPositionWithOffsetWs.xyz + g_vHighPrecisionLightingOffsetWs.xyz")} )"; return new( 3, $"pow( 1.0 - dot( normalize( {normal} ), normalize( {direction} ) ), {power} )" ); }; }