Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/branches/Shader_HS18/programs/Example/GLSLES/OffsetMapping_specular.glsles @ 12091

Last change on this file since 12091 was 12091, checked in by wiesep, 5 years ago

Updated programs and adjusted Material to work with GLSL>150

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