Initial commit
This commit is contained in:
15
engines/stark/shaders/stark_actor.fragment
Normal file
15
engines/stark/shaders/stark_actor.fragment
Normal file
@@ -0,0 +1,15 @@
|
||||
in vec2 Texcoord;
|
||||
in vec3 Color;
|
||||
|
||||
OUTPUT
|
||||
|
||||
uniform UBOOL textured;
|
||||
uniform sampler2D tex;
|
||||
|
||||
void main() {
|
||||
outColor = vec4(Color, 1.0);
|
||||
|
||||
if (UBOOL_TEST(textured)) {
|
||||
outColor *= texture(tex, Texcoord);
|
||||
}
|
||||
}
|
||||
118
engines/stark/shaders/stark_actor.vertex
Normal file
118
engines/stark/shaders/stark_actor.vertex
Normal file
@@ -0,0 +1,118 @@
|
||||
in vec3 position1;
|
||||
in vec3 position2;
|
||||
in float bone1; // No ints as shader attributes in GLSL 1.20
|
||||
in float bone2; // No ints as shader attributes in GLSL 1.20
|
||||
in float boneWeight;
|
||||
in vec3 normal;
|
||||
in vec2 texcoord;
|
||||
|
||||
out vec2 Texcoord;
|
||||
out vec3 Color;
|
||||
|
||||
struct Light {
|
||||
vec4 position;
|
||||
vec3 direction;
|
||||
vec3 color;
|
||||
vec4 params;
|
||||
};
|
||||
|
||||
const int lightTypePoint = 1;
|
||||
const int lightTypeDirectional = 2;
|
||||
const int lightTypeSpot = 4;
|
||||
|
||||
const int maxLights = 10;
|
||||
const int maxBones = 70;
|
||||
|
||||
uniform mat4 modelViewMatrix;
|
||||
uniform mat4 projectionMatrix;
|
||||
uniform mat3 normalMatrix;
|
||||
uniform vec4 boneRotation[maxBones];
|
||||
uniform vec3 bonePosition[maxBones];
|
||||
uniform Light lights[maxLights];
|
||||
uniform vec3 ambientColor;
|
||||
uniform vec3 color;
|
||||
uniform UBOOL textured;
|
||||
|
||||
vec4 eyePosition;
|
||||
vec3 eyeNormal;
|
||||
|
||||
vec3 qrot(vec4 q, vec3 v) {
|
||||
return v + 2.0 * cross(q.xyz, cross(q.xyz, v) + q.w * v);
|
||||
}
|
||||
|
||||
vec3 pointLight(vec3 position, vec3 color, float falloffNear, float falloffFar) {
|
||||
vec3 vertexToLight = position - eyePosition.xyz;
|
||||
|
||||
float dist = length(vertexToLight);
|
||||
float attn = clamp((falloffFar - dist) / max(0.001, falloffFar - falloffNear), 0.0, 1.0);
|
||||
|
||||
vertexToLight = normalize(vertexToLight);
|
||||
float incidence = max(0.0, dot(eyeNormal, vertexToLight));
|
||||
|
||||
return color * attn * incidence;
|
||||
}
|
||||
|
||||
vec3 directionalLight(vec3 direction, vec3 color) {
|
||||
float incidence = max(0.0, dot(eyeNormal, -direction));
|
||||
|
||||
return color * incidence;
|
||||
}
|
||||
|
||||
vec3 spotLight(vec3 position, vec3 color, float falloffNear, float falloffFar, vec3 direction, float cosInnerAngle, float cosOuterAngle) {
|
||||
vec3 vertexToLight = position - eyePosition.xyz;
|
||||
|
||||
float dist = length(vertexToLight);
|
||||
float attn = clamp((falloffFar - dist) / max(0.001, falloffFar - falloffNear), 0.0, 1.0);
|
||||
|
||||
vertexToLight = normalize(vertexToLight);
|
||||
float incidence = max(0.0, dot(eyeNormal, vertexToLight));
|
||||
|
||||
float cosAngle = max(0.0, dot(vertexToLight, -direction));
|
||||
float cone = clamp((cosAngle - cosInnerAngle) / max(0.001, cosOuterAngle - cosInnerAngle), 0.0, 1.0);
|
||||
|
||||
return color * attn * incidence * cone;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
Texcoord = texcoord;
|
||||
|
||||
// Compute the vertex position in eye-space
|
||||
vec3 b1 = qrot(boneRotation[int(bone1)], position1) + bonePosition[int(bone1)];
|
||||
vec3 b2 = qrot(boneRotation[int(bone2)], position2) + bonePosition[int(bone2)];
|
||||
vec3 modelPosition = mix(b2, b1, boneWeight);
|
||||
eyePosition = modelViewMatrix * vec4(modelPosition.xyz, 1.0);
|
||||
|
||||
// Compute the vertex normal in eye-space
|
||||
vec3 n1 = qrot(boneRotation[int(bone1)], normal);
|
||||
vec3 n2 = qrot(boneRotation[int(bone2)], normal);
|
||||
vec3 modelNormal = normalize(mix(n2, n1, boneWeight));
|
||||
eyeNormal = normalMatrix * modelNormal;
|
||||
eyeNormal = normalize(eyeNormal);
|
||||
|
||||
// Compute the vertex position in screen-space
|
||||
gl_Position = projectionMatrix * eyePosition;
|
||||
|
||||
// Set the initial vertex color
|
||||
if (UBOOL_TEST(textured)) {
|
||||
Color = vec3(1.0);
|
||||
} else {
|
||||
Color = color;
|
||||
}
|
||||
|
||||
// Shade the vertex color according to the lights
|
||||
vec3 lightColor = ambientColor;
|
||||
for (int i = 0; i < maxLights; i++) {
|
||||
int type = int(lights[i].position.w);
|
||||
if (type == lightTypePoint) {
|
||||
lightColor += pointLight(lights[i].position.xyz, lights[i].color, lights[i].params.x, lights[i].params.y);
|
||||
} else if (type == lightTypeDirectional) {
|
||||
lightColor += directionalLight(lights[i].direction, lights[i].color);
|
||||
} else if (type == lightTypeSpot) {
|
||||
lightColor += spotLight(lights[i].position.xyz, lights[i].color, lights[i].params.x, lights[i].params.y,
|
||||
lights[i].direction, lights[i].params.z, lights[i].params.w);
|
||||
}
|
||||
}
|
||||
|
||||
Color *= clamp(lightColor, 0.0, 1.0);
|
||||
}
|
||||
8
engines/stark/shaders/stark_fade.fragment
Normal file
8
engines/stark/shaders/stark_fade.fragment
Normal file
@@ -0,0 +1,8 @@
|
||||
|
||||
OUTPUT
|
||||
|
||||
uniform float alphaLevel;
|
||||
|
||||
void main() {
|
||||
outColor = vec4(0.0, 0.0, 0.0, alphaLevel);
|
||||
}
|
||||
5
engines/stark/shaders/stark_fade.vertex
Normal file
5
engines/stark/shaders/stark_fade.vertex
Normal file
@@ -0,0 +1,5 @@
|
||||
in vec2 position;
|
||||
|
||||
void main() {
|
||||
gl_Position = vec4(position, 0.0, 1.0);
|
||||
}
|
||||
18
engines/stark/shaders/stark_prop.fragment
Normal file
18
engines/stark/shaders/stark_prop.fragment
Normal file
@@ -0,0 +1,18 @@
|
||||
in vec2 Texcoord;
|
||||
in vec3 Color;
|
||||
|
||||
OUTPUT
|
||||
|
||||
uniform UBOOL textured;
|
||||
uniform vec3 color;
|
||||
uniform sampler2D tex;
|
||||
|
||||
void main() {
|
||||
outColor = vec4(Color, 1.0);
|
||||
|
||||
if (UBOOL_TEST(textured)) {
|
||||
outColor *= texture(tex, Texcoord);
|
||||
} else {
|
||||
outColor *= vec4(color, 1.0);
|
||||
}
|
||||
}
|
||||
92
engines/stark/shaders/stark_prop.vertex
Normal file
92
engines/stark/shaders/stark_prop.vertex
Normal file
@@ -0,0 +1,92 @@
|
||||
in vec3 position;
|
||||
in vec3 normal;
|
||||
in vec3 texcoord;
|
||||
|
||||
out vec2 Texcoord;
|
||||
out vec3 Color;
|
||||
|
||||
struct Light {
|
||||
vec4 position;
|
||||
vec3 direction;
|
||||
vec3 color;
|
||||
vec4 params;
|
||||
};
|
||||
|
||||
const int lightTypePoint = 1;
|
||||
const int lightTypeDirectional = 2;
|
||||
const int lightTypeSpot = 4;
|
||||
|
||||
const int maxLights = 10;
|
||||
|
||||
uniform mat4 modelViewMatrix;
|
||||
uniform mat4 projectionMatrix;
|
||||
uniform mat3 normalMatrix;
|
||||
uniform UBOOL doubleSided;
|
||||
uniform vec3 ambientColor;
|
||||
uniform Light lights[maxLights];
|
||||
|
||||
vec4 eyePosition;
|
||||
vec3 eyeNormal;
|
||||
|
||||
vec3 pointLight(vec3 position, vec3 color, float falloffNear, float falloffFar) {
|
||||
vec3 vertexToLight = position - eyePosition.xyz;
|
||||
|
||||
float dist = length(vertexToLight);
|
||||
float attn = clamp((falloffFar - dist) / max(0.001, falloffFar - falloffNear), 0.0, 1.0);
|
||||
|
||||
vertexToLight = normalize(vertexToLight);
|
||||
float incidence = max(0.0, dot(eyeNormal, vertexToLight));
|
||||
|
||||
return color * attn * incidence;
|
||||
}
|
||||
|
||||
vec3 directionalLight(vec3 direction, vec3 color) {
|
||||
float incidence = max(0.0, dot(eyeNormal, -direction));
|
||||
|
||||
return color * incidence;
|
||||
}
|
||||
|
||||
vec3 spotLight(vec3 position, vec3 color, float falloffNear, float falloffFar, vec3 direction, float cosInnerAngle, float cosOuterAngle) {
|
||||
vec3 vertexToLight = position - eyePosition.xyz;
|
||||
|
||||
float dist = length(vertexToLight);
|
||||
float attn = clamp((falloffFar - dist) / max(0.001, falloffFar - falloffNear), 0.0, 1.0);
|
||||
|
||||
vertexToLight = normalize(vertexToLight);
|
||||
float incidence = max(0.0, dot(eyeNormal, vertexToLight));
|
||||
|
||||
float cosAngle = max(0.0, dot(vertexToLight, -direction));
|
||||
float cone = clamp((cosAngle - cosInnerAngle) / max(0.001, cosOuterAngle - cosInnerAngle), 0.0, 1.0);
|
||||
|
||||
return color * attn * incidence * cone;
|
||||
}
|
||||
|
||||
void main() {
|
||||
if (UBOOL_TEST(doubleSided)) {
|
||||
Texcoord = vec2(texcoord.x, 1.0 - texcoord.y);
|
||||
} else {
|
||||
Texcoord = vec2(1.0 - texcoord.x, 1.0 - texcoord.y);
|
||||
}
|
||||
|
||||
// Compute the vertex position in screen-space
|
||||
eyePosition = modelViewMatrix * vec4(position.xyz, 1.0);
|
||||
eyeNormal = normalMatrix * normal;
|
||||
eyeNormal = normalize(eyeNormal);
|
||||
gl_Position = projectionMatrix * eyePosition;
|
||||
|
||||
// Shade the vertex color according to the lights
|
||||
vec3 lightColor = ambientColor;
|
||||
for (int i = 0; i < maxLights; i++) {
|
||||
int type = int(lights[i].position.w);
|
||||
if (type == lightTypePoint) {
|
||||
lightColor += pointLight(lights[i].position.xyz, lights[i].color, lights[i].params.x, lights[i].params.y);
|
||||
} else if (type == lightTypeDirectional) {
|
||||
lightColor += directionalLight(lights[i].direction, lights[i].color);
|
||||
} else if (type == lightTypeSpot) {
|
||||
lightColor += spotLight(lights[i].position.xyz, lights[i].color, lights[i].params.x, lights[i].params.y,
|
||||
lights[i].direction, lights[i].params.z, lights[i].params.w);
|
||||
}
|
||||
}
|
||||
|
||||
Color = clamp(lightColor, 0.0, 1.0);
|
||||
}
|
||||
5
engines/stark/shaders/stark_shadow.fragment
Normal file
5
engines/stark/shaders/stark_shadow.fragment
Normal file
@@ -0,0 +1,5 @@
|
||||
OUTPUT
|
||||
|
||||
void main() {
|
||||
outColor = vec4(0.0, 0.0, 0.0, 0.5);
|
||||
}
|
||||
30
engines/stark/shaders/stark_shadow.vertex
Normal file
30
engines/stark/shaders/stark_shadow.vertex
Normal file
@@ -0,0 +1,30 @@
|
||||
in vec3 position1;
|
||||
in vec3 position2;
|
||||
in float bone1;
|
||||
in float bone2;
|
||||
in float boneWeight;
|
||||
|
||||
const int maxBones = 70;
|
||||
|
||||
uniform mat4 mvp;
|
||||
uniform vec4 boneRotation[maxBones];
|
||||
uniform vec3 bonePosition[maxBones];
|
||||
uniform vec3 lightDirection;
|
||||
|
||||
vec3 qrot(vec4 q, vec3 v) {
|
||||
return v + 2.0 * cross(q.xyz, cross(q.xyz, v) + q.w * v);
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec3 b1 = qrot(boneRotation[int(bone1)], position1) + bonePosition[int(bone1)];
|
||||
vec3 b2 = qrot(boneRotation[int(bone2)], position2) + bonePosition[int(bone2)];
|
||||
vec3 modelPosition = mix(b2, b1, boneWeight);
|
||||
|
||||
// Project the modelPosition to the xz plane
|
||||
vec3 shadowPosition = modelPosition + lightDirection * (-modelPosition.y / lightDirection.y);
|
||||
|
||||
// In case precision problem
|
||||
shadowPosition.y = 0.0;
|
||||
|
||||
gl_Position = mvp * vec4(shadowPosition.xyz, 1.0);
|
||||
}
|
||||
11
engines/stark/shaders/stark_surface.fragment
Normal file
11
engines/stark/shaders/stark_surface.fragment
Normal file
@@ -0,0 +1,11 @@
|
||||
in vec2 Texcoord;
|
||||
|
||||
OUTPUT
|
||||
|
||||
uniform float fadeLevel;
|
||||
uniform sampler2D tex;
|
||||
|
||||
void main() {
|
||||
vec4 texColor = texture(tex, Texcoord);
|
||||
outColor = texColor + vec4(fadeLevel, fadeLevel, fadeLevel, 0) * texColor.a;
|
||||
}
|
||||
28
engines/stark/shaders/stark_surface.vertex
Normal file
28
engines/stark/shaders/stark_surface.vertex
Normal file
@@ -0,0 +1,28 @@
|
||||
in vec2 position;
|
||||
in vec2 texcoord;
|
||||
|
||||
uniform vec2 verOffsetXY;
|
||||
uniform vec2 verSizeWH;
|
||||
uniform vec2 viewport;
|
||||
uniform UBOOL snapToGrid;
|
||||
|
||||
out vec2 Texcoord;
|
||||
|
||||
void main() {
|
||||
Texcoord = texcoord;
|
||||
|
||||
// Coordinates are [0.0; 1.0], transform to [-1.0; 1.0]
|
||||
vec2 pos = verOffsetXY + position * verSizeWH;
|
||||
|
||||
if (UBOOL_TEST(snapToGrid)) {
|
||||
// Align vertex coordinates to the native pixel grid
|
||||
// This ensures text does not get garbled by nearest neighbors scaling
|
||||
pos.x = floor(pos.x * viewport.x + 0.5) / viewport.x;
|
||||
pos.y = floor(pos.y * viewport.y + 0.5) / viewport.y;
|
||||
}
|
||||
|
||||
pos.x = pos.x * 2.0 - 1.0;
|
||||
pos.y = -1.0 * (pos.y * 2.0 - 1.0);
|
||||
|
||||
gl_Position = vec4(pos, 0.0, 1.0);
|
||||
}
|
||||
9
engines/stark/shaders/stark_surface_fill.fragment
Normal file
9
engines/stark/shaders/stark_surface_fill.fragment
Normal file
@@ -0,0 +1,9 @@
|
||||
|
||||
OUTPUT
|
||||
|
||||
uniform float fadeLevel;
|
||||
uniform vec4 color;
|
||||
|
||||
void main() {
|
||||
outColor = color + vec4(fadeLevel, fadeLevel, fadeLevel, 0) * color.a;
|
||||
}
|
||||
23
engines/stark/shaders/stark_surface_fill.vertex
Normal file
23
engines/stark/shaders/stark_surface_fill.vertex
Normal file
@@ -0,0 +1,23 @@
|
||||
in vec2 position;
|
||||
|
||||
uniform vec2 verOffsetXY;
|
||||
uniform vec2 verSizeWH;
|
||||
uniform vec2 viewport;
|
||||
uniform UBOOL snapToGrid;
|
||||
|
||||
void main() {
|
||||
// Coordinates are [0.0; 1.0], transform to [-1.0; 1.0]
|
||||
vec2 pos = verOffsetXY + position * verSizeWH;
|
||||
|
||||
if (UBOOL_TEST(snapToGrid)) {
|
||||
// Align vertex coordinates to the native pixel grid
|
||||
// This ensures text does not get garbled by nearest neighbors scaling
|
||||
pos.x = floor(pos.x * viewport.x + 0.5) / viewport.x;
|
||||
pos.y = floor(pos.y * viewport.y + 0.5) / viewport.y;
|
||||
}
|
||||
|
||||
pos.x = pos.x * 2.0 - 1.0;
|
||||
pos.y = -1.0 * (pos.y * 2.0 - 1.0);
|
||||
|
||||
gl_Position = vec4(pos, 0.0, 1.0);
|
||||
}
|
||||
Reference in New Issue
Block a user