Skip to content

Commit 4adbeb6

Browse files
committed
Support RaymarchingWorldSandwich LocalTime
1 parent b7de455 commit 4adbeb6

File tree

5 files changed

+78
-51
lines changed

5 files changed

+78
-51
lines changed

Assets/Demoscene/Projects/2018-05-28-Sandwich/uRaymarchingShaders/Sandwich.shader

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Properties
1717

1818
// @block Properties
1919
// _Color2("Color2", Color) = (1.0, 1.0, 1.0, 1.0)
20+
_LocalTime("Local Time", Float) = 0
2021
_SlideEmission("Slide Emission", Vector) = (2.0, 2.0, 5.0, 1.0)
2122
// @endblock
2223
}
@@ -44,6 +45,8 @@ CGINCLUDE
4445
#include "Assets/uRaymarchingCustom/Common.cginc"
4546

4647
// @block DistanceFunction
48+
float _LocalTime;
49+
4750
float dFloor(float3 pos)
4851
{
4952
float3 p = pos;
@@ -55,7 +58,7 @@ float dFloor(float3 pos)
5558
inline float DistanceFunction(float3 pos)
5659
{
5760
float height = 4;
58-
pos.y += 0.1 * sin(12.0 * _Time.x + 5.0 * Rand(floor(pos.xz)));
61+
pos.y += 0.1 * sin(12.0 / 20 * _LocalTime + 5.0 * Rand(floor(pos.xz)));
5962
float d = dFloor(pos - float3(0, -height, 0));
6063
d = min(d, dFloor(pos - float3(0, height, 0)));
6164
return d;
@@ -67,9 +70,9 @@ float4 _SlideEmission;
6770

6871
inline void PostEffect(RaymarchInfo ray, inout PostEffectOutput o)
6972
{
70-
float a = frac(4.0 * abs(ray.endPos.y) - 2.0 * _Time.x);
73+
float a = frac(4.0 * abs(ray.endPos.y) - 2.0 / 20 * _LocalTime);
7174
float width = 0.1;
72-
o.emission = _SlideEmission * abs(sin(PI * 12.0 * _Time.x)) * step(a, width) * ((a + 0.5 * width) / width);
75+
o.emission = _SlideEmission * abs(sin(PI * 12.0 / 20 * _LocalTime)) * step(a, width) * ((a + 0.5 * width) / width);
7376
}
7477
// @endblock
7578

Assets/Demoscene/Scripts/Timeline/RaymarchingWolrdSandwich/RaymarchingWolrdSandwichBehaviour.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@
22
using UnityEngine;
33
using UnityEngine.Playables;
44
using UnityEngine.Timeline;
5-
using Demoscene;
65

7-
[Serializable]
8-
public class RaymarchingWolrdSandwichBehaviour : PlayableBehaviour
6+
namespace Demoscene
97
{
10-
public float param1;
11-
public float param2;
12-
public Vector3 vec1;
13-
14-
public override void OnPlayableCreate (Playable playable)
8+
[Serializable]
9+
public class RaymarchingWolrdSandwichBehaviour : PlayableBehaviour
1510
{
16-
11+
public float param1;
12+
public float param2;
13+
public Vector3 vec1;
14+
15+
public override void OnPlayableCreate(Playable playable)
16+
{
17+
}
1718
}
18-
}
19+
}

Assets/Demoscene/Scripts/Timeline/RaymarchingWolrdSandwich/RaymarchingWolrdSandwichClip.cs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,24 @@
22
using UnityEngine;
33
using UnityEngine.Playables;
44
using UnityEngine.Timeline;
5-
using Demoscene;
65

7-
[Serializable]
8-
public class RaymarchingWolrdSandwichClip : PlayableAsset, ITimelineClipAsset
6+
namespace Demoscene
97
{
10-
public RaymarchingWolrdSandwichBehaviour template = new RaymarchingWolrdSandwichBehaviour ();
11-
12-
public ClipCaps clipCaps
8+
[Serializable]
9+
public class RaymarchingWolrdSandwichClip : PlayableAsset, ITimelineClipAsset
1310
{
14-
get { return ClipCaps.None; }
15-
}
11+
public RaymarchingWolrdSandwichBehaviour template = new RaymarchingWolrdSandwichBehaviour();
1612

17-
public override Playable CreatePlayable (PlayableGraph graph, GameObject owner)
18-
{
19-
var playable = ScriptPlayable<RaymarchingWolrdSandwichBehaviour>.Create (graph, template);
20-
RaymarchingWolrdSandwichBehaviour clone = playable.GetBehaviour ();
21-
return playable;
13+
public ClipCaps clipCaps
14+
{
15+
get { return ClipCaps.None; }
16+
}
17+
18+
public override Playable CreatePlayable(PlayableGraph graph, GameObject owner)
19+
{
20+
var playable = ScriptPlayable<RaymarchingWolrdSandwichBehaviour>.Create(graph, template);
21+
RaymarchingWolrdSandwichBehaviour clone = playable.GetBehaviour();
22+
return playable;
23+
}
2224
}
23-
}
25+
}
Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,48 @@
11
using System;
2+
using System.Runtime.InteropServices;
23
using UnityEngine;
34
using UnityEngine.Playables;
45
using UnityEngine.Timeline;
5-
using Demoscene;
66

