Files
junisaber/assets/shaders/stage.js
2018-12-07 03:23:53 -08:00

29 lines
714 B
JavaScript

module.exports = {
vertexShader : `
varying vec2 uvs;
varying vec3 worldPos;
void main() {
uvs.xy = uv.xy;
vec4 p = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
worldPos = (modelMatrix * vec4( position, 1.0 )).xyz;
gl_Position = p;
}
`,
fragmentShader: `
#define FOG_RADIUS 50.0
#define FOG_FALLOFF 45.0
varying vec2 uvs;
varying vec3 worldPos;
uniform vec3 color;
uniform vec3 fogColor;
uniform sampler2D src;
void main() {
vec4 col = texture2D(src, uvs);
col.xyz = mix(fogColor, col.xyz, clamp(distance(worldPos, vec3(0., 0., -FOG_RADIUS)) / FOG_FALLOFF, 0., 1.));
gl_FragColor = col;
}
`
};