townforge/GameData/Shaders/GLSL/Armature.glsl

42 lines
1.0 KiB
GLSL

#include "Uniforms.glsl"
#include "Samplers.glsl"
#include "Transform.glsl"
varying vec2 vTexCoord;
varying vec3 vNormal;
uniform float cBottom = 0.2;
uniform float cSideX = 0.4;
uniform float cSideY = 0.5;
uniform float cTop = 1.5;
void VS()
{
mat4 modelMatrix = iModelMatrix;
vec3 worldPos = GetWorldPos(modelMatrix);
gl_Position = GetClipPos(worldPos);
vNormal = GetWorldNormal(modelMatrix);
vTexCoord = GetTexCoord(iTexCoord);
}
void PS()
{
#ifdef DIFFMAP
vec4 diffColor = cMatDiffColor * texture2D(sDiffMap, vTexCoord.xy);
#else
vec4 diffColor = cMatDiffColor;
#endif
vec3 weights=abs(vNormal);
float sum=weights.x + weights.y + weights.z;
weights.x /= sum;
weights.z /= sum;
vec3 armColor = diffColor.rgb * cBottom +
diffColor.rgb * clamp(vNormal.y, 0.0, 1.0) * cTop +
diffColor.rgb * weights.z * cSideX +
diffColor.rgb * weights.x * cSideY;
vec3 finalColor = armColor;
gl_FragColor = vec4(finalColor, diffColor.a);
}