Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/data_extern/programs/GLSL120/Instancing.frag @ 12187

Last change on this file since 12187 was 12115, checked in by wiesep, 6 years ago

Changed folder structure, deletet some unused files and cleaned up code

File size: 1.9 KB
Line 
1//---------------------------------------------------------------------------
2//These materials/shaders are part of the NEW InstanceManager implementation
3//Written by Matias N. Goldberg ("dark_sylinc")
4//---------------------------------------------------------------------------
5
6uniform sampler2D diffuseMap;
7
8uniform vec4    lightPosition;
9uniform vec3    cameraPosition;
10uniform vec3    lightAmbient;
11uniform vec3    lightDiffuse;
12uniform vec3    lightSpecular;
13uniform vec4    lightAttenuation;
14uniform float   lightGloss;
15
16#if DEPTH_SHADOWRECEIVER
17uniform float invShadowMapSize;
18uniform sampler2DShadow shadowMap;
19
20//declare external function
21//vec4 calcDepthShadow(in vec4 inColour, in float lum);
22float calcDepthShadow(sampler2DShadow shadowMap, vec4 uv, float invShadowMapSize);
23#endif
24
25varying vec2 _uv0;
26varying vec3 oNormal;
27varying vec3 oVPos;
28#if DEPTH_SHADOWRECEIVER
29        varying vec4 oLightSpacePos;
30#endif
31
32//---------------------------------------------
33//Main Pixel Shader
34//---------------------------------------------
35void 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}
Note: See TracBrowser for help on using the repository browser.