ho3/resources/shaders/NIU/multilight_parallax.fragment
Vladislav Khorev d132060e19 Resurrection
2024-06-06 16:25:38 +03:00

54 lines
1.3 KiB
Plaintext

uniform sampler2D Texture;
uniform sampler2D NormalMap;
uniform int NormalMapExists;
varying vec2 texCoord;
varying int activeLightCount;
varying vec3 camVec;
varying vec3 lightVec[8];
void main()
{
vec3 lVec;
vec3 cVec = normalize(camVec);
float parallax = 0.035;
//double refinement
float height = texture2D(NormalMap, texCoord.xy).a;
float offset = parallax * (2.0 * height - 1.0);
vec2 parallaxTexCoord = texCoord.xy + offset * cVec.xy;
height += texture2D(NormalMap, parallaxTexCoord).a;
offset = parallax * (height - 1.0);
parallaxTexCoord = texCoord.xy + offset * cVec.xy;
//go-go-go
vec3 TexRGB = texture2D(Texture, parallaxTexCoord).xyz;
vec3 norm;
if (NormalMapExists == 0)
{
norm = vec3(0.0,0.0,1.0);
}
else
{
norm = texture2D(NormalMap, parallaxTexCoord).xyz * 2.0 - 1.0;
}
float shineFactor = 15.0 * pow(max(dot(cVec, norm),0.0),gl_FrontMaterial.shininess) / (129.0 - gl_FrontMaterial.shininess);
gl_FragColor = vec4(0.0,0.0,0.0,1.0);
for (int i=0;i<activeLightCount;i++)
{
vec3 lVec = normalize(lightVec[i]);
vec4 ambient = gl_LightSource[i].ambient;
vec4 diffuse = gl_FrontMaterial.diffuse * gl_LightSource[i].diffuse * max( dot(lVec,norm),0.0);
vec4 specular = gl_LightSource[i].specular * shineFactor;
gl_FragColor += vec4(TexRGB,1.0)*ambient+(vec4(TexRGB,1.0)*diffuse+specular);
}
}