Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New ECM Visual Effect #494

Merged
merged 21 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
3f0d5e2
Added new postFX act 1
AnotherCommander Nov 22, 2024
840b71c
Added new postFX act 2
AnotherCommander Nov 22, 2024
1fe0c2c
Fixed occasional false indication of ECM burst when launching from st…
AnotherCommander Nov 22, 2024
6d1c668
Added new postFX act 3
AnotherCommander Nov 22, 2024
53d3599
Added CRTBadSignal effect to the final processing shader.
AnotherCommander Nov 22, 2024
a09ebe4
Fixed copy/paste error resulting in compile failure.
AnotherCommander Nov 22, 2024
e10ae4d
Added new ECM interference effect in the HDR final processing shader.
AnotherCommander Nov 22, 2024
85a6b82
Ensure that the ECM blast effect does not get way too bright in HDR.
AnotherCommander Nov 22, 2024
e958ab0
Some cosmetic changes part 1
AnotherCommander Nov 24, 2024
b5151a1
Some cosmetic changes part 2
AnotherCommander Nov 24, 2024
e480e65
Added new ECM visual effect to CHANGELOG.TXT
AnotherCommander Nov 24, 2024
5e69a38
Making new ECM visual a user default option - act 1
AnotherCommander Nov 25, 2024
f1e8c8c
Making new ECM visual a user default option - act 2
AnotherCommander Nov 25, 2024
ecfa355
Making new ECM visual a user default option - act 3
AnotherCommander Nov 25, 2024
81cc49c
Reduced the intensity of the ECM effect. Less is more.
Nov 25, 2024
5688f90
Fixing bug where ECM effect does not work when no entities are on sca…
AnotherCommander Nov 26, 2024
c33ed9f
Fixing bug where ECM effect does not work when no entities are on sca…
AnotherCommander Nov 26, 2024
d4c1da5
Fixed bug where docking while the ECM fx was playing would not stop ir.
AnotherCommander Nov 26, 2024
cb22369
Fixing bug where postFXs don't stop upon death - act 1
AnotherCommander Nov 26, 2024
9f79b90
Fixing bug where postFXs don't stop upon death - act 2
AnotherCommander Nov 26, 2024
c817b33
Fixing bug where postFXs don't stop upon death - act 3
AnotherCommander Nov 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Doc/CHANGELOG.TXT
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ General:
confusion.
* Updated the wormhole cloud effect.
* Mouse flight sensitivity made configurable by editing the preferences file.
* Implemented new ECM visual effect.

Expansion Pack Development:
===========================
Expand Down
25 changes: 25 additions & 0 deletions Resources/Shaders/oolite-final-hdr.fragment
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,25 @@ vec3 CRT(sampler2D inImage, vec2 inCoords)
}
// ------------------------------------------------------------------------------------------

// =======================================================================================
// CRTBadSignal - original at https://www.shadertoy.com/view/ltV3z1
// =======================================================================================
vec3 CRTBadSignal(sampler2D inImage, vec2 inCoords)
{
vec2 uv = inCoords;
float t = uTime;
float fx = 0.001 + 25.0 * abs(sin(t) / 10.0) - mod(1.0 + t, 7.0);
const float s = 50.0; // noise intensity
float x = (floor(uv.x * 300.0)) + (floor(uv.y * 300.0)) * (t * 0.1);
vec4 dtv = vec4(mod((mod(x, 2.0) + 1.0) * (mod(x, 0.0) + 0.0), 0.01) - 0.005) * s;
vec3 col = clamp(vec3(0.1, 0.1, 0.1) + dtv.xyz / fx, vec3(0.0), vec3(0.1));

col.xyz += texture(inImage,uv).xyz;

return col;
}
// ------------------------------------------------------------------------------------------


// =======================================================================================
// FXAA - original at https://www.shadertoy.com/view/MdyyRt
Expand Down Expand Up @@ -716,6 +735,12 @@ void main()
hdrColor *= exposure;
break;
case 8:
hdrColor = CRTBadSignal(scene, TexCoords);
bloomColor = CRT(bloomBlur, TexCoords); // yes CRT, not a typo
if(bloom) hdrColor += bloomColor;
hdrColor *= exposure;
break;
case 9:
hdrColor = gravLens(scene, TexCoords);
bloomColor = gravLens(bloomBlur, TexCoords);
if(bloom) hdrColor += bloomColor;
Expand Down
24 changes: 24 additions & 0 deletions Resources/Shaders/oolite-final.fragment
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,24 @@ vec3 CRT(sampler2D inImage, vec2 inCoords)
}
// ------------------------------------------------------------------------------------------

