Skip to content

Commit 513974e

Browse files
committed
Animated Lava
1 parent 1b8b0af commit 513974e

File tree

11 files changed

+194
-12
lines changed

11 files changed

+194
-12
lines changed

.idea/.idea.unity-demoscene/.idea/contentModel.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Demoscene/Projects/2018-07-12-Lava/Lava.asset

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
--- !u!114 &11400000
44
MonoBehaviour:
55
m_ObjectHideFlags: 0
6-
m_PrefabParentObject: {fileID: 0}
6+
m_CorrespondingSourceObject: {fileID: 0}
77
m_PrefabInternal: {fileID: 0}
88
m_GameObject: {fileID: 0}
99
m_Enabled: 1
@@ -53,4 +53,4 @@ MonoBehaviour:
5353
conditionsFolded: 0
5454
variablesFolded: 0
5555
materialsFolded: 0
56-
constantsFolded: 1
56+
constantsFolded: 0

Assets/Demoscene/Projects/2018-07-12-Lava/Lava.mat

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Material:
55
serializedVersion: 6
66
m_ObjectHideFlags: 0
7-
m_PrefabParentObject: {fileID: 0}
7+
m_CorrespondingSourceObject: {fileID: 0}
88
m_PrefabInternal: {fileID: 0}
99
m_Name: Lava
1010
m_Shader: {fileID: 4800000, guid: 5c314efc8c9d8449ab45d6dd0183c06e, type: 3}
@@ -17,15 +17,21 @@ Material:
1717
disabledShaderPasses: []
1818
m_SavedProperties:
1919
serializedVersion: 3
20-
m_TexEnvs: []
20+
m_TexEnvs:
21+
- _Noise:
22+
m_Texture: {fileID: 2800000, guid: e80c3c84ea861404d8a427db8b7abf04, type: 3}
23+
m_Scale: {x: 1, y: 1}
24+
m_Offset: {x: 0, y: 0}
2125
m_Floats:
26+
- _FlowIntensity: 0.32
27+
- _FlowSpeed: 0.5
2228
- _Loop: 99.2
2329
- _MinDistance: 0.01
2430
- _Power: 0.038
2531
- _ShadowExtraBias: 0.802
2632
- _ShadowLoop: 10
2733
- _ShadowMinDistance: 0.01
28-
- _Threshold: 1.38
34+
- _Threshold: 1.267
2935
m_Colors:
3036
- _Diffuse: {r: 0.9528302, g: 0.004494493, b: 0.004494493, a: 1}
3137
- _Emission: {r: 0, g: 0, b: 0, a: 0}

Assets/Demoscene/Projects/2018-07-12-Lava/Lava.shader

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ Properties
1616
_ShadowExtraBias("Shadow Extra Bias", Range(0.0, 1.0)) = 0.01
1717

1818
// @block Properties
19-
// _Color2("Color2", Color) = (1.0, 1.0, 1.0, 1.0)
20-
_Threshold("Threshold", Range(1.0, 2.0)) = 0.5
2119
_Power("Power", Range(0.0, 1.0)) = 0.5
2220
[HDR] _Lava("Lava", Color) = (1.0, 0.0, 0.0, 1.0)
21+
_Noise("Noise", 2D) = "gray" {}
22+
_Threshold("Threshold", Range(1.0, 2.0)) = 0.5
23+
_FlowIntensity("Flow Intensity", Range(0.0, 1.0)) = 0.2
24+
_FlowSpeed("Flow Speed", Range(0.0, 5.0)) = 0.2
2325
// @endblock
2426
}
2527

@@ -46,9 +48,9 @@ CGINCLUDE
4648
#include "Assets/uRaymarchingCustom/Common.cginc"
4749

4850
// @block DistanceFunction
51+
#include "Assets/Demoscene/Shaders/Includes/Common.cginc"
4952
#include "Assets/Demoscene/Shaders/Includes/Noise.cginc"
5053

51-
float _Threshold;
5254
float _Power;
5355

5456
inline float DistanceFunction(float3 pos)
@@ -69,9 +71,67 @@ inline float DistanceFunction(float3 pos)
6971

