Subversion Repository Public Repository

Divide-Framework

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

Diff Revisions 886 vs 887 for /trunk/assets/shaders/GLSL/fragmentAtoms/bumpMapping.frag

Diff revisions: vs.
  @@ -98,6 +98,47 @@
98 98 return getPixelColour(uv + uv_offset, getTBNMatrix() * getBump(uv + uv_offset));
99 99 }
100 100
101 + // http://www.thetenthplanet.de/archives/1180
102 + mat3 cotangent_frame(vec3 N, vec3 p, vec2 uv)
103 + {
104 + // get edge vectors of the pixel triangle
105 + vec3 dp1 = dFdx(p);
106 + vec3 dp2 = dFdy(p);
107 + vec2 duv1 = dFdx(uv);
108 + vec2 duv2 = dFdy(uv);
109 +
110 + // solve the linear system
111 + vec3 dp2perp = cross(dp2, N);
112 + vec3 dp1perp = cross(N, dp1);
113 + vec3 T = dp2perp * duv1.x + dp1perp * duv2.x;
114 + vec3 B = dp2perp * duv1.y + dp1perp * duv2.y;
115 +
116 + // construct a scale-invariant frame
117 + float invmax = inversesqrt(max(dot(T, T), dot(B, B)));
118 + return mat3(T * invmax, B * invmax, N);
119 + }
120 +
121 + vec3 perturb_normal(vec3 texNorm, vec3 N, vec3 V, vec2 texcoord)
122 + {
123 + // assume N, the interpolated vertex normal and
124 + // V, the view vector (vertex to eye)
125 + texNorm = texNorm * 255. / 127. - 128. / 127.;
126 + mat3 TBN = cotangent_frame(N, -V, texcoord);
127 + return normalize(TBN * texNorm);
128 + }
129 +
130 +
131 + void aproximateTBN(in vec3 normalWV, out vec3 tangent, out vec3 bitangent) {
132 + vec3 c1 = cross(normalWV, vec3(0.0, 0.0, 1.0));
133 + vec3 c2 = cross(normalWV, vec3(0.0, 1.0, 0.0));
134 + if (length(c1) > length(c2)) {
135 + tangent = c1;
136 + } else {
137 + tangent = c2;
138 + }
139 + tangent = normalize(tangent);
140 + bitangent = normalize(cross(normalWV, tangent));
141 + }
101 142 /*---------------- Normal blending -----------------*/
102 143 //ref: http://blog.selfshadow.com/sandbox/normals.html
103 144