Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

Diff Revisions 167 vs 168 for /trunk/assets/shaders/GLSL/fragmentAtoms/bumpMapping.frag

Diff revisions: vs.
  @@ -1,7 +1,7 @@
1 1
2 2 //Normal or BumpMap
3 - uniform sampler2D texBump;
4 - uniform vec2 zPlanes;
3 + uniform sampler2D texNormalMap;
4 + uniform vec2 dvd_zPlanes;
5 5 uniform float parallax_factor = 1.0f;
6 6 uniform float relief_factor = 1.0f;
7 7 uniform int bumpMapLightId = 0;
  @@ -11,12 +11,12 @@
11 11 #define MODE_PARALLAX 2
12 12 #define MODE_RELIEF 3
13 13
14 + const int num_steps_lin = 10;
15 + const int num_steps_bin = 15;
16 + float linear_step = 1.0 / (float(num_steps_lin));
17 +
14 18 float ReliefMapping_RayIntersection(in vec2 A, in vec2 AB){
15 19
16 - const int num_steps_lin = 10;
17 - const int num_steps_bin = 15;
18 -
19 - float linear_step = 1.0 / (float(num_steps_lin));
20 20 //Current depth position
21 21 float depth = 0.0;
22 22 //Best match found (starts with last position 1.0)
  @@ -25,29 +25,22 @@
25 25 //Search from front to back for first point inside the object
26 26 for(int i=0; i<num_steps_lin-1; i++){
27 27 depth += step;
28 - float h = 1.0 - texture(texBump, A+AB*depth).a;
29 -
30 - if (depth >= h) {
28 + if (depth >= 1.0 - texture(texNormalMap, A+AB*depth).a) {
31 29 best_depth = depth; //Store best depth
32 30 i = num_steps_lin-1;
33 31 }
34 32 }
35 33 //The point of intersection is found between (depth) and (depth-step)
36 34 //so start from (depth - step/2)
37 - step = linear_step/2.0;
35 + step = linear_step * 0.5;
38 36 depth = best_depth - step;
39 37 // binary search
40 - for(int i=0; i<num_steps_bin; i++){
41 -
42 - float h = 1.0 - texture(texBump, A+AB*depth).a;
43 -
44 - step /= 2.0;
45 - if (depth >= h) {
46 - best_depth = depth;
38 + for(int i = 0; i < num_steps_bin; ++i){
39 + step *= 0.5;
40 + best_depth = depth;
41 + if (depth >= 1.0 - texture(texNormalMap, A + AB * depth).a) {
47 42 depth -= step;
48 - }
49 - else {
50 - best_depth = depth;
43 + }else {
51 44 depth += step;
52 45 }
53 46 }
  @@ -56,32 +49,27 @@
56 49
57 50 vec4 NormalMapping(in vec2 uv){
58 51 //Normal mapping in TBN space
59 - vec3 normalTBN = normalize(texture(texBump, uv).xyz * 2.0 - 1.0);
60 - //Lighting
61 - return Phong(uv, normalTBN);
52 + return Phong(uv, normalize(2.0 * texture(texNormalMap, uv).xyz - 1.0));
62 53 }
63 54
64 55 vec4 ParallaxMapping(in vec2 uv, in vec3 pixelToLightTBN){
65 56 vec3 lightVecTBN = normalize(pixelToLightTBN);
66 57 vec3 viewVecTBN = normalize(_viewDirection);
67 58
68 - //Offset, scale and biais
69 - float height = texture(texBump, uv).a;
70 - vec2 vTexCoord = uv + ((height-0.5)* parallax_factor * (vec2(viewVecTBN.x, -viewVecTBN.y)/viewVecTBN.z));
71 -
59 + //Offset, scale and bias
60 + vec2 vTexCoord = uv + ((texture(texNormalMap, uv).a - 0.5) * parallax_factor *
61 + (vec2(viewVecTBN.x, -viewVecTBN.y) / viewVecTBN.z));
62 +
72 63 //Normal mapping in TBN space
73 - vec3 normalTBN = normalize(texture(texBump, vTexCoord).xyz * 2.0 - 1.0);
74 - //Lighting
75 - return Phong(vTexCoord, normalTBN);
64 + return Phong(vTexCoord, normalize(2.0 * texture(texNormalMap, vTexCoord).xyz - 1.0));
76 65 }
77 66
78 67 vec4 ReliefMapping(in int _light, in vec2 uv){
79 68 vec3 viewVecTBN = normalize(_viewDirection);
80 69 //Size and search starting position in texture space
81 - vec2 A = uv;
82 70 vec2 AB = relief_factor * vec2(-viewVecTBN.x, viewVecTBN.y)/viewVecTBN.z;
83 71
84 - float h = ReliefMapping_RayIntersection(A, AB);
72 + float h = ReliefMapping_RayIntersection(uv, AB);
85 73
86 74 vec2 uv_offset = h * AB;
87 75
  @@ -91,10 +79,11 @@
91 79 p += v*h*viewVecTBN.z;
92 80
93 81 vec2 planes;
94 - planes.x = -zPlanes.y/(zPlanes.y-zPlanes.x);
95 - planes.y = -zPlanes.y*zPlanes.x/(zPlanes.y-zPlanes.x);
96 - gl_FragDepth =((planes.x*p.z+planes.y)/-p.z);
82 + planes.x = -dvd_zPlanes.y / (dvd_zPlanes.y - dvd_zPlanes.x);
83 + planes.y = -dvd_zPlanes.y * dvd_zPlanes.x / (dvd_zPlanes.y - dvd_zPlanes.x);
84 +
85 + gl_FragDepth =((planes.x * p.z + planes.y) / -p.z);
97 86
98 - return NormalMapping(uv+uv_offset);
87 + return NormalMapping(uv + uv_offset);
99 88 }
100 89