1
0
Fork 0
fgdata/Shaders/ws30.frag

54 lines
1.7 KiB
GLSL
Raw Normal View History

// WS30 FRAGMENT SHADER
// -*-C++-*-
#version 130
#extension GL_EXT_texture_array : enable
varying vec3 normal;
uniform sampler2D landclass;
uniform sampler2DArray atlas;
uniform sampler1D dimensionsArray;
uniform sampler1D diffuseArray;
uniform sampler1D specularArray;
// Passed from VPBTechnique, not the Effect
uniform float tile_width;
uniform float tile_height;
2021-01-23 17:15:12 +00:00
// See include_fog.frag
uniform int fogType;
vec3 fog_Func(vec3 color, int type);
void main()
{
2021-01-23 17:15:12 +00:00
vec3 lightDir = gl_LightSource[0].position.xyz;
vec3 halfVector = gl_LightSource[0].halfVector.xyz;
vec4 texel;
vec4 fragColor;
2021-01-23 17:15:12 +00:00
// The Landclass for this particular fragment. This can be used to
// index into the atlas textures.
int lc = int(texture2D(landclass, gl_TexCoord[0].st).g * 255.0 + 0.5);
// If gl_Color.a == 0, this is a back-facing polygon and the
// normal should be reversed.
2021-01-23 17:15:12 +00:00
vec3 n = (2.0 * gl_Color.a - 1.0) * normal;
n = normalize(n);
2021-01-23 17:15:12 +00:00
float NdotL = dot(n, lightDir);
float NdotHV = max(dot(n, halfVector), 0.0);
// Different textures have different have different dimensions.
// Dimensions array is scaled to fit in [0...1.0] in the texture1D, so has to be scaled back up here.
2021-01-23 17:15:12 +00:00
vec4 color = texture(diffuseArray, float(lc)/512.0) * NdotL;
vec4 specular = texture(specularArray, float(lc)/512.0);
vec2 atlas_dimensions = 10000.0 * texture(dimensionsArray, float(lc)/512.0).st;
vec2 atlas_scale = vec2(tile_width / atlas_dimensions.s, tile_height / atlas_dimensions.t );
texel = texture(atlas, vec3(atlas_scale * gl_TexCoord[0].st, lc));
2021-01-23 17:15:12 +00:00
fragColor = texel + pow(NdotHV, gl_FrontMaterial.shininess) * gl_LightSource[0].specular * specular;
2021-01-23 17:15:12 +00:00
fragColor.rgb = fog_Func(fragColor.rgb, fogType);
gl_FragColor = fragColor;
}