forked from 17thshard/roshar-map
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[docker-push] Add factions special effect for map
- Loading branch information
1 parent
86bf238
commit 71f2241
Showing
12 changed files
with
204 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { AdditiveBlending, Group, Mesh, PlaneBufferGeometry, ShaderMaterial } from 'three' | ||
import factionsFragmentShader from '@/components/map/factionsFragmentShader' | ||
import { clamp01 } from '@/utils.js' | ||
|
||
export default class Factions extends Group { | ||
constructor (texture) { | ||
super() | ||
this.position.set(0, 0, 1) | ||
this.frustumCulled = false | ||
|
||
this.enabled = false | ||
this.entering = true | ||
this.t = 0 | ||
|
||
this.init(texture) | ||
} | ||
|
||
init (texture) { | ||
const geo = new PlaneBufferGeometry(2, 2, 1, 1) | ||
const mat = new ShaderMaterial({ | ||
// language=GLSL | ||
vertexShader: ` | ||
varying vec2 vUv; | ||
void main() { | ||
vUv = uv; | ||
gl_Position = projectionMatrix * modelViewMatrix * vec4(position * vec3(512, 256, 1.0), 1.0); | ||
} | ||
`, | ||
fragmentShader: factionsFragmentShader, | ||
uniforms: { | ||
Texture: { value: texture }, | ||
Time: { value: 0 }, | ||
Progress: { value: 0 } | ||
}, | ||
depthTest: false, | ||
premultipliedAlpha: true, | ||
transparent: true, | ||
blending: AdditiveBlending | ||
}) | ||
|
||
this.plane = new Mesh(geo, mat) | ||
this.plane.frustumCulled = false | ||
|
||
this.add(this.plane) | ||
} | ||
|
||
enter () { | ||
this.entering = true | ||
this.enabled = true | ||
} | ||
|
||
leave () { | ||
this.entering = false | ||
this.enabled = true | ||
} | ||
|
||
update (camera, timestamp) { | ||
if (!this.enabled) { | ||
return | ||
} | ||
|
||
if (this.t <= 1) { | ||
this.t = clamp01(this.t + (this.entering ? 0.05 : -0.05)) | ||
} | ||
|
||
if (!this.entering && this.t <= 0) { | ||
this.enabled = false | ||
this.t = 0 | ||
} | ||
|
||
this.plane.material.uniforms.Progress.value = this.t | ||
this.plane.material.uniforms.Time.value = timestamp / 1000 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// language=GLSL | ||
export default ` | ||
#ifdef GL_ES | ||
precision highp float; | ||
#endif | ||
varying vec2 vUv; | ||
uniform sampler2D Texture; | ||
uniform float Progress; | ||
uniform float Time; | ||
const int OCTAVES = 4; | ||
const float INTENSITY = 2.; | ||
float random (vec2 st) { | ||
return fract(sin(dot(st.xy, vec2(12.9818, 79.279)))*43758.5453123); | ||
} | ||
vec2 random2(vec2 st){ | ||
st = vec2(dot(st, vec2(127.1, 311.7)), dot(st, vec2(269.5, 183.3))); | ||
return -1.0 + 2.0 * fract(sin(st) * 43759.34517123); | ||
} | ||
float noise(vec2 st) { | ||
vec2 i = floor(st); | ||
vec2 f = fract(st); | ||
// smootstep | ||
vec2 u = f*f*(3.0-2.0*f); | ||
return mix(mix(dot(random2(i + vec2(0.0, 0.0)), f - vec2(0.0, 0.0)), | ||
dot(random2(i + vec2(1.0, 0.0)), f - vec2(1.0, 0.0)), u.x), | ||
mix(dot(random2(i + vec2(0.0, 1.0)), f - vec2(0.0, 1.0)), | ||
dot(random2(i + vec2(1.0, 1.0)), f - vec2(1.0, 1.0)), u.x), u.y); | ||
} | ||
float fractal_brownian_motion(vec2 coord) { | ||
float value = 0.0; | ||
float scale = 0.5; | ||
for (int i = 0; i < 2; i++) { | ||
value += noise(coord) * scale; | ||
coord *= 2.0; | ||
scale *= 0.5; | ||
} | ||
return value + 0.25; | ||
} | ||
void main() { | ||
vec3 base = texture2D(Texture, vUv).rgb; | ||
vec2 pos = vec2(vUv * 8.0); | ||
vec2 motion = vec2(fractal_brownian_motion(pos + vec2(Time * 0.3, Time * 0.3))); | ||
vec3 factors = vec3( | ||
fractal_brownian_motion(pos + motion), | ||
fractal_brownian_motion(pos + motion + vec2(5., 0.)), | ||
fractal_brownian_motion(pos + motion + vec2(12., 4.)) | ||
) * INTENSITY; | ||
vec3 mixed = mix(vec3(.0, .0, .0), vec3(239. / 255., 187. / 255., 21. / 255.), base.r * factors.r); // Odium | ||
mixed = mix(mixed, vec3(85. / 255., 211. / 255., 35. / 255.), base.g * factors.g); // Neutral | ||
float total = floor(vUv.x * 256.) + floor(vUv.y * 128.); | ||
bool isEven = mod(total, 2.0) == 0.0; | ||
vec3 coalitionColor = mix(vec3(32. / 255., 137. / 255., 227. / 255.), vec3(136. / 255., 67. / 255., 19. / 255.), isEven ? 1. : 0.); | ||
mixed = mix(mixed, coalitionColor, base.b * (factors.b + 0.1)); // Coalition | ||
gl_FragColor = vec4(mixed * Progress, 0.8 * max(factors.r, max(factors.g, factors.b)) * max(base.r, max(base.g, base.b)) * Progress); | ||
} | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# State of the World | ||
Blurb | ||
|
||
## Details | ||
Details |