Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/branches/Shader_HS18/programs/GLSL120/OffsetMapping_specular.glsl @ 12373

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

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

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