7072
// @block PostEffect
7173
float4 _Lava;
74+
sampler2D _Noise;
75+
float _Threshold;
76+
float _FlowIntensity;
77+
float _FlowSpeed;
78+
79+
// https://www.shadertoy.com/view/lslXRS
80+
float noise( in vec2 x ){
81+
return tex2D(_Noise, x*.01).x;
82+
}
83+
84+
vec2 gradn(vec2 p)
85+
{
86+
float ep = .09;
87+
float gradx = noise(vec2(p.x+ep,p.y))-noise(vec2(p.x-ep,p.y));
88+
float grady = noise(vec2(p.x,p.y+ep))-noise(vec2(p.x,p.y-ep));
89+
return vec2(gradx,grady);
90+
}
91+
92+
float lavaFlow(in vec2 p)
93+
{
94+
float z=2.;
95+
float rz = 0.;
96+
vec2 bp = p;
97+
for (float i= 1.; i < 3.; i++)
98+
{
99+
//primary flow speed
100+
p += _Time.y * .6 * _FlowSpeed;
101+
102+
//secondary flow speed (speed of the perceived flow)
103+
bp += _Time.y * 1.9 * _FlowSpeed;
104+
105+
//displacement field (try changing _Time.y multiplier)
106+
vec2 gr = gradn(i*p*.34 + _Time.y * 1.);
107+
108+
//rotation of the displacement field
109+
// gr *= rotateMat(_Time.y * 6.-(0.05 * p.x + 0.03 * p.y) * 40.);
110+
gr = mul(rotateMat(_Time.y * 6.-(0.05 * p.x + 0.03 * p.y) * 40.), gr);
111+
112+
//displace the system
113+
p += gr*.5;
114+
115+
//add noise octave
116+
rz+= (sin(noise(p) * 7.) * 0.5 + 0.5) / z;
117+
118+
//blend factor (blending displaced system with base system)
119+
//you could call this advection factor (.5 being low, .95 being high)
120+
p = mix(bp, p, .77);
121+
122+
//intensity scaling
123+
z *= 1.4;
124+
//octave scaling
125+
p *= 2.;
126+
bp *= 1.9;
127+
}
128+
return rz;
129+
}
130+
72131
inline void PostEffect(RaymarchInfo ray, inout PostEffectOutput o)
73132
{
74-
o.emission = step(ray.endPos.y, _Threshold) * _Lava;
133+
o.emission = step(ray.endPos.y, _Threshold + _FlowIntensity * lavaFlow(ray.endPos.xz)) * _Lava;
134+
// o.emission = lavaFlow(ray.endPos.xz) * _Lava;
75135
}
76136
// @endblock
77137

Assets/Demoscene/Projects/2018-07-12-Lava/Lava.unity

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,13 +333,13 @@ Transform:
333333
m_CorrespondingSourceObject: {fileID: 0}
334334
m_PrefabInternal: {fileID: 0}
335335
m_GameObject: {fileID: 1896176113}
336-
m_LocalRotation: {x: 0.13516438, y: 0.8623384, z: -0.3079131, w: 0.37854007}
337-
m_LocalPosition: {x: -0, y: 6.4, z: 0}
336+
m_LocalRotation: {x: 0.28891098, y: 0.020202622, z: -0.066766895, w: 0.9548112}
337+
m_LocalPosition: {x: -0, y: 6.13, z: 0}
338338
m_LocalScale: {x: 1, y: 1, z: 1}
339339
m_Children: []
340340
m_Father: {fileID: 0}
341341
m_RootOrder: 0
342-
m_LocalEulerAnglesHint: {x: 39.3, y: 132.6, z: 0}
342+
m_LocalEulerAnglesHint: {x: 33.67, y: 0, z: -8}
343343
--- !u!1 &1943384519
344344
GameObject:
345345
m_ObjectHideFlags: 0

Assets/Demoscene/Resources/Textures.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
95.1 KB
Loading

Assets/Demoscene/Resources/Textures/white_noise_256.png.meta

Lines changed: 86 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#ifndef __COMMON__
2+
#define __COMMON__
3+
4+
float2x2 rotateMat(float theta)
5+
{
6+
float c = cos(theta);
7+
float s = sin(theta);
8+
return float2x2(c, -s ,s, c);
9+
}
10+
11+
#endif

Assets/Demoscene/Shaders/Includes/Common.cginc.meta

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)