Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/branches/Shader_HS18/programs/Cg/Instancing_ps.cg @ 12181

Last change on this file since 12181 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
6#include "InstancingVertexInterpolators.cg"
7
8#include "shadows.cg"
9
10//---------------------------------------------
11//Main Pixel Shader
12//---------------------------------------------
13half4 main_ps( PS_INPUT input ,
14                                uniform float4  lightPosition,
15                                uniform float3  cameraPosition,
16                                uniform half3   lightAmbient,
17                                uniform half3   lightDiffuse,
18                                uniform half3   lightSpecular,
19                                uniform half4   lightAttenuation,
20                                uniform half    lightGloss,
21
22                                //Textures
23                                uniform sampler2D diffuseMap : register(s0)
24
25#ifdef DEPTH_SHADOWRECEIVER
26                        ,       uniform float invShadowMapSize,
27                                uniform sampler2D shadowMap : register(s1)
28#endif
29                        ) : COLOR0
30{
31        float fShadow = 1.0f;
32#ifdef DEPTH_SHADOWRECEIVER
33        fShadow = calcDepthShadow( shadowMap, input.lightSpacePos, invShadowMapSize );
34#endif
35
36        const half4 baseColour = tex2D( diffuseMap, input.uv0 );
37       
38        //Blinn-Phong lighting
39        const half3 normal              = normalize( input.Normal );
40        half3 lightDir                  = lightPosition.xyz - input.vPos * lightPosition.w;
41        half3 eyeDir                    = normalize( cameraPosition - input.vPos  );
42
43        const half fLength              = length( lightDir );
44        lightDir                                = normalize( lightDir );
45
46        const half NdotL = max( 0.0f, dot( normal, lightDir ) );
47        half3 halfVector = normalize(lightDir + eyeDir);
48        const half HdotN = max( 0.0f, dot( halfVector, normal ) );
49       
50        const half3 ambient  = lightAmbient * baseColour.xyz;
51        const half3 diffuse  = lightDiffuse * NdotL * baseColour.xyz;
52        const half3 specular = lightSpecular * pow( HdotN, lightGloss );
53       
54        const half3 directLighting = (diffuse + specular) * fShadow;
55       
56        return half4( directLighting + ambient, baseColour.a );
57}
Note: See TracBrowser for help on using the repository browser.