diff --git a/Content.Client/Singularity/SingularityOverlay.cs b/Content.Client/Singularity/SingularityOverlay.cs index c7c6aa2b5b4..3286f471102 100644 --- a/Content.Client/Singularity/SingularityOverlay.cs +++ b/Content.Client/Singularity/SingularityOverlay.cs @@ -4,6 +4,8 @@ using Robust.Shared.Enums; using Robust.Shared.Prototypes; using System.Numerics; +using Robust.Shared.Timing; + namespace Content.Client.Singularity { @@ -38,6 +40,7 @@ public SingularityOverlay() private readonly Vector2[] _positions = new Vector2[MaxCount]; private readonly float[] _intensities = new float[MaxCount]; private readonly float[] _falloffPowers = new float[MaxCount]; + private readonly float[] _energys = new float[MaxCount]; private int _count = 0; protected override bool BeforeDraw(in OverlayDrawArgs args) @@ -47,7 +50,34 @@ protected override bool BeforeDraw(in OverlayDrawArgs args) if (_xformSystem is null && !_entMan.TrySystem(out _xformSystem)) return false; + //_count = 0; +// + //var query = _entMan.EntityQueryEnumerator(); + //while (query.MoveNext(out var uid, out var singulo, out var xform)) + //{ + // if (xform.MapID != args.MapId) + // continue; +// + // var mapPos = _xformSystem.GetWorldPosition(uid); +// + // // is the distortion in range? + // if ((mapPos - args.WorldAABB.ClosestPoint(mapPos)).LengthSquared() > MaxDistance * MaxDistance) + // continue; +// + // // To be clear, this needs to use "inside-viewport" pixels. + // // In other words, specifically NOT IViewportControl.WorldToScreen (which uses outer coordinates). + // var tempCoords = args.Viewport.WorldToLocal(mapPos); + // tempCoords.Y = args.Viewport.Size.Y - tempCoords.Y; // Local space to fragment space. +// + // _energys[_count] = singulo.Energy; + // _count++; +// + // if (_count == MaxCount) + // break; + //} + _count = 0; + var query = _entMan.EntityQueryEnumerator(); while (query.MoveNext(out var uid, out var distortion, out var xform)) { @@ -65,11 +95,13 @@ protected override bool BeforeDraw(in OverlayDrawArgs args) var tempCoords = args.Viewport.WorldToLocal(mapPos); tempCoords.Y = args.Viewport.Size.Y - tempCoords.Y; // Local space to fragment space. + _positions[_count] = tempCoords; _intensities[_count] = distortion.Intensity; _falloffPowers[_count] = distortion.FalloffPower; + _energys[_count] = distortion.Energy; _count++; - +// if (_count == MaxCount) break; } @@ -84,6 +116,7 @@ protected override void Draw(in OverlayDrawArgs args) _shader?.SetParameter("renderScale", args.Viewport.RenderScale * args.Viewport.Eye.Scale); _shader?.SetParameter("count", _count); + _shader?.SetParameter("energy", _energys);//new float[]{250,500,1000,1500,2000}); _shader?.SetParameter("position", _positions); _shader?.SetParameter("intensity", _intensities); _shader?.SetParameter("falloffPower", _falloffPowers); diff --git a/Content.Server/Singularity/EntitySystems/SingularitySystem.cs b/Content.Server/Singularity/EntitySystems/SingularitySystem.cs index cf6b142b6b8..9129b8485ed 100644 --- a/Content.Server/Singularity/EntitySystems/SingularitySystem.cs +++ b/Content.Server/Singularity/EntitySystems/SingularitySystem.cs @@ -86,6 +86,11 @@ public override void Update(float frameTime) var curTime = _timing.CurTime; if (singularity.NextUpdateTime <= curTime) Update(uid, curTime - singularity.LastUpdateTime, singularity); + if(TryComp(uid, out SingularityDistortionComponent? sinDist)){ + sinDist.Energy = singularity.Energy; + Dirty(uid,sinDist); + + } } } @@ -135,6 +140,9 @@ public void SetEnergy(EntityUid uid, float value, SingularityComponent? singular return; singularity.Energy = value; + + + SetLevel(uid, value switch { >= 5000 when HasEatenSM => 6, diff --git a/Content.Shared/Singularity/Components/SingularityDistortionComponent.cs b/Content.Shared/Singularity/Components/SingularityDistortionComponent.cs index 1382dd45f49..4ac9ed1eb4b 100644 --- a/Content.Shared/Singularity/Components/SingularityDistortionComponent.cs +++ b/Content.Shared/Singularity/Components/SingularityDistortionComponent.cs @@ -11,6 +11,9 @@ public sealed partial class SingularityDistortionComponent : Component [DataField, AutoNetworkedField, ViewVariables(VVAccess.ReadWrite)] public float Intensity = 31.25f; + [DataField("energy"), AutoNetworkedField, ViewVariables(VVAccess.ReadWrite)] + public float Energy = 150f; + [DataField, AutoNetworkedField, ViewVariables(VVAccess.ReadWrite)] public float FalloffPower = MathF.Sqrt(2f); } diff --git a/Resources/Prototypes/Entities/Objects/Fun/toys.yml b/Resources/Prototypes/Entities/Objects/Fun/toys.yml index 6341316ecfa..16cf7b07a9a 100644 --- a/Resources/Prototypes/Entities/Objects/Fun/toys.yml +++ b/Resources/Prototypes/Entities/Objects/Fun/toys.yml @@ -1125,6 +1125,7 @@ state: singularitytoy - type: SingularityDistortion intensity: 2000 + energy: 5 falloffPower: 2.6 - type: Item size: Normal diff --git a/Resources/Prototypes/Entities/Structures/Power/Generation/Singularity/singularity.yml b/Resources/Prototypes/Entities/Structures/Power/Generation/Singularity/singularity.yml index 25d219ab945..9b9e064125b 100644 --- a/Resources/Prototypes/Entities/Structures/Power/Generation/Singularity/singularity.yml +++ b/Resources/Prototypes/Entities/Structures/Power/Generation/Singularity/singularity.yml @@ -53,6 +53,7 @@ minSpeed: 1.875 - type: SingularityDistortion falloffPower: 2.529822 + energy: 180 intensity: 3645 - type: RadiationSource slope: 0.2 # its emit really far away @@ -80,23 +81,29 @@ sprite: Structures/Power/Generation/Singularity/singularity_1.rsi state: singularity_1 scale: 1.0,1.0 + visible: false 2: sprite: Structures/Power/Generation/Singularity/singularity_2.rsi state: singularity_2 scale: 1.0,1.0 + visible: false 3: sprite: Structures/Power/Generation/Singularity/singularity_3.rsi state: singularity_3 scale: 1.0,1.0 + visible: false 4: sprite: Structures/Power/Generation/Singularity/singularity_4.rsi state: singularity_4 scale: 1.0,1.0 + visible: false 5: sprite: Structures/Power/Generation/Singularity/singularity_5.rsi state: singularity_5 scale: 1.5,1.5 + visible: false 6: sprite: Structures/Power/Generation/Singularity/singularity_6.rsi state: singularity_6 scale: .9,.9 + visible: false diff --git a/Resources/Textures/Shaders/singularity.swsl b/Resources/Textures/Shaders/singularity.swsl index 609a4b3b104..6a538792bdb 100644 --- a/Resources/Textures/Shaders/singularity.swsl +++ b/Resources/Textures/Shaders/singularity.swsl @@ -3,43 +3,403 @@ uniform sampler2D SCREEN_TEXTURE; uniform highp vec2 renderScale; uniform highp float maxDistance; + uniform lowp int count; uniform highp float[5] falloffPower; uniform highp float[5] intensity; uniform highp vec2[5] position; -// the `5`s in the array lengths correspond to the upper limit on the simultaneous distortion sources that can be present on screen at a time. +uniform highp float[5] energy; +// the `5`s in the array lengths correspond to the upper limit on the simultaneous distortion sources that can be present on screen at a time. // If you want to change this, make sure to change all of them here, in the for loop, and, in whatever overlay assigns the uniforms // (apparently #define is an unknown preprocessor directive) + void fragment() { highp vec2 finalCoords = FRAGCOORD.xy; highp vec2 delta; highp float distance; highp float deformation; - + highp vec2 coord = FRAGCOORD.xy * SCREEN_PIXEL_SIZE.xy; + highp vec4 blackCol = vec4(1,1,1,1); + highp vec4 addCol = vec4(0); + + + ///////////////////////////////////////////////////////// + + + //highp vec4 ringColor = vec4(1.0, 0.0, 0.0, 15.0); + //highp vec4 ringCloseColor = vec4(1.0, 0.0, 0.0, 1.0); + //highp vec4 ringRandomColor = vec4(1.0, 0.9843, 0.0, 5.0); + //highp vec4 ringRandomCloseColor = vec4(0.0, 0.0, 0.0, 1.0); + //highp float ringDencity = 5; + //highp float ringCloseFallOff = 0.02; + //highp float ringScale = 2; + //highp float ringSpeed = 5; + //highp float ringMinDis = 0.03; + //highp float ringMaxDis = 0.1; + + + ///////////////////////////////////////////////////////// + + + highp float deformationPower = 1; + highp float intensityPower = 3645; + highp float avarageDistance; + highp float avarageClose; + highp float testEnergy = 2950; + highp float falofPower = sqrt(6.4); + //highp vec2 dif; + + + for (int i = 0; i < 5 && i < count; i++) { - - delta = FRAGCOORD.xy - position[i]; + testEnergy = energy[i]; + + if(testEnergy<150){ + + + ///////////////////////////////////////////////////////// + + + //ringColor = mix(vec4(0),vec4(1.0, 0.0, 0.0, 15.0) ,(testEnergy)/150); + //ringCloseColor = mix(vec4(0),vec4(1.0, 0.0, 0.0, 1.0) ,(testEnergy)/150); + //ringRandomColor = mix(vec4(0),vec4(1.0, 0.9843, 0.0, 5.0) ,(testEnergy)/150); + //ringRandomCloseColor = mix(vec4(0),vec4(0.0, 0.0, 0.0, 1.0) ,(testEnergy)/150); + //ringDencity = mix(0,4 ,(testEnergy)/150); + //ringCloseFallOff = mix(0,0.02 ,(testEnergy)/150); + //ringScale = mix(0,2 ,(testEnergy)/150); + //ringSpeed = mix(0,3 ,(testEnergy)/150); + //ringMinDis = mix(0,0.03 ,(testEnergy)/150); + //ringMaxDis = mix(0,0.1 ,(testEnergy)/150); + //deformationPower = mix(0,1 ,(testEnergy)/150); + + + ///////////////////////////////////////////////////////// + + + intensityPower = mix(0,3645 ,(testEnergy)/150); + falofPower = mix(sqrt(6.4),sqrt(6.4) ,(testEnergy)/150); + }else if(testEnergy>=150&&testEnergy<250){ + + + ///////////////////////////////////////////////////////// + + + //ringColor = mix(vec4(1.0, 0.0, 0.0, 15.0),vec4(0.8, 0.6, 0.0, 15.0) ,(testEnergy-150)/100); + //ringCloseColor = mix(vec4(1.0, 0.0, 0.0, 1.0),vec4(1.0, 0.0, 0.0, 3.0) ,(testEnergy-150)/100); + //ringRandomColor = mix(vec4(1.0, 0.9843, 0.0, 5.0),vec4(1.0, 1.0, 1.0, 15.0) ,(testEnergy-150)/100); + //ringRandomCloseColor = mix(vec4(0.0, 0.0, 0.0, 1.0),vec4(0.0, 0.1, 0.0, 1.0) ,(testEnergy-150)/100); + //ringDencity = mix(4,5 ,(testEnergy-150)/100); + //ringCloseFallOff = mix(0.02,0.03 ,(testEnergy-150)/100); + //ringScale = mix(2,2.2 ,(testEnergy-150)/100); + //ringSpeed = mix(2,2.5 ,(testEnergy-150)/100); + //ringMinDis = mix(0.03,0.1 ,(testEnergy-150)/100); + //ringMaxDis = mix(0.1,0.25 ,(testEnergy-150)/100); + //deformationPower = mix(1,2 ,(testEnergy-150)/100); + + + ///////////////////////////////////////////////////////// + + + intensityPower = mix(3645,103680 ,(testEnergy-150)/100); + falofPower = mix(sqrt(6.4),sqrt(7.0) ,(testEnergy-150)/100); + }else if(testEnergy>=250&&testEnergy<300){ + + + ///////////////////////////////////////////////////////// + + + //ringColor = mix(vec4(0.8, 0.6, 0.0, 15.0),vec4(0.4, 0.7, 1.0, 15.0) ,(testEnergy-250)/50); + //ringCloseColor = mix(vec4(1.0, 0.0, 0.0, 3.0),vec4(0.2, 0.1, 1.0, 1.0) ,(testEnergy-250)/50); + //ringRandomColor = mix(vec4(1.0, 1.0, 1.0, 15.0),vec4(1.0, 0.0, 1.0, 5.0) ,(testEnergy-250)/50); + //ringRandomCloseColor = mix(vec4(0.0, 0.1, 0.0, 1.0),vec4(0.0, 1.1, 0.0, 1.0) ,(testEnergy-250)/50); + //ringDencity = mix(5,5.2 ,(testEnergy-250)/50); + //ringCloseFallOff = mix(0.03,0.05 ,(testEnergy-250)/50); + //ringScale = mix(2.2,2.2 ,(testEnergy-250)/50); + //ringSpeed = mix(2.5,3 ,(testEnergy-250)/50); + //ringMinDis = mix(0.1,0.1 ,(testEnergy-250)/50); + //ringMaxDis = mix(0.25,0.35 ,(testEnergy-250)/50); + //deformationPower = mix(2,2.2 ,(testEnergy-250)/50); + + + ///////////////////////////////////////////////////////// + + + intensityPower = mix(103680,113680 ,(testEnergy-250)/50); + falofPower = mix(sqrt(7.0),sqrt(7.2) ,(testEnergy-250)/50); + }else if(testEnergy>=300&&testEnergy<950){ + + + ///////////////////////////////////////////////////////// + + + //ringColor = mix(vec4(0.4, 0.7, 1.0, 15.0),vec4(0.1, 0.0, 1.0, 15.0) ,(testEnergy-300)/650); + //ringCloseColor = mix(vec4(0.2, 0.1, 1.0, 1.0),vec4(0.3, 0.0, 1.0, 1.0) ,(testEnergy-300)/650); + //ringRandomColor = mix(vec4(1.0, 0.0, 1.0, 5.0),vec4(0.8, 1.0, 0.4, 5.0) ,(testEnergy-300)/650); + //ringRandomCloseColor = mix(vec4(0.0, 1.1, 0.0, 1.0),vec4(0.0, 0.2, 0.0, 1.0) ,(testEnergy-300)/650); + //ringDencity = mix(5.2,2.6 ,(testEnergy-300)/650); + //ringCloseFallOff = mix(0.05,0.07 ,(testEnergy-300)/650); + //ringScale = mix(2.2,2.2 ,(testEnergy-300)/650); + //ringSpeed = mix(3,3.5 ,(testEnergy-300)/650); + //ringMinDis = mix(0.1,0.17 ,(testEnergy-300)/650); + //ringMaxDis = mix(0.35,0.5 ,(testEnergy-300)/650); + //deformationPower = mix(2.2,3 ,(testEnergy-300)/650); + + + ///////////////////////////////////////////////////////// + + + intensityPower = mix(113680,1113920 ,(testEnergy-300)/650); + falofPower = mix(sqrt(7.2),sqrt(8.0) ,(testEnergy-300)/650); + }else if(testEnergy>=950&&testEnergy<1000){ + + + ///////////////////////////////////////////////////////// + + + //ringColor = mix(vec4(0.1, 0.0, 1.0, 15.0),vec4(0.1, 0.0, 0.5, 5.0) ,(testEnergy-950)/50); + //ringCloseColor = mix(vec4(0.3, 0.0, 1.0, 1.0),vec4(0.1725, 0.0, 0.4157, 5.0) ,(testEnergy-950)/50); + //ringRandomColor = mix(vec4(0.8, 1.0, 0.4, 5.0),vec4(1.0, 3.0, 0.5, 15.0) ,(testEnergy-950)/50); + //ringRandomCloseColor = mix(vec4(0.0, 0.2, 0.0, 1.0),vec4(0.3, 1.2, 0.7, 3.0) ,(testEnergy-950)/50); + //ringDencity = mix(6,6 ,(testEnergy-950)/50); + //ringCloseFallOff = mix(0.07,0.1 ,(testEnergy-950)/50); + //ringScale = mix(2.2,2.3 ,(testEnergy-950)/50); + //ringSpeed = mix(3.5,5 ,(testEnergy-950)/50); + //ringMinDis = mix(0.17,0.25 ,(testEnergy-950)/50); + //ringMaxDis = mix(0.5,0.6 ,(testEnergy-950)/50); + //deformationPower = mix(3,4 ,(testEnergy-950)/50); + + + ///////////////////////////////////////////////////////// + + + intensityPower = mix(1113920,16200000 ,(testEnergy-950)/50); + falofPower = mix(sqrt(8.0),sqrt(10.0) ,(testEnergy-950)/50); + }else if(testEnergy>=1000&&testEnergy<1950){ + + + ///////////////////////////////////////////////////////// + + + //ringColor = mix(vec4(0.1, 0.0, 0.5, 5.0),vec4(1.0, 0.0, 0.0, 15.0) ,(testEnergy-1000)/950); + //ringCloseColor = mix(vec4(0.1725, 0.0, 0.4157, 5.0),vec4(0.9294, 0.2, 0.0, 1.0) ,(testEnergy-1000)/950); + //ringRandomColor = mix(vec4(1.0, 3.0, 0.5, 15.0),vec4(1.0, 1.0, 0.0, 15.0) ,(testEnergy-1000)/950); + //ringRandomCloseColor = mix(vec4(0.3, 1.2, 0.7, 3.0),vec4(1.0, 1.0, 1.0, 15.0) ,(testEnergy-1000)/950); + //ringDencity = mix(6,6 ,(testEnergy-1000)/950); + //ringCloseFallOff = mix(0.1,0.15 ,(testEnergy-1000)/950); + //ringScale = mix(2.3,2.5 ,(testEnergy-1000)/950); + //ringSpeed = mix(5,6 ,(testEnergy-1000)/950); + //ringMinDis = mix(0.25,0.3 ,(testEnergy-1000)/950); + //ringMaxDis = mix(0.6,0.9 ,(testEnergy-1000)/950); + //deformationPower = mix(4,5 ,(testEnergy-1000)/950); + + + ///////////////////////////////////////////////////////// + + + intensityPower = mix(16200000,180000000 ,(testEnergy-1000)/950); + falofPower = mix(sqrt(10.0),sqrt(12.0) ,(testEnergy-1000)/950); + }else if(testEnergy>=1950&&testEnergy<2950){ + + + ///////////////////////////////////////////////////////// + + + //ringColor = mix(vec4(1.0, 0.0, 0.0, 15.0),vec4(0.0, 2.0, 1.0, 15.0) ,(testEnergy-1950)/1000); + //ringCloseColor = mix(vec4(0.9294, 0.2, 0.0, 1.0),vec4(1.0, 0.0, 1.0, 5.0) ,(testEnergy-1950)/1000); + //ringRandomColor = mix(vec4(1.0, 1.0, 0.0, 15.0),vec4(1.0, 1.0, 2.0, 5.0) ,(testEnergy-1950)/1000); + //ringRandomCloseColor = mix(vec4(1.0, 1.0, 1.0, 15.0),vec4(0.0, 0.0, 0.0, 1.0) ,(testEnergy-1950)/1000); + //ringDencity = mix(6,7 ,(testEnergy-1950)/1000); + //ringCloseFallOff = mix(0.15,0.2 ,(testEnergy-1950)/1000); + //ringScale = mix(2.5,2.7 ,(testEnergy-1950)/1000); + //ringSpeed = mix(6,8 ,(testEnergy-1950)/1000); + //ringMinDis = mix(0.3,0.35 ,(testEnergy-1950)/1000); + //ringMaxDis = mix(0.9,1 ,(testEnergy-1950)/1000); + //deformationPower = mix(5,6 ,(testEnergy-1950)/1000); + + + ///////////////////////////////////////////////////////// + + + intensityPower = mix(180000000,280000000 ,(testEnergy-1950)/1000); + falofPower = mix(sqrt(12.0),sqrt(12.0) ,(testEnergy-1950)/1000); + }else{ + + + ///////////////////////////////////////////////////////// + + + //ringColor = vec4(0.0, 2.0, 1.0, 15.0); + //ringCloseColor = vec4(1.0, 0.0, 1.0, 5.0); + //ringRandomColor =vec4(1.0, 1.0, 2.0, 5.0); + //ringRandomCloseColor = vec4(0.0, 0.0, 0.0, 1.0); + //ringDencity = 7; + //ringCloseFallOff = 0.2; + //ringScale = 2.7; + //ringSpeed = 8; + //ringMinDis = 0.35; + //ringMaxDis = 1; + //deformationPower = 6; + + + ///////////////////////////////////////////////////////// + + + intensityPower = 280000000; + falofPower = sqrt(12.0); + } + + + + delta = position[i]-FRAGCOORD.xy; distance = length(delta / renderScale); + avarageDistance = (distance)/(maxDistance); // 5 / 15 + avarageClose = abs(avarageDistance-1); + deformation = intensityPower / pow(distance, falofPower); - deformation = intensity[i] / pow(distance, falloffPower[i]); - // ensure deformation goes to zero at max distance // avoids long-range single-pixel shifts that are noticeable when leaving PVS. - + if (distance >= maxDistance) { deformation = 0.0; } else { - deformation *= (1.0 - pow(distance/maxDistance, 4.0)); + deformation *= (1 - pow(distance/maxDistance, 1.0)); + //if(distance 1.1){ + blackCol=vec4(0,0,0,1);// + deformation = pow(deformation, 0.1); + finalCoords += deformation*(FRAGCOORD.xy-position[i]); + //blackCol = vec4(0,0,0,1); + //}//else if(deformation > 0.9){ + // addCol=vec4(15,15,15,1);// + // //deformation = -pow(deformation, 0.1); + // //finalCoords += deformation*(FRAGCOORD.xy-position[i]); + // //blackCol = vec4(0,0,0,1); + }else{ + finalCoords += deformation*delta; } - - if(deformation > 0.8) - deformation = pow(deformation, 0.3); - finalCoords -= deformation * delta; + + + ///////////////////////////////////////////////////////// + + + //if(avarageDistance < ringMaxDis && avarageDistance > ringMinDis){ + // //addCol = vec4(0.5); + // ////dif = finalCoords.st - 0.5; + // //timesin = sin(TIME); + // //timecos = cos(TIME); + // //addCol = vec4(vec3(octavePerlinNoise(polarCoordinate(vec3(FRAGCOORD,TIME)))),1);//vec3(zFBM(vec2(polarCoordinate(vec3(delta.xy,15)))/100)),1); + // //addCol = vec4(vec3(zFBM(vec2(avarageDistance/15,atan(FRAGCOORD.y+position[i].x,FRAGCOORD.x+position[i].y)/57.3248)*150)),1); + // //highp vec2 uv = FRAGCOORD/SCREEN_PIXEL_SIZE.xy; + // //highp vec2 cuv = (FRAGCOORD.xy/SCREEN_PIXEL_SIZE.xy - vec2(0.5)) * 2; + // + // //highp float spiral = atan(cuv.x, cuv.y) / 6.283185307 * 6 - TIME + length(cuv) * 3; + // //highp float falloff = (1 - length(cuv)); + // //addCol = vec4(vec3(vec3((1. - abs(0.5 - mod(spiral, 1.))) + falloff) * falloff),1); + // //addCol = vec4(vec3(zFBM(vec2(avarageDistance,atan(delta.y,delta.x)))),1); + // highp float ringFallOff = pow((avarageDistance abs(y)); +// return mix(3.14159265359/2.0 - atan(x,y), atan(y,x), s); +//} +// +//highp vec3 polarCoordinate(highp vec3 p){ +// highp float r=length(p); +// highp float theta1=atan(p.x,p.z); +// highp float theta2=atan(p.y,p.z); +// return vec3(r,theta1,theta2); +//} +// +//highp vec2 rotaUV(highp vec2 uv2, highp float angle, highp vec2 pivot){ +// //highp vec2 uv2 = UV; +// //highp float angle = TIME*2.0; +// highp float s = sin(angle); +// highp float c = cos(angle); +// highp mat2 rotationMatrix = mat2( c, s, -s, c); +// //highp vec2 pivot = vec2( 0.5, 0.5); +// return rotationMatrix * (uv2 - pivot) + pivot; +//}