mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-08-02 08:50:18 -04:00
* Shadows Rewrite: C#, bindless, flexible, quality options, less VRAM... Introduces a new shadow mapper written entirely in C#, as well as rewritten shader code for sampling shadow maps. This fully removes and replaces Source 2's native shadow mapping giving us greater flexibility and allowing us to open-source it all. The main goal for the new shadow mapper is greater flexibility whilst reducing complexity. Older shaders are incompatible with the new lighting buffers, and will need to be recompiled to receive lighting properly. What's new: - Bindless per-light shadow maps instead of a shared shadow atlas — this means games can avoid the shadow atlas cost if not using many shadows, but also allows games with many shadows to not be limited by atlas space. - Directional lights have developer configurable cascade count (1-4) and control over split ratio (logarithmic/uniform blend via lambda parameter), useful for games where you may not need multiple cascades. User quality settings define a maximum cascade count which always overrides developer settings, allowing low end hardware to use fewer. - Directional lights have a dedicated cbuffer and uniform fast path in rendering code, and are no longer binned and looped over with local lights. Every pixel on screen is always affected by a directional light. - CSM cascade selection uses bounding spheres instead of depth comparison, with per-cascade texel snapping to eliminate sub-texel shimmer. - Point lights use a TextureCube for cube shadows for much simpler rendering and mapping, along with hardware PCF filtering. - Local light shadow resolution is derived from each light's screen-space size. Shadows below a configurable threshold are not rendered at all. Lights are sorted by screen size, and r.shadows.max caps the total count, culling least important lights first. - User settings have been added for shadow quality (Low/Medium/High) controlling max resolution, max cascades, and PCF filter quality. - Local light shadow maps use D16 depth format, halving memory compared to D32. CSMs remain D32 for precision at large distances. (Although this could be a TODO, I bet we could make it work in D16) - ShadowHardness: New per-light property controlling shadow sharpness. Defaults to soft (0.0) and scales up to 4x sharper. For directional lights, hardness is automatically scaled per cascade proportional to texel density (wider cascades get softer shadows), and clamped so the filter never exceeds a full texel — ensuring consistent softness across cascade transitions. - Shadow debug overlay showing all information about allocated shadow maps, their textures, cascades and more. - Many new convars to control - r.shadows.max: Maximum number of shadow-casting local lights, sorted by screen size, least important culled first - r.shadows.maxresolution: Max texture size for a projected light shadow map (128–4096) - r.shadows.quality: Shadow filter quality (0=Off, 1=Low, 2=Med, 3=High, 4=Experimental Penumbra) - r.shadows.csm.maxcascades: Maximum number of cascades for directional light shadows (1–4) - r.shadows.csm.maxresolution: Maximum resolution for each cascade shadow map (512–8192) - r.shadows.csm.distance: Maximum distance from camera that directional light shadows render (500–50000) - r.shadows.debug: Show shadow debug overlay with CSM textures, cascade bounds, and memory budget - r.shadows.csm.enabled: Enable or disable directional light (CSM) shadows - r.shadows.local.enabled: Enable or disable local light (spot/point) shadows - r.shadows.depthbias: Rasterizer constant depth bias during shadow map rendering - r.shadows.slopescale: Rasterizer slope-scaled depth bias during shadow map rendering - r.shadows.size_cull_threshold: Screen size percentage below which local light shadows are culled - SceneLight refactored into a base class with ScenePointLight, SceneSpotLight, SceneDirectionalLight. SceneOrthoLight removed. - Simplified Light.hlsl: Light is now a class, DynamicLight merged into Light, ProbeLight and LightmappedLight no longer inherit from DynamicLight. - GPULight/BinnedLight struct reorganized and trimmed: explicit typed fields instead of packed uint4 Params, shadow data replaced with a shadow index into a separate StructuredBuffer, removed embedded shadow matrices and atlas bounds. - ViewLightingConfig cleaned up: removed ViewLightingFlags, Shadow3x3PCFConstants, EnvironmentMapSizeConstants, LegacyAmbientLightColor. - Baked light mode flags fixed: BAKED lights (lightmaps only) no longer create shadow maps. MIXED_SHADOWS gated to Stationary lights only (was unconditionally applied). RENDER_ALL_GEOMETRY flag removed. DirectLightMode enum documented across Hammer entity definitions. - Removed light cookie sheets; cookie UV derived from light transform (LightToWorld transpose). Cookie sampling simplified to a single bindless texture lookup.
269 lines
8.9 KiB
C#
269 lines
8.9 KiB
C#
namespace Editor.MapEditor.EntityDefinitions;
|
|
|
|
/// <summary>
|
|
/// A directional spot light entity.
|
|
/// </summary>
|
|
[Library( "light_spot" ), HammerEntity]
|
|
[EditorModel( "models/editor/spot", "rgb(0, 255, 192)", "rgb(255, 64, 64)" )]
|
|
[Sphere( "lightsourceradius", IsLean = true )]
|
|
[VisGroup( VisGroup.Lighting )]
|
|
[Light, LightCone, CanBeClientsideOnly]
|
|
[HideProperty( "enable_shadows" )]
|
|
[Title( "Spot Light" ), Category( "Lighting" ), Icon( "flashlight_on" ), Description( "A directional spot light entity." )]
|
|
class SpotLightEntity : HammerEntityDefinition
|
|
{
|
|
/// <inheritdoc cref="PointLightEntity.Enabled"/>
|
|
[Property, DefaultValue( true )]
|
|
public bool Enabled
|
|
{
|
|
get => default;
|
|
set { }
|
|
}
|
|
|
|
/// <inheritdoc cref="PointLightEntity.Color"/>
|
|
[Property, DefaultValue( "255 255 255" )]
|
|
public Color Color
|
|
{
|
|
get => default;
|
|
set { }
|
|
}
|
|
|
|
/// <inheritdoc cref="PointLightEntity.Brightness"/>
|
|
[Property, DefaultValue( 1 )]
|
|
public float Brightness
|
|
{
|
|
get => default;
|
|
set { }
|
|
}
|
|
|
|
/// <inheritdoc cref="PointLightEntity.BrightnessMultiplier"/>
|
|
public float BrightnessMultiplier
|
|
{
|
|
get => default;
|
|
set { }
|
|
}
|
|
|
|
/// <inheritdoc cref="PointLightEntity.Range"/>
|
|
[Property, DefaultValue( 512 ), Description( "Distance range for light. 0=infinite" )]
|
|
public float Range
|
|
{
|
|
get => default;
|
|
set { }
|
|
}
|
|
|
|
/// <inheritdoc cref="PointLightEntity.Falloff"/>
|
|
[Property, DefaultValue( 1.0f ), Description( "Angular falloff exponent. Does not work with light cookies. Does not work with dynamic lighting." )]
|
|
public float Falloff
|
|
{
|
|
get => default;
|
|
set { }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Inner cone angle. No angular falloff within this cone.
|
|
/// </summary>
|
|
[Property, DefaultValue( 45 ), Description( "Inner cone angle. No angular falloff within this cone." )]
|
|
public float InnerConeAngle
|
|
{
|
|
get => default;
|
|
set { }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Outer cone angle.
|
|
/// </summary>
|
|
[Property, DefaultValue( 60 ), Description( "Outer cone angle." )]
|
|
public float OuterConeAngle
|
|
{
|
|
get => default;
|
|
set { }
|
|
}
|
|
|
|
/// <inheritdoc cref="OrthoLightEntity.LightCookie"/>
|
|
[Property]
|
|
public Texture LightCookie
|
|
{
|
|
get => default;
|
|
set { }
|
|
}
|
|
|
|
/// <inheritdoc cref="PointLightEntity.Flicker"/>
|
|
public bool Flicker
|
|
{
|
|
get => default;
|
|
set { }
|
|
}
|
|
|
|
/// <inheritdoc cref="PointLightEntity.DynamicShadows"/>
|
|
public bool DynamicShadows
|
|
{
|
|
get => default;
|
|
set { }
|
|
}
|
|
|
|
internal enum VolumetricFogType
|
|
{
|
|
None,
|
|
Baked,
|
|
Dynamic,
|
|
DynamicNoShadows
|
|
}
|
|
|
|
[Property( "fog_lighting" ), DefaultValue( VolumetricFogType.Baked ), Description( "Volumetric Fogging - How should light interact with volumetric fogging. Requires Volumetric Fog Cntroller entity be present to function." )]
|
|
internal VolumetricFogType FogLighting
|
|
{
|
|
get => default;
|
|
set { }
|
|
}
|
|
|
|
/// <inheritdoc cref="PointLightEntity.FogStrength"/>
|
|
[Property( "fogcontributionstrength" ), DefaultValue( 1.0f ), Description( "Overrides how much the light affects the fog. (if enabled)" )]
|
|
public float FogStrength
|
|
{
|
|
get => default;
|
|
set { }
|
|
}
|
|
|
|
/// <inheritdoc cref="PointLightEntity.UseNoFog"/>
|
|
public void UseNoFog() => FogLighting = VolumetricFogType.None;
|
|
|
|
/// <inheritdoc cref="PointLightEntity.UseFog"/>
|
|
public void UseFog() => FogLighting = VolumetricFogType.Dynamic;
|
|
|
|
/// <inheritdoc cref="PointLightEntity.UseFogNoShadows"/>
|
|
public void UseFogNoShadows() => FogLighting = VolumetricFogType.DynamicNoShadows;
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc cref="PointLightEntity.FadeDistanceMin"/>
|
|
[Property( "fademindist" ), Category( "Fade Distance" ), DefaultValue( -250 ), Description( "Distance at which the light starts to fade. (less than 0 = use 'Fade Distance Max')" )]
|
|
public float FadeDistanceMin
|
|
{
|
|
get => default;
|
|
set { }
|
|
}
|
|
|
|
/// <inheritdoc cref="PointLightEntity.FadeDistanceMax"/>
|
|
[Property( "fademaxdist" ), Category( "Fade Distance" ), DefaultValue( 1250 ), Description( "Maximum distance at which the light is visible. (0 = don't fade out)" )]
|
|
public float FadeDistanceMax
|
|
{
|
|
get => default;
|
|
set { }
|
|
}
|
|
|
|
/// <inheritdoc cref="PointLightEntity.ShadowFadeDistanceMin"/>
|
|
[Property( "shadowfademindist" ), Category( "Shadows" ), DefaultValue( -250 ), Title( "Shadow Start Fade Distance" ), Description( "Distance at which the shadow starts to fade. (less than 0 = use 'Shadow End Fade Dist')" )]
|
|
public float ShadowFadeDistanceMin
|
|
{
|
|
get => default;
|
|
set { }
|
|
}
|
|
|
|
/// <inheritdoc cref="PointLightEntity.ShadowFadeDistanceMax"/>
|
|
[Property( "shadowfademaxdist" ), Category( "Shadows" ), DefaultValue( 1000 ), Title( "Shadow End Fade Distance" ), Description( "Maximum distance at which the shadow is visible. (0 = don't fade out)" )]
|
|
public float ShadowFadeDistanceMax
|
|
{
|
|
get => default;
|
|
set { }
|
|
}
|
|
|
|
|
|
|
|
internal enum ShadowType
|
|
{
|
|
No,
|
|
Yes
|
|
}
|
|
|
|
[Property, Category( "Shadows" ), DefaultValue( ShadowType.Yes ), Description( "Whether this light casts shadows." )]
|
|
internal ShadowType CastShadows { get; set; } = ShadowType.Yes;
|
|
|
|
[Property( "nearclipplane" ), Category( "Shadows" ), DefaultValue( 1.0f ), Description( "Distance for near clip plane for shadow map." )]
|
|
internal float ShadowNearClipPlane { get; set; } = 1.0f;
|
|
|
|
[Property, Category( "Shadows" ), DefaultValue( 0 ), Description( "0 = use default texture resolution" )]
|
|
internal int ShadowTextureWidth { get; set; } = 0;
|
|
|
|
[Property, Category( "Shadows" ), DefaultValue( 0 ), Description( "0 = use default texture resolution" )]
|
|
internal int ShadowTextureHeight { get; set; } = 0;
|
|
|
|
// TODO: This was in the fgd, but I found no references to it anywhere
|
|
//[Property, Category( "Shadows" ), DefaultValue( false ), Display( Name = "Transmit Shadow Casters to Client", Description = "When this light is visible to a player, add its shadow casters to the player's PVS." )]
|
|
//internal bool pvs_modify_entity { get; set; } = false;
|
|
|
|
// Internal thing used only during compile.
|
|
[Property, DefaultValue( true ), Category( "Advanced" ), Description( "If true, this light renders into baked cube maps." )]
|
|
internal bool RenderToCubemaps { get; set; } = true;
|
|
|
|
[Property, DefaultValue( 0 ), Category( "Advanced" ), Description( "When the number of visible lights exceeds the rendering budget, higher priority lights are chosen for rendering first." )]
|
|
internal int Priority { get; set; } = 0;
|
|
|
|
[Property, Category( "Advanced" ), Description( "Semicolon-delimited list of light groups to affect." )]
|
|
internal string LightGroup { get; set; }
|
|
|
|
// TODO: What does this even do?
|
|
[Property, DefaultValue( 2.0f ), Category( "Advanced" ), Description( "The radius of the light source in game units." )]
|
|
internal float LightSourceRadius { get; set; } = 2.0f;
|
|
|
|
[Property( "baked_light_indexing" ), Category( "Advanced" ), DefaultValue( true ), Description( "Allows direct light to be indexed if baked. Indexed lights have per-pixel quality specular lighting and normal map response." )]
|
|
internal bool BakedLightIndexing { get; set; } = true;
|
|
|
|
[Property( "lightsourcedim0" ), Category( "Shape" ), DefaultValue( 0.00 ), MinMax( 0, 128 ), Description( "Sphere radius of the light." )]
|
|
internal float LightSize { get; set; } = 0.0f;
|
|
|
|
[Property, Category( "Animation" )]
|
|
[Description( "Controls how the animation loops. This is useful if you wish to make first part be the \"turn on animation\" and the remaining part of the curve be the \"looping animation\"<br/> If 0 or above - Loop from given point in animation (X axis)<br/>If below 0 - Do not loop." )]
|
|
internal float AnimationLoop { set; get; }
|
|
|
|
[Property( "attenuation1" ), DefaultValue( 0 ), Category( "Advanced" )]
|
|
public float LinearAttenuation
|
|
{
|
|
get => default;
|
|
set { }
|
|
}
|
|
|
|
[Property( "attenuation2" ), DefaultValue( 1 ), Category( "Advanced" )]
|
|
public float QuadraticAttenuation
|
|
{
|
|
get => default;
|
|
set { }
|
|
}
|
|
|
|
internal enum DirectLightMode
|
|
{
|
|
/// <summary>
|
|
/// Disabled for direct lighting.
|
|
/// </summary>
|
|
None,
|
|
/// <summary>
|
|
/// Fully baked into lightmaps. No real-time shadow maps are generated.
|
|
/// </summary>
|
|
Baked,
|
|
/// <summary>
|
|
/// Fully dynamic with real-time shadow maps that include all objects. Not baked into lightmaps.
|
|
/// </summary>
|
|
Dynamic,
|
|
/// <summary>
|
|
/// Baked into lightmaps but also generates real-time shadow maps for dynamic objects only.
|
|
/// Static objects are excluded from shadow maps since their shadows come from lightmaps.
|
|
/// </summary>
|
|
Stationary
|
|
}
|
|
|
|
[Property, Description( "Specifies the mode of direct lighting to be used." ), DefaultValue( DirectLightMode.Baked )]
|
|
internal DirectLightMode DirectLight { get; set; } = DirectLightMode.Baked;
|
|
|
|
internal enum IndirectLightMode
|
|
{
|
|
None,
|
|
Baked
|
|
}
|
|
|
|
[Property, Description( "Specifies the mode of indirect lighting to be used." ), DefaultValue( IndirectLightMode.Baked )]
|
|
internal IndirectLightMode IndirectLight { get; set; } = IndirectLightMode.Baked;
|
|
|
|
[Property( "bouncescale" ), DefaultValue( 1.0f ), Range( 0.0f, 1.0f ), Category( "Advanced" ), Description( "Scale for the brightness of light bounces, values beyond 1.0f are not energy conserving." )]
|
|
internal float IndirectLightScale { get; set; } = 1.0f;
|
|
}
|