1#import "Common/ShaderLib/Optics.glsllib" 2 3uniform float m_Shininess; 4 5varying vec2 texCoord; 6varying vec4 AmbientSum; 7varying vec4 DiffuseSum; 8varying vec4 SpecularSum; 9 10varying float vDepth; 11varying vec3 vNormal; 12 13#ifdef DIFFUSEMAP 14 uniform sampler2D m_DiffuseMap; 15#endif 16 17#ifdef SPECULARMAP 18 uniform sampler2D m_SpecularMap; 19#endif 20 21#ifdef PARALLAXMAP 22 uniform sampler2D m_ParallaxMap; 23#endif 24 25#ifdef NORMALMAP 26 uniform sampler2D m_NormalMap; 27 varying mat3 tbnMat; 28#endif 29 30vec2 encodeNormal(in vec3 n){ 31 vec2 enc = normalize(n.xy) * (sqrt(-n.z*0.5+0.5)); 32 enc = enc*vec2(0.5)+vec2(0.5); 33 return enc; 34} 35 36void main(){ 37 vec2 newTexCoord = texCoord; 38 float height = 0.0; 39 #if defined(PARALLAXMAP) || defined(NORMALMAP_PARALLAX) 40 #ifdef PARALLAXMAP 41 height = texture2D(m_ParallaxMap, texCoord).r; 42 #else 43 height = texture2D(m_NormalMap, texCoord).a; 44 #endif 45 float heightScale = 0.05; 46 float heightBias = heightScale * -0.5; 47 height = (height * heightScale + heightBias); 48 #endif 49 50 51 // *********************** 52 // Read from textures 53 // *********************** 54 #if defined(NORMALMAP) && !defined(VERTEX_LIGHTING) 55 vec4 normalHeight = texture2D(m_NormalMap, newTexCoord); 56 vec3 normal = (normalHeight.xyz * vec3(2.0) - vec3(1.0)); 57 normal.y = -normal.y; 58 59 normal = tbnMat * normal; 60 #else 61 vec3 normal = vNormal; 62 #if !defined(LOW_QUALITY) && !defined(V_TANGENT) 63 normal = normalize(normal); 64 #endif 65 #endif 66 67 #ifdef DIFFUSEMAP 68 vec4 diffuseColor = texture2D(m_DiffuseMap, newTexCoord); 69 #else 70 vec4 diffuseColor = vec4(1.0); 71 #endif 72 73 #ifdef SPECULARMAP 74 vec4 specularColor = texture2D(m_SpecularMap, newTexCoord); 75 #else 76 vec4 specularColor = vec4(1.0); 77 #endif 78 79 diffuseColor.rgb *= DiffuseSum.rgb; 80 specularColor.rgb *= SpecularSum.rgb; 81 82 gl_FragData[0] = vec4(diffuseColor.rgb, 1.0); 83 gl_FragData[1] = vec4(encodeNormal(normal), 0.0, 0.0); 84 /*encodeNormal(vNormal));*/ 85 gl_FragData[2] = vec4(specularColor.rgb, m_Shininess / 128.0); 86} 87