Skip to content

Commit 6d925db

Browse files
committed
seeking look...
1 parent 35f70c1 commit 6d925db

File tree

3 files changed

+88
-7
lines changed

3 files changed

+88
-7
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ Material:
2121
m_Floats:
2222
- _Loop: 99.2
2323
- _MinDistance: 0.01
24-
- _Power: 0.072
24+
- _Power: 0.038
2525
- _ShadowExtraBias: 0.802
2626
- _ShadowLoop: 10
2727
- _ShadowMinDistance: 0.01
28-
- _Threshold: 0.82
28+
- _Threshold: 1.38
2929
m_Colors:
3030
- _Diffuse: {r: 0.9528302, g: 0.004494493, b: 0.004494493, a: 1}
3131
- _Emission: {r: 0, g: 0, b: 0, a: 0}

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

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

1818
// @block Properties
1919
// _Color2("Color2", Color) = (1.0, 1.0, 1.0, 1.0)
20-
_Threshold("Threshold", Range(-5.0, 5.0)) = 0.5
20+
_Threshold("Threshold", Range(1.0, 2.0)) = 0.5
2121
_Power("Power", Range(0.0, 1.0)) = 0.5
2222
[HDR] _Lava("Lava", Color) = (1.0, 0.0, 0.0, 1.0)
2323
// @endblock
@@ -55,8 +55,12 @@ inline float DistanceFunction(float3 pos)
5555
{
5656
float2 c = cellular(float3(pos.xz, _Time.y));
5757
float h = c.y - c.x;
58-
// h = h > _Threshold ? 1.0 : 0.0;
5958
h = pow(h, _Power);
59+
60+
float2 c2 = cellular(float3(3.0 * pos.xz, 0.0));
61+
h += 0.5 * pow((c2.y - c2.x), _Power);
62+
63+
h += 0.001 * snoise(50.0 * pos.xz);
6064
return pos.y - h;
6165
}
6266
// @endblock

Assets/Demoscene/Shaders/Includes/Noise.cginc

Lines changed: 80 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,88 @@
33

44
#include "PortingFromGLSL.cginc"
55

6-
// https://thebookofshaders.com/edit.php#12/3d-cnoise.frag
7-
vec3 permute(vec3 x) {
8-
return mod((34.0 * x + 1.0) * x, 289.0);
6+
// https://thebookofshaders.com/edit.php#11/2d-snoise-clear.frag
7+
8+
// Some useful functions
9+
vec3 mod289(vec3 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }
10+
vec2 mod289(vec2 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }
11+
vec3 permute(vec3 x) { return mod289(((x*34.0)+1.0)*x); }
12+
13+
//
14+
// Description : GLSL 2D simplex noise function
15+
// Author : Ian McEwan, Ashima Arts
16+
// Maintainer : ijm
17+
// Lastmod : 20110822 (ijm)
18+
// License :
19+
// Copyright (C) 2011 Ashima Arts. All rights reserved.
20+
// Distributed under the MIT License. See LICENSE file.
21+
// https://github.com/ashima/webgl-noise
22+
//
23+
float snoise(vec2 v) {
24+
25+
// Precompute values for skewed triangular grid
26+
const vec4 C = vec4(0.211324865405187,
27+
// (3.0-sqrt(3.0))/6.0
28+
0.366025403784439,
29+
// 0.5*(sqrt(3.0)-1.0)
30+
-0.577350269189626,
31+
// -1.0 + 2.0 * C.x
32+
0.024390243902439);
33+
// 1.0 / 41.0
34+
35+
// First corner (x0)
36+
vec2 i = floor(v + dot(v, C.yy));
37+
vec2 x0 = v - i + dot(i, C.xx);
38+
39+
// Other two corners (x1, x2)
40+
vec2 i1 = vec2(0.0, 0.0);
41+
i1 = (x0.x > x0.y)? vec2(1.0, 0.0):vec2(0.0, 1.0);
42+
vec2 x1 = x0.xy + C.xx - i1;
43+
vec2 x2 = x0.xy + C.zz;
44+
45+
// Do some permutations to avoid
46+
// truncation effects in permutation
47+
i = mod289(i);
48+
vec3 p = permute(
49+
permute( i.y + vec3(0.0, i1.y, 1.0))
50+
+ i.x + vec3(0.0, i1.x, 1.0 ));
51+
52+
vec3 m = max(0.5 - vec3(
53+
dot(x0,x0),
54+
dot(x1,x1),
55+
dot(x2,x2)
56+
), 0.0);
57+
58+
m = m*m ;
59+
m = m*m ;
60+
61+
// Gradients:
62+
// 41 pts uniformly over a line, mapped onto a diamond
63+
// The ring size 17*17 = 289 is close to a multiple
64+
// of 41 (41*7 = 287)
65+
66+
vec3 x = 2.0 * fract(p * C.www) - 1.0;
67+
vec3 h = abs(x) - 0.5;
68+
vec3 ox = floor(x + 0.5);
69+
vec3 a0 = x - ox;
70+
71+
// Normalise gradients implicitly by scaling m
72+
// Approximation of: m *= inversesqrt(a0*a0 + h*h);
73+
m *= 1.79284291400159 - 0.85373472095314 * (a0*a0+h*h);
74+
75+
// Compute final noise value at P
76+
vec3 g = vec3(0.0, 0.0, 0.0);
77+
g.x = a0.x * x0.x + h.x * x0.y;
78+
g.yz = a0.yz * vec2(x1.x,x2.x) + h.yz * vec2(x1.y,x2.y);
79+
return 130.0 * dot(m, g);
980
}
1081

82+
83+
// https://thebookofshaders.com/edit.php#12/3d-cnoise.frag
84+
//vec3 permute(vec3 x) {
85+
// return mod((34.0 * x + 1.0) * x, 289.0);
86+
//}
87+
1188
// Cellular noise, returning F1 and F2 in a vec2.
1289
// 3x3x3 search region for good F2 everywhere, but a lot
1390
// slower than the 2x2x2 version.

0 commit comments

Comments
 (0)