7-
public class RaymarchingWolrdSandwichMixerBehaviour : PlayableBehaviour
7+
namespace Demoscene
88
{
9-
// NOTE: This function is called at runtime and edit time. Keep that in mind when setting the values of properties.
10-
public override void ProcessFrame(Playable playable, FrameData info, object playerData)
9+
public class RaymarchingWolrdSandwichMixerBehaviour : PlayableBehaviour
1110
{
12-
RaymarchingWorldSandwichComponet trackBinding = playerData as RaymarchingWorldSandwichComponet;
11+
// NOTE: This function is called at runtime and edit time. Keep that in mind when setting the values of properties.
12+
public override void ProcessFrame(Playable playable, FrameData info, object playerData)
13+
{
14+
RaymarchingWorldSandwichComponet trackBinding = playerData as RaymarchingWorldSandwichComponet;
1315

14-
if (!trackBinding)
15-
return;
16+
if (!trackBinding)
17+
return;
1618

17-
int inputCount = playable.GetInputCount ();
19+
int inputCount = playable.GetInputCount();
1820

19-
for (int i = 0; i < inputCount; i++)
20-
{
21-
float inputWeight = playable.GetInputWeight(i);
22-
ScriptPlayable<RaymarchingWolrdSandwichBehaviour> inputPlayable = (ScriptPlayable<RaymarchingWolrdSandwichBehaviour>)playable.GetInput(i);
23-
RaymarchingWolrdSandwichBehaviour input = inputPlayable.GetBehaviour ();
24-
25-
// Use the above variables to process each frame of this playable.
21+
var maxWeight = 0f;
22+
var time = 0f;
23+
24+
for (int i = 0; i < inputCount; i++)
25+
{
26+
var weight = playable.GetInputWeight(i);
27+
if (Mathf.Approximately(weight, 0))
28+
{
29+
continue;
30+
}
31+
32+
ScriptPlayable<RaymarchingWolrdSandwichBehaviour> inputPlayable =
33+
(ScriptPlayable<RaymarchingWolrdSandwichBehaviour>) playable.GetInput(i);
34+
RaymarchingWolrdSandwichBehaviour input = inputPlayable.GetBehaviour();
35+
36+
// Use the above variables to process each frame of this playable.
37+
// NOTE: hosoda-sho 単純なブレンドが難しい値は最もウェイトが高いクリップを採用
38+
if (weight > maxWeight)
39+
{
40+
time = (float) inputPlayable.GetTime();
41+
maxWeight = weight;
42+
}
43+
}
2644

45+
trackBinding.ApplyTime(time);
2746
}
2847
}
29-
}
48+
}
Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
using UnityEngine;
22
using UnityEngine.Playables;
33
using UnityEngine.Timeline;
4-
using Demoscene;
54

6-
[TrackColor(0.855f, 0.8623f, 0.87f)]
7-
[TrackClipType(typeof(RaymarchingWolrdSandwichClip))]
8-
[TrackBindingType(typeof(RaymarchingWorldSandwichComponet))]
9-
public class RaymarchingWolrdSandwichTrack : TrackAsset
5+
namespace Demoscene
106
{
11-
public override Playable CreateTrackMixer(PlayableGraph graph, GameObject go, int inputCount)
7+
[TrackColor(0.855f, 0.8623f, 0.87f)]
8+
[TrackClipType(typeof(RaymarchingWolrdSandwichClip))]
9+
[TrackBindingType(typeof(RaymarchingWorldSandwichComponet))]
10+
public class RaymarchingWolrdSandwichTrack : TrackAsset
1211
{
13-
return ScriptPlayable<RaymarchingWolrdSandwichMixerBehaviour>.Create (graph, inputCount);
12+
public override Playable CreateTrackMixer(PlayableGraph graph, GameObject go, int inputCount)
13+
{
14+
return ScriptPlayable<RaymarchingWolrdSandwichMixerBehaviour>.Create(graph, inputCount);
15+
}
1416
}
15-
}
17+
}

0 commit comments

Comments
 (0)