1 | //--------------------------------------------------------------------------- |
---|
2 | //These materials/shaders are part of the NEW InstanceManager implementation |
---|
3 | //Written by Matias N. Goldberg ("dark_sylinc") |
---|
4 | //--------------------------------------------------------------------------- |
---|
5 | |
---|
6 | uniform sampler2D diffuseMap; |
---|
7 | |
---|
8 | uniform vec4 lightPosition; |
---|
9 | uniform vec3 cameraPosition; |
---|
10 | uniform vec3 lightAmbient; |
---|
11 | uniform vec3 lightDiffuse; |
---|
12 | uniform vec3 lightSpecular; |
---|
13 | uniform vec4 lightAttenuation; |
---|
14 | uniform float lightGloss; |
---|
15 | |
---|
16 | #if DEPTH_SHADOWRECEIVER |
---|
17 | uniform float invShadowMapSize; |
---|
18 | uniform sampler2DShadow shadowMap; |
---|
19 | |
---|
20 | //declare external function |
---|
21 | //vec4 calcDepthShadow(in vec4 inColour, in float lum); |
---|
22 | float calcDepthShadow(sampler2DShadow shadowMap, vec4 uv, float invShadowMapSize); |
---|
23 | #endif |
---|
24 | |
---|
25 | varying vec2 _uv0; |
---|
26 | varying vec3 oNormal; |
---|
27 | varying vec3 oVPos; |
---|
28 | #if DEPTH_SHADOWRECEIVER |
---|
29 | varying vec4 oLightSpacePos; |
---|
30 | #endif |
---|
31 | |
---|
32 | //--------------------------------------------- |
---|
33 | //Main Pixel Shader |
---|
34 | //--------------------------------------------- |
---|
35 | void main(void) |
---|
36 | { |
---|
37 | vec4 color = texture2D( diffuseMap, _uv0 ); |
---|
38 | |
---|
39 | float fShadow = 1.0; |
---|
40 | #if DEPTH_SHADOWRECEIVER |
---|
41 | fShadow = calcDepthShadow( shadowMap, oLightSpacePos, invShadowMapSize ); |
---|
42 | #endif |
---|
43 | |
---|
44 | vec4 baseColour = texture2D( diffuseMap, _uv0 ); |
---|
45 | |
---|
46 | //Blinn-Phong lighting |
---|
47 | vec3 normal = normalize( oNormal ); |
---|
48 | vec3 lightDir = lightPosition.xyz - oVPos * lightPosition.w; |
---|
49 | vec3 eyeDir = normalize( cameraPosition - oVPos ); |
---|
50 | |
---|
51 | float fLength = length( lightDir ); |
---|
52 | lightDir = normalize( lightDir ); |
---|
53 | |
---|
54 | float NdotL = max( 0.0, dot( normal, lightDir ) ); |
---|
55 | vec3 halfVector = normalize(lightDir + eyeDir); |
---|
56 | float HdotN = max( 0.0, dot( halfVector, normal ) ); |
---|
57 | |
---|
58 | vec3 ambient = lightAmbient * baseColour.xyz; |
---|
59 | vec3 diffuse = lightDiffuse * NdotL * baseColour.xyz; |
---|
60 | vec3 specular = lightSpecular * pow( HdotN, lightGloss ); |
---|
61 | |
---|
62 | vec3 directLighting = (diffuse + specular) * fShadow; |
---|
63 | |
---|
64 | gl_FragColor = vec4( directLighting + ambient, baseColour.a ); |
---|
65 | //gl_FragColor = baseColour; |
---|
66 | } |
---|