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

Camera Noise Effect #126

Open
13 tasks
ramokz opened this issue Oct 21, 2023 · 3 comments
Open
13 tasks

Camera Noise Effect #126

ramokz opened this issue Oct 21, 2023 · 3 comments
Assignees
Labels
2D Issues concerning 2D scenes 3D Issues concerning 3D scenes enhancement New feature or request phantom camera Related to PhantomCamera nodes
Milestone

Comments

@ramokz
Copy link
Owner

ramokz commented Oct 21, 2023

Project Type

2D, 3D

Feature Description

At the minute, cameras, both 2D and 3D, are very linear when either idling or following/looking at a target.
The introduction of camera noise allows for more diversity of how the camera is being, virtually, held to add an optional degree of roughness to its current linearity. This will open up opportunities to apply a more dynamic behaviour to the camera that's not purely based on a specified target – be it subtle or drastic.

For example, it can allow for a persistent handheld camera-like effect or for situational effects to simulate an in-game earthquake, explosion, or other scene rumbling moments.

Use Cases

Can be useful for cases like:

  • First person, to simulate a handheld camera effect
  • Top down, to apply a rumble motion to a scene when needed

Importance

Medium - the feature would unlock new possibilities, but it's not a showstopper

Usage

Often - a significant amount of projects can find this useful

(Optional) Proposed Solution

General goals

  • Noise amount, how strong the noise is
  • Noise frequency, i.e. how rapid it is moving
  • Noise parameters should be reusable across multiple PhantomCamera nodes – i.e. should be a resource type

How to use it

Properties

Should be settable from the property inspector with the following parameters:

  • Autostart (bool) = false
  • Amplitude (float) = 1
  • Frequency (float) = 1
  • Fixed Duration (bool) = false
  • Duration (float) = 1

Methods

One-off

  • One-time camera noise call, i.e. call a method to trigger a camera noise effect that ends after a set duration. This is to allow calling different noise parameters, either via parameters or resource, on the same PhantomCamera as needed for only certain amounts of time.

Persistent

  • Method to apply a camera noise to a PhantomCamera. Will automatically trigger itself once applied, with an optional parameter to not do so.
  • Method to stop the camera noise from PhantomCamera.
  • Method to remove camera noise from PhantomCamera.

Technical Notes

2D

3D

  • Utilize the Camera3D H/V Offset to simulate the offset.
    • Note: Needs to work alongside the H/V Offset property override from the Camera3D resource property.
@ramokz ramokz added enhancement New feature or request phantom camera Related to PhantomCamera nodes 3D Issues concerning 3D scenes 2D Issues concerning 2D scenes labels Oct 21, 2023
@ramokz ramokz added this to the Future milestone Oct 21, 2023
@ramokz ramokz self-assigned this Oct 23, 2023
@spheras
Copy link

spheras commented Nov 25, 2023

Hi there!
I have currently a very early custom modification of the Phantom Camera 2D to achieve this effect, based on the code of Camera 2D Plus (https://github.com/LucasBr003/camera-2d-plus) (MIT License). As I said, I did this in a very early stage just to have this feature in my personal project.

The basis idea is to add properties like these in the phantom_camera_2d.gd (those should be put as general properties for all the cameras, but for now I tested this way)

@export_group("Camera Shake")
@export_range(0.000, 1.0) var SHAKE_DECAY: float = 0.02 ## How long it takes the camera to completely stop shaking.
@export_range(0.0, 2.0) var SHAKE_ANGLE_MULTIPLIER: float = 1.0 ## How much the camera will rotate during shakes (won't work if IGNORE ROTATION is enabled).
@export_range(0.0, 2.0) var SHAKE_POSITION_MULTIPLIER: float = 1.0 ## How much the camera will shake.
@export_range(0.0,100.0) var shake_strength: float = 0.0 ## This variable determines the current shake strength.
var position_tilt: Vector2 = Vector2.ZERO ## The camera's position tilt offset.
var angle_tilt: float = 0.0 ## The camera's angle tilt offset.

And after that, in the physics_process of the phantom_camera_2D, I just put this code:

	if(Properties.is_active && shake_strength>0.1):
		var rotation = randf_range(-shake_strength * SHAKE_ANGLE_MULTIPLIER, shake_strength * SHAKE_ANGLE_MULTIPLIER) + angle_tilt # Randomizing the camera angle.
		var offset = Vector2(randf_range(-shake_strength * SHAKE_POSITION_MULTIPLIER, shake_strength * SHAKE_POSITION_MULTIPLIER), # Randomizing the camera offset.
						randf_range(-shake_strength * SHAKE_POSITION_MULTIPLIER, shake_strength * SHAKE_POSITION_MULTIPLIER)) + position_tilt
		if (shake_strength > 0): # Checking if the shake strength is greater than 0.
			shake_strength = lerp(shake_strength, 0.0, SHAKE_DECAY) # Slowly decreasing the shake strength if so.
		self.get_pcam_host_owner().camera_2D.offset=offset

And that's all, it works very well. As I said, this is a very early implementation, just to check it works. Hope it helps.

@ramokz ramokz modified the milestones: Future, 0.7 Dec 12, 2023
@ramokz ramokz modified the milestones: 0.7, 0.7.1 Apr 15, 2024
@ramokz ramokz modified the milestones: 0.7.1, 0.8, 0.7.2, 0.7.3 May 2, 2024
@ramokz ramokz modified the milestones: 0.7.3, 0.8 May 27, 2024
@P5ina
Copy link
Contributor

P5ina commented Aug 9, 2024

I have some suggestion, maybe we don't need to implement shaker like parameter to camera. The idea is we can use composition and add child nodes to camera, that can call owner.apply_motion(motion: Vector2) for example. By that way we separate shaker and phantom camera functionality. This gives us opportunity to integrate third party shakers easily.

Edit: owner.apply_motion(motion: Vector2) is just an example, for now it's only position offset. But it could contain position, rotation or field of view.

@ramokz
Copy link
Owner Author

ramokz commented Aug 10, 2024

I have some suggestion, maybe we don't need to implement shaker like parameter to camera. The idea is we can use composition and add child nodes to camera, that can call owner.apply_motion(motion: Vector2) for example. By that way we separate shaker and phantom camera functionality. This gives us opportunity to integrate third party shakers easily.

The current WIP implementation doesn't apply any noise parameters to a PCam directly, but instead it's being defined in a custom resource that then gets passed to the PCamHost/Camera. The resource isn't required to be attached to the PCam to work, and is meant to allow to be triggered from a function call as well at runtime as well. So there's an opening to use custom noise systems, be it personal or third-party, using a PCam method that just accepts an arbitrary positional / rotational value. The exact way of doing that is a bit tricky, so don't want to support it right out of the gate, as I'm sure there's feedback / kinks to iron out once the addon's initial version is released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2D Issues concerning 2D scenes 3D Issues concerning 3D scenes enhancement New feature or request phantom camera Related to PhantomCamera nodes
Projects
Status: 👀 In review
Development

No branches or pull requests

3 participants