MCPcopy Create free account
hub / github.com/dhewm/dhewm3 / R_SmoothNormalMap

Function R_SmoothNormalMap

neo/renderer/Image_program.cpp:249–294  ·  view source on GitHub ↗

================ R_SmoothNormalMap ================ */

Source from the content-addressed store, hash-verified

247================
248*/
249static void R_SmoothNormalMap( byte *data, int width, int height ) {
250 byte *orig;
251 int i, j, k, l;
252 idVec3 normal;
253 byte *out;
254 static float factors[3][3] = {
255 { 1, 1, 1 },
256 { 1, 1, 1 },
257 { 1, 1, 1 }
258 };
259
260 orig = (byte *)R_StaticAlloc( width * height * 4 );
261 memcpy( orig, data, width * height * 4 );
262
263 for ( i = 0 ; i < width ; i++ ) {
264 for ( j = 0 ; j < height ; j++ ) {
265 normal = vec3_origin;
266 for ( k = -1 ; k < 2 ; k++ ) {
267 for ( l = -1 ; l < 2 ; l++ ) {
268 byte *in;
269
270 in = orig + ( ((j+l)&(height-1))*width + ((i+k)&(width-1)) ) * 4;
271
272 // ignore 000 and -1 -1 -1
273 if ( in[0] == 0 && in[1] == 0 && in[2] == 0 ) {
274 continue;
275 }
276 if ( in[0] == 128 && in[1] == 128 && in[2] == 128 ) {
277 continue;
278 }
279
280 normal[0] += factors[k+1][l+1] * ( in[0] - 128 );
281 normal[1] += factors[k+1][l+1] * ( in[1] - 128 );
282 normal[2] += factors[k+1][l+1] * ( in[2] - 128 );
283 }
284 }
285 normal.Normalize();
286 out = data + ( j * width + i ) * 4;
287 out[0] = (byte)(128 + 127 * normal[0]);
288 out[1] = (byte)(128 + 127 * normal[1]);
289 out[2] = (byte)(128 + 127 * normal[2]);
290 }
291 }
292
293 R_StaticFree( orig );
294}
295
296
297/*

Callers 1

R_ParseImageProgram_rFunction · 0.85

Calls 3

R_StaticAllocFunction · 0.85
R_StaticFreeFunction · 0.85
NormalizeMethod · 0.45

Tested by

no test coverage detected