Files
pixel.horse/src/ts/generated/shaders.ts
T
Eliot Partridge caf70a864f Revert codestyle changes (#40)
* Revert "7f7efbb94bab8574e42d942ad82d414e007b2970"

Code style changes should probably be part of a PR
2019-08-30 10:53:14 -05:00

18 lines
6.1 KiB
TypeScript

/* tslint:disable */
export const basicShader = `// VERTEX
attribute vec2 position;
attribute vec2 texcoords;
uniform mat4 transform;
varying vec2 textureCoord;
void main() {
textureCoord = texcoords;
gl_Position = transform * vec4(position, 0, 1);
}
// FRAGMENT
precision mediump float;
uniform sampler2D sampler1;
varying vec2 textureCoord;
void main() {
gl_FragColor = texture2D(sampler1, textureCoord);
}`;
export const lightShader = `// VERTEX
attribute vec2 position;
attribute vec2 texcoords;
attribute vec4 vertexColor;
uniform mat4 transform;
uniform vec4 lighting;
varying vec2 textureCoord;
varying vec4 vColor;
void main() {
textureCoord = texcoords;
vColor = vertexColor * lighting;
gl_Position = transform * vec4(position, 0, 1);
}
// FRAGMENT
precision mediump float;
varying vec2 textureCoord;
varying vec4 vColor;
void main() {
float d = clamp((1.0 - length(textureCoord)) + 0.1, 0.0, 1.0);
float m = d * d * d;
gl_FragColor = vec4(m, m, m, 1) * vColor;
}`;
export const paletteDepthShader = `// VERTEX
attribute vec3 position;
attribute vec4 texcoords;
attribute vec4 vertexColor;
uniform mat4 transform;
uniform vec4 lighting;
varying vec4 textureCoord;
varying vec4 vColor;
void main() {
textureCoord = texcoords;
vColor = vertexColor * lighting;
gl_Position = transform * vec4(position, 1);
}
// FRAGMENT
precision mediump float;
uniform sampler2D sampler1; // sprite
uniform sampler2D sampler2; // palette
uniform float pixelSize;
varying vec4 textureCoord;
varying vec4 vColor;
void main() {
vec4 sprite = texture2D(sampler1, vec2(textureCoord.x, textureCoord.y));
vec4 palette = texture2D(sampler2, vec2(textureCoord.z + sprite.x * pixelSize, textureCoord.w));
vec4 color = vec4(palette.xyz * sprite.y, palette.w) * vColor;
gl_FragColor = color;
if (color.a < 0.01)
discard;
}`;
export const paletteLayersInstancedShader = `// VERTEX
attribute vec2 position0;
attribute vec4 position1;
attribute vec4 texcoord0;
attribute vec2 texcoord1;
attribute vec4 vertexColor;
attribute vec4 vertexColor1;
uniform mat4 transform;
uniform vec4 lighting;
varying vec2 textureCoord0;
varying vec2 textureCoord1;
varying vec4 vColor;
varying vec4 vColor1;
void main() {
textureCoord0 = vec2(texcoord0.x + position0.x * texcoord0.z, texcoord0.y + position0.y * texcoord0.w);
textureCoord1 = texcoord1;
vColor = vertexColor * lighting;
vColor1 = vertexColor1;
gl_Position = transform * vec4(
position1.x + position0.x * position1.z, position1.y + position0.y * position1.w, 0, 1);
}
// FRAGMENT
precision mediump float;
uniform sampler2D sampler1; // sprite
uniform sampler2D sampler2; // palette
uniform float pixelSize;
varying vec2 textureCoord0;
varying vec2 textureCoord1;
varying vec4 vColor;
varying vec4 vColor1;
void main() {
vec4 sprite = texture2D(sampler1, textureCoord0.xy);
float shade = clamp(sprite.g + vColor1.a, 0.0, 1.0);
vec4 mask = vec4(vColor1.rgb, 1.0 - (vColor1.r + vColor1.g + vColor1.b));
float paletteIndex = dot(mask, sprite);
vec4 palette = texture2D(sampler2, vec2(textureCoord1.x + paletteIndex * pixelSize, textureCoord1.y));
gl_FragColor = vec4(palette.xyz * shade, palette.w) * vColor;
}`;
export const paletteLayersShader = `// VERTEX
attribute vec2 position;
attribute vec4 texcoords;
attribute vec4 vertexColor;
attribute vec4 vertexColor1;
uniform mat4 transform;
uniform vec4 lighting;
varying vec4 textureCoord;
varying vec4 vColor;
varying vec4 vColor1;
void main() {
textureCoord = texcoords;
// float f = texcoords.z;
// float fr = fract(texcoords.z);
// textureCoord.z = fr;
// textureCoord.w = (f - fr) / 1024.0;
vColor = vertexColor * lighting;
vColor1 = vertexColor1;
gl_Position = transform * vec4(position, 0, 1);
}
// FRAGMENT
precision mediump float;
uniform sampler2D sampler1; // sprite
uniform sampler2D sampler2; // palette
uniform float pixelSize;
uniform float textureSize;
varying vec4 textureCoord;
varying vec4 vColor;
varying vec4 vColor1;
void main() {
vec4 sprite = texture2D(sampler1, textureCoord.xy / textureSize);
float shade = clamp(sprite.g + vColor1.a, 0.0, 1.0);
vec4 mask = vec4(vColor1.rgb, 1.0 - (vColor1.r + vColor1.g + vColor1.b));
float paletteIndex = dot(mask, sprite);
vec2 paletteCoord = textureCoord.zw;
vec4 palette = texture2D(sampler2, vec2(paletteCoord.x + paletteIndex * pixelSize, paletteCoord.y));
gl_FragColor = vec4(palette.xyz * shade, palette.w) * vColor;
}`;
export const paletteShader = `// VERTEX
attribute vec2 position;
attribute vec4 texcoords;
attribute vec4 vertexColor;
uniform mat4 transform;
uniform vec4 lighting;
varying vec4 textureCoord;
varying vec4 vColor;
void main() {
textureCoord = texcoords;
vColor = vertexColor * lighting;
gl_Position = transform * vec4(position, 0, 1);
}
// FRAGMENT
precision mediump float;
uniform sampler2D sampler1; // sprite
uniform sampler2D sampler2; // palette
uniform float pixelSize;
varying vec4 textureCoord;
varying vec4 vColor;
void main() {
vec4 sprite = texture2D(sampler1, vec2(textureCoord.x, textureCoord.y));
vec4 palette = texture2D(sampler2, vec2(textureCoord.z + sprite.x * pixelSize, textureCoord.w));
gl_FragColor = vec4(palette.xyz * sprite.y, palette.w) * vColor;
}`;
export const spriteShader = `// VERTEX
attribute vec2 position;
attribute vec2 texcoords;
attribute vec4 vertexColor;
uniform mat4 transform;
uniform vec4 lighting;
varying vec2 textureCoord;
varying vec4 vColor;
void main() {
textureCoord = texcoords;
vColor = vertexColor * lighting;
gl_Position = transform * vec4(position, 0, 1);
}
// FRAGMENT
precision mediump float;
uniform sampler2D sampler1;
uniform float textureSize;
varying vec2 textureCoord;
varying vec4 vColor;
void main() {
gl_FragColor = texture2D(sampler1, textureCoord / textureSize) * vColor;
}`;
export const sprite2Shader = `// VERTEX
attribute vec3 position;
attribute vec2 texcoords;
attribute vec4 vertexColor;
uniform mat4 transform;
varying vec2 textureCoord;
varying vec4 vColor;
void main() {
textureCoord = texcoords;
vColor = vertexColor;
gl_Position = transform * vec4(position, 1);
}
// FRAGMENT
precision mediump float;
uniform sampler2D sampler1;
varying vec2 textureCoord;
varying vec4 vColor;
void main() {
gl_FragColor = texture2D(sampler1, textureCoord) * vColor;
}`;