Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
LightFlicker
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
unity
LightFlicker
Commits
f24d3015
Commit
f24d3015
authored
3 years ago
by
David Huss
Browse files
Options
Downloads
Patches
Plain Diff
Initial commit
parents
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
LightFlicker.cs
+80
-0
80 additions, 0 deletions
LightFlicker.cs
with
80 additions
and
0 deletions
LightFlicker.cs
0 → 100644
+
80
−
0
View file @
f24d3015
using
System.Collections
;
using
System.Collections.Generic
;
using
UnityEngine
;
[
RequireComponent
(
typeof
(
Light
))]
public
class
LightFlicker
:
MonoBehaviour
{
[
Tooltip
(
"Base Brightness of the flickering light (used when Normality happens)"
)]
[
Range
(
0.0f
,
8.0f
)]
public
float
baseBrightness
=
1.0f
;
[
Tooltip
(
"Intensity of the periodic brightness fluctuations"
)]
[
Range
(
0.0f
,
10.0f
)]
public
float
oscillationIntensity
=
2.0f
;
[
Tooltip
(
"Frequency of the periodic brightness fluctuations"
)]
[
Range
(
0.0f
,
100.0f
)]
public
float
oscillationSpeed
=
44.0f
;
[
Tooltip
(
"Intensity of the random brightness flicker"
)]
[
Range
(
0.0f
,
10.0f
)]
public
float
flickerIntensity
=
2.0f
;
[
Tooltip
(
"Frequency of the random brightness flicker"
)]
[
Range
(
0.0f
,
1.0f
)]
public
float
flickerSpeed
=
0.1f
;
[
Tooltip
(
"Off vs On-percentage of the random brightness flicker"
)]
[
Range
(
0.0f
,
1.0f
)]
public
float
flickerOffVsOn
=
0.5f
;
[
Tooltip
(
"Frequency of the normality effect (where flicker and oscillations are switched off)"
)]
[
Range
(
0.0f
,
1.0f
)]
public
float
normalitySpeed
=
0.1f
;
[
Tooltip
(
"Likelyhood of the normality effect to happen (where flicker and oscillations are switched off)"
)]
[
Range
(
0.0f
,
1.0f
)]
public
float
normalityLikelyhood
=
0.5f
;
float
randomWalk
=
0.0f
;
float
flickerBrightness
=
0.0f
;
float
upperBound
=
1.0f
;
float
lowerBound
=
-
1.0f
;
float
oscillationBrightness
=
0.0f
;
float
randomWalk2
=
0.0f
;
float
upperBound2
=
1.0f
;
float
lowerBound2
=
0.0f
;
Light
thisLight
;
// Start is called before the first frame update
void
Start
()
{
thisLight
=
this
.
gameObject
.
GetComponent
<
Light
>();
}
// Update is called once per frame
void
Update
()
{
// Flicker
randomWalk
+=
Random
.
Range
(-
flickerSpeed
,
flickerSpeed
);
if
(
randomWalk
>=
upperBound
)
{
randomWalk
=
upperBound
;
}
if
(
randomWalk
<=
lowerBound
)
{
randomWalk
=
lowerBound
;
}
flickerBrightness
=
(
randomWalk
*
flickerIntensity
)
+
(-
8.0f
+
flickerOffVsOn
*
16.0f
)
*
flickerIntensity
;
// Oscillation
oscillationBrightness
=
((
Mathf
.
PingPong
(
Time
.
time
*
oscillationSpeed
,
8.0f
)
*
Mathf
.
PingPong
(
Time
.
time
*
oscillationSpeed
*
1.131517f
,
4.0f
))
-
4.0f
)
*
oscillationIntensity
*
0.1f
;
// Normality
randomWalk2
+=
Random
.
Range
(-
normalitySpeed
*
0.2f
,
normalitySpeed
*
0.2f
);
if
(
randomWalk2
>=
upperBound2
)
{
randomWalk2
=
upperBound2
;
}
if
(
randomWalk2
<=
lowerBound2
)
{
randomWalk2
=
lowerBound2
;
}
if
(
randomWalk2
<=
normalityLikelyhood
)
{
thisLight
.
intensity
=
baseBrightness
;
}
else
{
thisLight
.
intensity
=
baseBrightness
+
flickerBrightness
+
oscillationBrightness
;
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment