Skip to content

Commit

Permalink
Presets tweaking and description.
Browse files Browse the repository at this point in the history
  • Loading branch information
gasgiant committed Mar 14, 2020
1 parent 79fa1a3 commit 3cd48fb
Show file tree
Hide file tree
Showing 15 changed files with 2,124 additions and 384 deletions.
55 changes: 48 additions & 7 deletions Assets/CameraShake/Core/CameraShakePresets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ public CameraShakePresets(CameraShaker shaker)
}

public void ShortShake2D(
float posStrength = 0.05f,
float rotStrength = 0.1f,
float positionStrength = 0.04f,
float rotationStrength = 0.08f,
float freq = 25,
int numBounces = 3)
int numBounces = 5)
{
BounceShake.Params pars = new BounceShake.Params
{
positionStrength = posStrength,
rotationStrength = rotStrength,
positionStrength = positionStrength,
rotationStrength = rotationStrength,
freq = freq,
numBounces = numBounces
};
Expand All @@ -30,16 +30,57 @@ public void ShortShake2D(
public void ShortShake3D(
float strength = 0.2f,
float freq = 25,
int numBounces = 3)
int numBounces = 5)
{
BounceShake.Params pars = new BounceShake.Params
{
axesMultiplier = new Displacement(Vector3.zero, Vector3.one),
axesMultiplier = new Displacement(Vector3.zero, new Vector3(1, 1, 0.4f)),
rotationStrength = strength,
freq = freq,
numBounces = numBounces
};
shaker.RegisterShake(new BounceShake(pars));
}

public void Explosion2D(
float positionStrength = 1f,
float rotationStrength = 3,
float duration = 0.5f)
{
PerlinShake.NoiseMode[] modes =
{
new PerlinShake.NoiseMode(8, 1),
new PerlinShake.NoiseMode(20, 0.4f)
};
Envelope.EnvelopeParams envelopePars = new Envelope.EnvelopeParams();
envelopePars.decay = duration <= 0 ? 1 : 1 / duration;
PerlinShake.Params pars = new PerlinShake.Params
{
strength = new Displacement(new Vector3(1, 1) * positionStrength, Vector3.forward * rotationStrength),
noiseModes = modes,
envelope = envelopePars,
};
shaker.RegisterShake(new PerlinShake(pars));
}

public void Explosion3D(
float strength = 8f,
float duration = 0.7f)
{
PerlinShake.NoiseMode[] modes =
{
new PerlinShake.NoiseMode(6, 1),
new PerlinShake.NoiseMode(20, 0.2f)
};
Envelope.EnvelopeParams envelopePars = new Envelope.EnvelopeParams();
envelopePars.decay = duration <= 0 ? 1 : 1 / duration;
PerlinShake.Params pars = new PerlinShake.Params
{
strength = new Displacement(Vector3.zero, new Vector3(1, 1, 0.5f) * strength),
noiseModes = modes,
envelope = envelopePars,
};
shaker.RegisterShake(new PerlinShake(pars));
}
}
}
5 changes: 4 additions & 1 deletion Assets/CameraShake/Core/PerlinShake.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class PerlinShake : ICameraShake
Vector2[] seeds;
float time;
Vector3? sourcePosition;
float norm;

/// <summary>
/// Creates an instance of PerlinShake.
Expand Down Expand Up @@ -40,9 +41,11 @@ public PerlinShake(
public void Initialize(Vector3 cameraPosition, Quaternion cameraRotation)
{
seeds = new Vector2[pars.noiseModes.Length];
norm = 0;
for (int i = 0; i < seeds.Length; i++)
{
seeds[i] = Random.insideUnitCircle * 20;
norm += pars.noiseModes[i].amplitude;
}
}

Expand All @@ -59,7 +62,7 @@ public void Update(float deltaTime, Vector3 cameraPosition, Quaternion cameraRot
Displacement disp = Displacement.Zero;
for (int i = 0; i < pars.noiseModes.Length; i++)
{
disp += pars.noiseModes[i].amplitude *
disp += pars.noiseModes[i].amplitude / norm *
SampleNoise(seeds[i], pars.noiseModes[i].freq);
}

Expand Down
77 changes: 77 additions & 0 deletions Assets/CameraShake/Examples/Cube.mat
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Cube
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
m_ShaderKeywords:
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- _BumpScale: 1
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _GlossMapScale: 1
- _Glossiness: 0
- _GlossyReflections: 1
- _Metallic: 0
- _Mode: 0
- _OcclusionStrength: 1
- _Parallax: 0.02
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _UVSec: 0
- _ZWrite: 1
m_Colors:
- _Color: {r: 0.754717, g: 0.25180975, b: 0.17443931, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
8 changes: 8 additions & 0 deletions Assets/CameraShake/Examples/Cube.mat.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

77 changes: 77 additions & 0 deletions Assets/CameraShake/Examples/Floor.mat
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Floor
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
m_ShaderKeywords:
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- _BumpScale: 1
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _GlossMapScale: 1
- _Glossiness: 0.141
- _GlossyReflections: 1
- _Metallic: 0
- _Mode: 0
- _OcclusionStrength: 1
- _Parallax: 0.02
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _UVSec: 0
- _ZWrite: 1
m_Colors:
- _Color: {r: 0.5441979, g: 0.6603774, b: 0.34576362, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
8 changes: 8 additions & 0 deletions Assets/CameraShake/Examples/Floor.mat.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3cd48fb

Please sign in to comment.