// =======================================================================================
// CRTBadSignal - original at https://www.shadertoy.com/view/ltV3z1
// =======================================================================================
vec3 CRTBadSignal(sampler2D inImage, vec2 inCoords)
{
vec2 uv = inCoords;
float t = uTime;
float fx = 0.001 + 25.0 * abs(sin(t) / 10.0) - mod(1.0 + t, 7.0);
const float s = 50.0; // noise intensity
float x = (floor(uv.x * 300.0)) + (floor(uv.y * 300.0 )) * (t * 0.1);
vec4 dtv = vec4(mod((mod(x, 2.0) + 1.0) * (mod(x, 0.0) + 0.0), 0.01) - 0.005) * s;
vec3 col = clamp(vec3(0.1, 0.1, 0.1) + dtv.xyz / fx, vec3(0.0), vec3(0.1));

col.xyz += texture(inImage,uv).xyz;

return col;
}
// ------------------------------------------------------------------------------------------

// =======================================================================================
// FXAA - original at https://www.shadertoy.com/view/MdyyRt
Expand Down Expand Up @@ -533,6 +551,12 @@ void main()
hdrColor *= exposure;
break;
case 8:
hdrColor = CRTBadSignal(scene, TexCoords);
bloomColor = CRT(bloomBlur, TexCoords); // yes CRT, not a typo
if(bloom) hdrColor += bloomColor;
hdrColor *= exposure;
break;
case 9:
hdrColor = gravLens(scene, TexCoords);
bloomColor = gravLens(bloomBlur, TexCoords);
if(bloom) hdrColor += bloomColor;
Expand Down
44 changes: 40 additions & 4 deletions src/Core/Entities/PlayerEntity.m
Original file line number Diff line number Diff line change
Expand Up @@ -2725,6 +2725,8 @@ - (void) doBookkeeping:(double) delta_t
STAGE_TRACKING_BEGIN

double speed_delta = SHIP_THRUST_FACTOR * thrust;

static BOOL gettingInterference = NO;

OOSunEntity *sun = [UNIVERSE sun];
double external_temp = 0;
Expand Down Expand Up @@ -2819,6 +2821,29 @@ - (void) doBookkeeping:(double) delta_t
ecm_in_operation = NO;
}
}

// ecm interference visual effect
if ([UNIVERSE useShaders] && [UNIVERSE ECMVisualFXEnabled])
{
// we want to start and stop the effect exactly once, not start it
// or stop it on every frame
if ([self scannerFuzziness] > 0.0)
{
if (!gettingInterference)
{
[UNIVERSE setCurrentPostFX:OO_POSTFX_CRTBADSIGNAL];
gettingInterference = YES;
}
}
else
{
if (gettingInterference)
{
[UNIVERSE terminatePostFX:OO_POSTFX_CRTBADSIGNAL];
gettingInterference = NO;
}
}
}

// Energy Banks and Shields

Expand Down Expand Up @@ -3930,11 +3955,18 @@ - (void) performDockingUpdates:(OOTimeDelta)delta_t
{
[self docked]; // bookkeeping for docking
}

// if cloak or ecm visual effects are playing while docking, terminate them
[UNIVERSE terminatePostFX:OO_POSTFX_CLOAK];
if ([UNIVERSE ECMVisualFXEnabled]) [UNIVERSE terminatePostFX:OO_POSTFX_CRTBADSIGNAL];
}


- (void) performDeadUpdates:(OOTimeDelta)delta_t
{
[UNIVERSE terminatePostFX:OO_POSTFX_CLOAK];
if ([UNIVERSE ECMVisualFXEnabled]) [UNIVERSE terminatePostFX:OO_POSTFX_CRTBADSIGNAL];

[self gameOverFadeToBW];

if ([self shotTime] > kDeadResetTime)
Expand Down Expand Up @@ -6055,7 +6087,7 @@ - (void) deactivateCloakingDevice
if (![self hasCloakingDevice]) return;

[super deactivateCloakingDevice];
[UNIVERSE setCurrentPostFX:[UNIVERSE colorblindMode]];
[UNIVERSE terminatePostFX:OO_POSTFX_CLOAK];
[UNIVERSE addMessage:DESC(@"cloak-off") forCount:2];
[self playCloakingDeviceOff];
}
Expand All @@ -6066,11 +6098,15 @@ - (void) deactivateCloakingDevice
- (double) scannerFuzziness
{
double fuzz = 0.0;

/* Fuzziness from ECM bursts */
double since = [UNIVERSE getTime] - last_ecm_time;
if (since < SCANNER_ECM_FUZZINESS)
if (last_ecm_time > 0.0)
{
fuzz += (SCANNER_ECM_FUZZINESS - since) * (SCANNER_ECM_FUZZINESS - since) * 500.0;
double since = [UNIVERSE getTime] - last_ecm_time;
if (since < SCANNER_ECM_FUZZINESS)
{
fuzz += (SCANNER_ECM_FUZZINESS - since) * (SCANNER_ECM_FUZZINESS - since) * 500.0;
}
}
/* Other causes could go here */

Expand Down
7 changes: 7 additions & 0 deletions src/Core/Universe.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ enum
OO_POSTFX_GRAYSCALE,
OO_POSTFX_OLDMOVIE,
OO_POSTFX_CRT,
OO_POSTFX_CRTBADSIGNAL,
OO_POSTFX_ENDOFLIST // keep this for last
};

