Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/branches/Shader_HS18/programs/Example/GLSL150/Instancing.frag @ 12083

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

Reorganised shader programs

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