2 #define OSG_HAS_DIFFUSE_MAP 1
4 #ifdef OSG_HAS_DIFFUSE_MAP
5 uniform sampler2D diffuseMap;
7 #ifdef OSG_HAS_NORMAL_MAP
8 uniform sampler2D normalMap;
10 #ifdef OSG_HAS_SPECULAR_MAP
11 uniform sampler2D specularMap;
15 varying vec3 vertNorm;
17 #ifdef OSG_HAS_NORMAL_MAP
18 varying vec3 vertTangent;
21 uniform int OSGLight0Active;
22 uniform int OSGLight1Active;
23 uniform int OSGLight2Active;
24 uniform int OSGLight3Active;
26 #ifdef OSG_HAS_SPECULAR_MAP
27 vec4 calcLight(int idx, vec3 normal, vec4 matDiff, float matSpec)
29 vec4 color = vec4(0., 0., 0., 0.);
30 float NdotL = max(dot(normal, gl_LightSource[idx].position.xyz), 0.);
34 color += NdotL * matDiff * gl_LightSource[idx].diffuse;
36 float NdotH = max(dot(normal, gl_LightSource[idx].halfVector.xyz), 0.);
40 color += matSpec * pow(NdotH, 20.) * gl_LightSource[idx].specular;
47 vec4 calcLight(int idx, vec3 normal, vec4 matDiff)
49 vec4 color = vec4(0., 0., 0., 0.);
50 float NdotL = max(dot(normal, gl_LightSource[idx].position.xyz), 0.);
54 color += NdotL * matDiff * gl_LightSource[idx].diffuse;
63 vec3 pos = vertPos.xyz / vertPos.w;
65 #ifdef OSG_HAS_DIFFUSE_MAP
66 vec4 diffCol = texture2D(diffuseMap, gl_TexCoord[0].xy);
68 vec4 diffCol = gl_FrontMaterial.diffuse;
71 #ifdef OSG_HAS_ALPHA_TEST
78 #ifdef OSG_HAS_NORMAL_MAP
79 vec3 texNormal = texture2D(normalMap, gl_TexCoord[0].xy).xyz * 2.0 - 1.0;
81 vec3 vNormal = normalize(vertNorm);
82 vec3 vTangent = normalize(vertTangent);
83 vec3 vBitangent = cross(vNormal, vTangent);
85 mat3 matTangentSpace = mat3(vTangent, vBitangent, vNormal);
86 vec3 normal = normalize(matTangentSpace * texNormal);
88 vec3 normal = normalize(vertNorm);
91 #ifdef OSG_HAS_SPECULAR_MAP
92 vec3 specular = texture2D(specularMap, gl_TexCoord[0].xy).rgb;
93 float luminance = dot(specular, vec3(0.212671,
98 gl_FragColor = vec4(0., 0., 0., 0.);
100 #ifdef OSG_HAS_SPECULAR_MAP
101 if(OSGLight0Active > 0)
102 gl_FragColor += calcLight(0, normal, diffCol, luminance);
103 if(OSGLight1Active > 0)
104 gl_FragColor += calcLight(1, normal, diffCol, luminance);
105 if(OSGLight2Active > 0)
106 gl_FragColor += calcLight(2, normal, diffCol, luminance);
107 if(OSGLight3Active > 0)
108 gl_FragColor += calcLight(3, normal, diffCol, luminance);
110 if(OSGLight0Active > 0)
111 gl_FragColor += calcLight(0, normal, diffCol);
112 if(OSGLight1Active > 0)
113 gl_FragColor += calcLight(1, normal, diffCol);
114 if(OSGLight2Active > 0)
115 gl_FragColor += calcLight(2, normal, diffCol);
116 if(OSGLight3Active > 0)
117 gl_FragColor += calcLight(3, normal, diffCol);