-
Notifications
You must be signed in to change notification settings - Fork 4
/
Sun.json
46 lines (46 loc) · 12.6 KB
/
Sun.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
{
"id": 4494,
"name": "Sun",
"fragment": "precision highp float;\nprecision highp int;\nuniform float time;\nuniform float contrast;\nuniform float brightness;\nuniform mat4 viewMatrix;\nuniform vec3 color;\nvarying vec3 vTexCoord3D;\nvarying vec3 vNormal;\nvarying vec3 vViewPosition;\nvec4 permute(vec4 x) \n {\n return mod(((x * 34.0) + 1.0) * x, 289.0);\n }\nvec4 taylorInvSqrt(vec4 r) \n {\n return 1.79284291400159 - 0.85373472095314 * r;\n }\nfloat snoise(vec3 v) \n {\n const vec2 C = vec2(1.0 / 6.0, 1.0 / 3.0);\n const vec4 D = vec4(0.0, 0.5, 1.0, 2.0);\n vec3 i = floor(v + dot(v, C.yyy));\n vec3 x0 = v - i + dot(i, C.xxx);\n vec3 g = step(x0.yzx, x0.xyz);\n vec3 l = 1.0 - g;\n vec3 i1 = min(g.xyz, l.zxy);\n vec3 i2 = max(g.xyz, l.zxy);\n vec3 x1 = x0 - i1 + 1.0 * C.xxx;\n vec3 x2 = x0 - i2 + 2.0 * C.xxx;\n vec3 x3 = x0 - 1. + 3.0 * C.xxx;\n i = mod(i, 289.0);\n vec4 p = permute(permute(permute(i.z + vec4(0.0, i1.z, i2.z, 1.0)) + i.y + vec4(0.0, i1.y, i2.y, 1.0)) + i.x + vec4(0.0, i1.x, i2.x, 1.0));\n float n_ = 1.0 / 7.0;\n vec3 ns = n_ * D.wyz - D.xzx;\n vec4 j = p - 49.0 * floor(p * ns.z * ns.z);\n vec4 x_ = floor(j * ns.z);\n vec4 y_ = floor(j - 7.0 * x_);\n vec4 x = x_ * ns.x + ns.yyyy;\n vec4 y = y_ * ns.x + ns.yyyy;\n vec4 h = 1.0 - abs(x) - abs(y);\n vec4 b0 = vec4(x.xy, y.xy);\n vec4 b1 = vec4(x.zw, y.zw);\n vec4 s0 = floor(b0) * 2.0 + 1.0;\n vec4 s1 = floor(b1) * 2.0 + 1.0;\n vec4 sh = -step(h, vec4(0.0));\n vec4 a0 = b0.xzyw + s0.xzyw * sh.xxyy;\n vec4 a1 = b1.xzyw + s1.xzyw * sh.zzww;\n vec3 p0 = vec3(a0.xy, h.x);\n vec3 p1 = vec3(a0.zw, h.y);\n vec3 p2 = vec3(a1.xy, h.z);\n vec3 p3 = vec3(a1.zw, h.w);\n vec4 norm = taylorInvSqrt(vec4(dot(p0, p0), dot(p1, p1), dot(p2, p2), dot(p3, p3)));\n p0 *= norm.x;\n p1 *= norm.y;\n p2 *= norm.z;\n p3 *= norm.w;\n vec4 m = max(0.6 - vec4(dot(x0, x0), dot(x1, x1), dot(x2, x2), dot(x3, x3)), 0.0);\n m = m * m;\n return 42.0 * dot(m * m, vec4(dot(p0, x0), dot(p1, x1), dot(p2, x2), dot(p3, x3)));\n }\nfloat heightMap(vec3 coord) \n {\n float n = abs(snoise(coord));\n n += 0.25 * abs(snoise(coord * 2.0));\n n += 0.25 * abs(snoise(coord * 4.0));\n n += 0.125 * abs(snoise(coord * 8.0));\n n += 0.0625 * abs(snoise(coord * 16.0));\n return n;\n }\nvec4 Lava1594265560658_1683_main(void) \n {\n vec4 Lava1594265560658_1683_gl_FragColor = vec4(0.0);\n float n = heightMap(vTexCoord3D);\n vec3 baseColor = color * vec3(color.r * 1.5 - n + 0.5, color.g - n + 0.5, color.b * 0.5 - n + 0.5);\n const float e = 0.001;\n float nx = heightMap(vTexCoord3D + vec3(e, 0.0, 0.0));\n float ny = heightMap(vTexCoord3D + vec3(0.0, e, 0.0));\n float nz = heightMap(vTexCoord3D + vec3(0.0, 0.0, e));\n vec3 normal = normalize(vNormal + contrast * vec3(n - nx, n - ny, n - nz) / e);\n vec3 vLightWeighting = vec3(0.1) * brightness;\n vec4 lDirection = viewMatrix * vec4(normalize(vec3(1.0, 0.0, 0.5)), 0.0);\n float directionalLightWeighting = dot(normal, normalize(lDirection.xyz)) * 0.25 + 0.75;\n vLightWeighting += vec3(1.0) * directionalLightWeighting;\n vec3 dirHalfVector = normalize(lDirection.xyz + normalize(vViewPosition));\n float dirDotNormalHalf = dot(normal, dirHalfVector);\n float dirSpecularWeight = 0.0;\n if (dirDotNormalHalf >= 0.0) dirSpecularWeight = (1.0 - n) * pow(dirDotNormalHalf, 5.0);\n vLightWeighting += color * dirSpecularWeight * n * 2.0;\n Lava1594265560658_1683_gl_FragColor = vec4(baseColor * vLightWeighting, 1.0);\n return Lava1594265560658_1683_gl_FragColor *= 1.0;\n }\nvoid main() \n {\n gl_FragColor = Lava1594265560658_1683_main(); }\n",
"vertex": "precision highp float;\nprecision highp int;\nuniform mat4 modelMatrix;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform mat4 viewMatrix;\nuniform mat3 normalMatrix;\nuniform vec3 cameraPosition;\nuniform float speed;\nuniform float time;\nuniform float scale;\nattribute vec3 position;\nattribute vec3 normal;\nattribute vec2 uv;\nattribute vec2 uv2;\nvarying vec3 vTexCoord3D;\nvarying vec3 vNormal;\nvarying vec3 vViewPosition;\nvec4 Lava1594265560658_1683_main(void) \n {\n vec4 Lava1594265560658_1683_gl_Position = vec4(0.0);\n vec4 mPosition = modelMatrix * vec4(position, 1.0);\n vNormal = normalize(normalMatrix * normal);\n vViewPosition = cameraPosition - mPosition.xyz;\n vTexCoord3D = scale * (position.xyz + vec3(0.0, 0.0, time * speed));\n Lava1594265560658_1683_gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);\n return Lava1594265560658_1683_gl_Position *= 1.0;\n }\nvoid main() \n {\n gl_Position = Lava1594265560658_1683_main(); }\n",
"uniforms": {
"time": {
"type": "f",
"glslType": "float"
},
"speed": {
"value": "0.03",
"type": "f",
"glslType": "float"
},
"scale": {
"value": "1",
"type": "f",
"glslType": "float"
},
"color": {
"value": {
"r": 0.8,
"g": 0.8,
"b": 0.8
},
"type": "c",
"glslType": "vec3"
},
"contrast": {
"value": "10",
"type": "f",
"glslType": "float"
},
"brightness": {
"value": "8.0",
"type": "f",
"glslType": "float"
}
},
"url": "http://shaderfrog.com/app/view/4494",
"user": {
"username": "jcastellano92",
"url": "http://shaderfrog.com/app/profile/andrewray"
}
}