mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-03-23 10:20:48 +00:00
Add normal map code
This commit is contained in:
parent
18e80d5627
commit
e5a37a7023
@ -20,9 +20,15 @@ uniform sampler2D emissiveMap;
|
||||
varying vec2 emissiveMapUV;
|
||||
#endif
|
||||
|
||||
#if @normalMap
|
||||
uniform sampler2D normalMap;
|
||||
varying vec2 normalMapUV;
|
||||
varying vec3 viewTangent;
|
||||
#endif
|
||||
|
||||
varying float depth;
|
||||
|
||||
#define PER_PIXEL_LIGHTING 0
|
||||
#define PER_PIXEL_LIGHTING @normalMap
|
||||
|
||||
#if !PER_PIXEL_LIGHTING
|
||||
varying vec4 lighting;
|
||||
@ -50,11 +56,21 @@ void main()
|
||||
gl_FragData[0].xyz *= texture2D(darkMap, darkMapUV).xyz;
|
||||
#endif
|
||||
|
||||
#if @normalMap
|
||||
vec3 viewNormal = passViewNormal;
|
||||
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
|
||||
|
||||
|
||||
#if !PER_PIXEL_LIGHTING
|
||||
gl_FragData[0] *= lighting;
|
||||
#else
|
||||
gl_FragData[0] *= doLighting(passViewPos, passViewNormal, passColour);
|
||||
gl_FragData[0] *= doLighting(passViewPos, normalize(viewNormal), passColour);
|
||||
#endif
|
||||
|
||||
#if @emissiveMap
|
||||
|
@ -16,9 +16,14 @@ varying vec2 detailMapUV;
|
||||
varying vec2 emissiveMapUV;
|
||||
#endif
|
||||
|
||||
#if @normalMap
|
||||
varying vec2 normalMapUV;
|
||||
varying vec3 viewTangent;
|
||||
#endif
|
||||
|
||||
varying float depth;
|
||||
|
||||
#define PER_PIXEL_LIGHTING 0
|
||||
#define PER_PIXEL_LIGHTING @normalMap
|
||||
|
||||
#if !PER_PIXEL_LIGHTING
|
||||
varying vec4 lighting;
|
||||
@ -55,6 +60,11 @@ void main(void)
|
||||
emissiveMapUV = (gl_TextureMatrix[@emissiveMapUV] * gl_MultiTexCoord@emissiveMapUV).xy;
|
||||
#endif
|
||||
|
||||
#if @normalMap
|
||||
normalMapUV = (gl_TextureMatrix[@normalMapUV] * gl_MultiTexCoord@normalMapUV).xy;
|
||||
viewTangent = normalize(gl_NormalMatrix * gl_MultiTexCoord7.xyz);
|
||||
#endif
|
||||
|
||||
#if !PER_PIXEL_LIGHTING
|
||||
lighting = doLighting(viewPos.xyz, viewNormal, gl_Color);
|
||||
#else
|
||||
|
Loading…
x
Reference in New Issue
Block a user