Expand Down Expand Up @@ -313,6 +314,8 @@ enum
#ifndef NDEBUG
double timeAccelerationFactor;
#endif

BOOL ECMVisualFXEnabled;

NSMutableArray *activeWormholes;

Expand Down Expand Up @@ -380,6 +383,7 @@ enum

- (int) currentPostFX;
- (void) setCurrentPostFX: (int) newCurrentPostFX;
- (void) terminatePostFX:(int) postFX;

- (id)initWithGameView:(MyOpenGLView *)gameView;

Expand Down Expand Up @@ -644,6 +648,9 @@ enum
- (double) timeAccelerationFactor;
- (void) setTimeAccelerationFactor:(double)newTimeAccelerationFactor;

- (BOOL) ECMVisualFXEnabled;
- (void) setECMVisualFXEnabled:(BOOL)isEnabled;

- (void) filterSortedLists;

///////////////////////////////////////
Expand Down
29 changes: 26 additions & 3 deletions src/Core/Universe.m
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,15 @@ - (void) setCurrentPostFX: (int) newCurrentPostFX
_currentPostFX = newCurrentPostFX;
}


- (void) terminatePostFX:(int)postFX
{
if ([self currentPostFX] == postFX)
{
[self setCurrentPostFX:[self colorblindMode]];
}
}

- (int) nextColorblindMode:(int) index
{
if (++index > OO_POSTFX_COLORBLINDNESS_TRITAN)
Expand Down Expand Up @@ -745,7 +754,9 @@ - (id) initWithGameView:(MyOpenGLView *)inGameView
OOLog(@"MSAA.setup", @"Multisample anti-aliasing %@requested.", [inGameView msaa] ? @"" : @"not ");
[inGameView setFov:OOClamp_0_max_f([prefs oo_floatForKey:@"fov-value" defaultValue:57.2f], MAX_FOV_DEG) fromFraction:NO];
if ([inGameView fov:NO] < MIN_FOV_DEG) [inGameView setFov:MIN_FOV_DEG fromFraction:NO];


[self setECMVisualFXEnabled:[prefs oo_boolForKey:@"ecm-visual-fx" defaultValue:YES]];

// Set up speech synthesizer.
#if OOLITE_SPEECH_SYNTH
#if OOLITE_MAC_OS_X
Expand Down Expand Up @@ -4802,8 +4813,8 @@ - (BOOL) viewFrustumIntersectsSphereAt:(Vector)position withRadius:(GLfloat)radi
- (void) drawUniverse
{
int currentPostFX = [self currentPostFX];
BOOL hudSeparateRenderPass = [self useShaders] && (currentPostFX == OO_POSTFX_NONE || (currentPostFX == OO_POSTFX_CLOAK && [self colorblindMode] == OO_POSTFX_NONE));
NSSize viewSize = [gameView viewSize];
BOOL hudSeparateRenderPass = [self useShaders] && (currentPostFX == OO_POSTFX_NONE || ((currentPostFX == OO_POSTFX_CLOAK || currentPostFX == OO_POSTFX_CRTBADSIGNAL) && [self colorblindMode] == OO_POSTFX_NONE));
NSSize viewSize = [gameView viewSize];
OOLog(@"universe.profile.draw", @"%@", @"Begin draw");

if (!no_update)
Expand Down Expand Up @@ -7383,6 +7394,18 @@ - (void) setTimeAccelerationFactor:(double)newTimeAccelerationFactor
#endif


- (BOOL) ECMVisualFXEnabled
{
return ECMVisualFXEnabled;
}


- (void) setECMVisualFXEnabled:(BOOL)isEnabled
{
ECMVisualFXEnabled = isEnabled;
}


- (void) filterSortedLists
{
/*
Expand Down
Loading