vkQuake2 doxygen  1.0 dev
r_dither.h
Go to the documentation of this file.
1 #ifndef __R_DITHER__
2 #define __R_DITHER__
3 /*
4 Copyright (C) 2012 Szilard Biro
5 
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
10 
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 
15 See the GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 
21 */
22 
23 /*
24 
25 http://www.flipcode.com/archives/Texturing_As_In_Unreal.shtml
26 
27  (X&1)==0 (X&1==1)
28  +---------------------------------
29 (Y&1)==0 | u+=.25,v+=.00 u+=.50,v+=.75
30 (Y&1)==1 | u+=.75,v+=.50 u+=.00,v+=.25
31 
32 */
33 
34 #if 1
35 
36 #define DitherKernel2(u, v, X, Y) \
37  if ((Y)&1) { \
38  if ((X)&1) { \
39  (u) = (u) + (32768); \
40  (v) = (v) + (49152); \
41  } else { \
42  (u) = (u) + (16384); \
43  } \
44  } else { \
45  if ((X)&1) { \
46  (v) = (v) + (32768); \
47  } else { \
48  (u) = (u) + (49152); \
49  (v) = (v) + (16384); \
50  } \
51  }
52 
53 #else
54 
55 #define DitherKernel2(u, v, X, Y) \
56  if ((Y)&1) { \
57  if ((X)&1) { \
58  (u) = (u) + (65536 * 0.50); /* 50 */ \
59  (v) = (v) + (65536 * 0.75); /* 75 */ \
60  } else { \
61  (u) = (u) + (65536 * 0.25); /* 25 */ \
62  (v) = (v) + (65536 * 0.0); /* 00 */ \
63  } \
64  } else { \
65  if ((X)&1) { \
66  (u) = (u) + (65536 * 0.0); /* 00 */ \
67  (v) = (v) + (65536 * 0.5); /* 25 */ \
68  } else { \
69  (u) = (u) + (65536 * 0.75); /* 75 */ \
70  (v) = (v) + (65536 * 0.25); /* 50 */ \
71  } \
72  }
73 
74 #endif
75 
76 #endif