1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-26 09:35:28 +00:00
OpenMW/files/shaders/objects_fragment.glsl

96 lines
1.9 KiB
Plaintext
Raw Normal View History

#version 120
#if @diffuseMap
uniform sampler2D diffuseMap;
varying vec2 diffuseMapUV;
#endif
#if @darkMap
uniform sampler2D darkMap;
varying vec2 darkMapUV;
#endif
#if @detailMap
uniform sampler2D detailMap;
varying vec2 detailMapUV;
#endif
#if @emissiveMap
uniform sampler2D emissiveMap;
varying vec2 emissiveMapUV;
#endif
2016-02-18 00:00:12 +01:00
#if @normalMap
uniform sampler2D normalMap;
varying vec2 normalMapUV;
varying vec3 viewTangent;
#endif
2016-02-18 23:05:44 +01:00
#if @envMap
uniform sampler2D envMap;
varying vec2 envMapUV;
uniform vec4 envMapColor;
#endif
2016-02-16 22:32:59 +01:00
varying float depth;
2016-02-18 17:08:18 +01:00
#define PER_PIXEL_LIGHTING (@normalMap || @forcePPL)
2016-02-17 23:39:06 +01:00
#if !PER_PIXEL_LIGHTING
varying vec4 lighting;
2016-02-17 23:39:06 +01:00
#else
varying vec3 passViewPos;
varying vec3 passViewNormal;
2016-02-18 23:05:44 +01:00
varying vec4 passColor;
2016-02-17 23:39:06 +01:00
#endif
#include "lighting.glsl"
2016-02-16 23:30:23 +01:00
void main()
{
#if @diffuseMap
gl_FragData[0] = texture2D(diffuseMap, diffuseMapUV);
#else
2016-02-16 22:32:59 +01:00
gl_FragData[0] = vec4(1.0, 1.0, 1.0, 1.0);
#endif
2016-02-16 22:32:59 +01:00
#if @detailMap
gl_FragData[0].xyz *= texture2D(detailMap, detailMapUV).xyz * 2.0;
#endif
#if @darkMap
gl_FragData[0].xyz *= texture2D(darkMap, darkMapUV).xyz;
#endif
2016-02-18 17:08:18 +01:00
#if PER_PIXEL_LIGHTING
2016-02-18 00:00:12 +01:00
vec3 viewNormal = passViewNormal;
2016-02-18 17:08:18 +01:00
#endif
#if @normalMap
2016-02-18 00:00:12 +01:00
vec3 normalTex = texture2D(normalMap, normalMapUV).xyz;
vec3 viewBinormal = cross(viewTangent, viewNormal);
mat3 tbn = mat3(viewTangent, viewBinormal, viewNormal);
viewNormal = normalize(tbn * (normalTex * 2.0 - 1.0));
#endif
2016-02-17 23:39:06 +01:00
#if !PER_PIXEL_LIGHTING
gl_FragData[0] *= lighting;
2016-02-17 23:39:06 +01:00
#else
2016-02-18 23:05:44 +01:00
gl_FragData[0] *= doLighting(passViewPos, normalize(viewNormal), passColor);
2016-02-17 23:39:06 +01:00
#endif
2016-02-16 23:30:23 +01:00
#if @emissiveMap
gl_FragData[0].xyz += texture2D(emissiveMap, emissiveMapUV).xyz;
#endif
2016-02-18 23:05:44 +01:00
#if @envMap
gl_FragData[0].xyz += texture2D(envMap, envMapUV).xyz * envMapColor.xyz;
#endif
2016-02-16 22:32:59 +01:00
float fogValue = clamp((depth - gl_Fog.start) * gl_Fog.scale, 0.0, 1.0);
gl_FragData[0].xyz = mix(gl_FragData[0].xyz, gl_Fog.color.xyz, fogValue);
}