Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/branches/Shader_HS18/programs/Example/GLSLES/OffsetMappingShadowsFp.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: 2.1 KB
Line 
1#version 100
2precision mediump int;
3precision mediump float;
4
5uniform vec4 lightDiffuse;
6uniform vec4 scaleBias;
7uniform vec4 spotParams;
8uniform vec4 lightDiffuse1;
9uniform vec4 spotParams1;
10
11uniform sampler2D normalHeightMap;
12uniform sampler2D diffuseMap;
13uniform sampler2D shadowMap1;
14uniform sampler2D shadowMap2;
15
16varying vec3 tangentEyeDir;
17varying vec3 tangentLightDir[2];
18varying vec3 tangentSpotDir[2];
19varying vec4 shadowUV[2];
20varying vec4 oUv0;
21
22// Expand a range-compressed vector
23vec3 expand(vec3 v)
24{
25        return (v - 0.5) * 2.0;
26}
27
28void main()
29{
30        // get the height using the tex coords
31        float height = texture2D(normalHeightMap, oUv0.xy).a;
32        // scale and bias factors       
33        float scale = scaleBias.x;
34        float bias = scaleBias.y;
35
36        // calculate displacement       
37        float displacement = (height * scale) + bias;
38        //float displacement = (height * 0.04) - 0.02;
39       
40        vec3 scaledEyeDir = tangentEyeDir * displacement;
41       
42        // calculate the new tex coord to use for normal and diffuse
43        vec2 newTexCoord = (scaledEyeDir + oUv0.xyz).xy;
44       
45        // get the new normal and diffuse values
46        vec3 normal = expand(texture2D(normalHeightMap, newTexCoord).xyz);
47        vec4 diffuse = texture2D(diffuseMap, newTexCoord);
48       
49        vec4 col1 = diffuse * clamp(dot(normal, tangentLightDir[0]),0.0,1.0) * lightDiffuse;
50        // factor in spotlight angle
51        float rho = clamp(dot(tangentSpotDir[0], tangentLightDir[0]),0.0,1.0);
52        // factor = (rho - cos(outer/2) / cos(inner/2) - cos(outer/2)) ^ falloff
53        float spotFactor = pow(
54                clamp(rho - spotParams.y,0.0,1.0) / (spotParams.x - spotParams.y), spotParams.z);
55        col1 = col1 * spotFactor;
56        vec4 col2 = diffuse * clamp(dot(normal, tangentLightDir[1]),0.0,1.0) * lightDiffuse1;
57        // factor in spotlight angle
58        rho = clamp(dot(tangentSpotDir[1], tangentLightDir[1]),0.0,1.0);
59        // factor = (rho - cos(outer/2) / cos(inner/2) - cos(outer/2)) ^ falloff
60        spotFactor = pow(
61                clamp(rho - spotParams1.y,0.0,1.0) / (spotParams1.x - spotParams1.y), spotParams1.z);
62        col2 = col2 * spotFactor;
63
64        // shadow textures
65        col1 = col1 * texture2DProj(shadowMap1, shadowUV[0]);
66        col2 = col2 * texture2DProj(shadowMap2, shadowUV[1]);
67
68        gl_FragColor = col1 + col2;
69
70}
Note: See TracBrowser for help on using the repository browser.