mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-01-20 04:10:00 -05:00
This commit imports the C# engine code and game files, excluding C++ source code. [Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
49 lines
1.4 KiB
C#
49 lines
1.4 KiB
C#
|
|
namespace Editor.ShaderGraph.Nodes;
|
|
|
|
/// <summary>
|
|
/// Calculates a Fresnel term.
|
|
/// </summary>
|
|
[Title( "Fresnel" ), Category( "Effects" )]
|
|
public sealed class Fresnel : ShaderNode
|
|
{
|
|
/// <summary>
|
|
/// Normal at the point being shaded.
|
|
/// </summary>
|
|
[Input( typeof( Vector3 ) )]
|
|
[Hide]
|
|
public NodeInput Normal { get; set; }
|
|
|
|
/// <summary>
|
|
/// Direction of the viewer's eye.
|
|
/// </summary>
|
|
[Input( typeof( Vector3 ) )]
|
|
[Hide]
|
|
public NodeInput Direction { get; set; }
|
|
|
|
/// <summary>
|
|
/// Power that controls the strength of the Fresnel effect.
|
|
/// </summary>
|
|
[Input( typeof( float ) )]
|
|
[Hide]
|
|
public NodeInput Power { get; set; }
|
|
|
|
/// <summary>
|
|
/// Default value for when Power input is missing.
|
|
/// </summary>
|
|
[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} )" );
|
|
};
|
|
}
|