Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/branches/Shader_HS18/programs/Example/GLSL150/OffsetMapping_specular.glsl @ 12083

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

Reorganised shader programs

File size: 1.2 KB
Line 
1#version 150
2
3uniform vec4 lightDiffuse;
4uniform vec4 lightSpecular;
5uniform vec4 scaleBias;
6uniform float exponent;
7uniform sampler2D normalHeightMap;
8
9in vec3 tangentEyeDir;
10in vec3 tangentLightDir[2];
11in vec4 shadowUV[2];
12in vec4 oUv0;
13
14out vec4 fragColour;
15
16vec4 lit(float NdotL, float NdotH, float m) {
17
18  float ambient = 1.0;
19  float diffuse = max(NdotL, 0.0);
20  float specular = step(0.0, NdotL) * max(NdotH * m, 0.0);
21
22  return vec4(ambient, diffuse, specular, 1.0);
23}
24
25vec3 expand(vec3 v)
26{
27        return (v - 0.5) * 2.0;
28}
29
30/*
31  Pixel Shader for doing bump mapping with parallax plus diffuse and specular lighting by masterfalcon
32*/
33void main()
34{
35        float height = texture(normalHeightMap, oUv0.xy).a;
36        float displacement = (height * scaleBias.x) + scaleBias.y;
37        vec2 newTexCoord = ((tangentEyeDir * displacement) + oUv0.xyz).xy;
38        vec3 bumpVec = expand(texture(normalHeightMap, newTexCoord).xyz);
39        vec3 N = normalize(bumpVec);
40
41        vec3 halfAngle = normalize(tangentEyeDir + tangentLightDir[0]); 
42        float NdotL = dot(normalize(tangentLightDir[0]), N);
43        float NdotH = dot(normalize(halfAngle), N); 
44
45        vec4 Lit = lit(NdotL, NdotH, exponent);
46       
47        fragColour = lightDiffuse * Lit.y + lightSpecular * Lit.z;
48}
Note: See TracBrowser for help on using the repository browser.