#
source:
src/materials/_normalisationCubemap.pym
@
1241:537ca1099be0

Revision 1241:537ca1099be0, 5.0 KB checked in by Arc Riley <arcriley@…>, 6 years ago (diff) |
---|

Line | |
---|---|

1 | # PySoy's materials._normalisationCubemap function |

2 | # |

3 | # Copyright (C) 2006,2007,2008 PySoy Group |

4 | # |

5 | # This program is free software; you can redistribute it and/or modify |

6 | # it under the terms of the GNU Affero General Public License as published |

7 | # by the Free Software Foundation, either version 3 of the License, or |

8 | # (at your option) any later version. |

9 | # |

10 | # This program is distributed in the hope that it will be useful, |

11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |

12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |

13 | # GNU Affero General Public License for more details. |

14 | # |

15 | # You should have received a copy of the GNU Affero General Public License |

16 | # along with this program; if not, see http://www.gnu.org/licenses |

17 | # |

18 | # $Id: _normalisationCubemap.pym 1287 2008-05-20 05:17:04Z ArcRiley $ |

19 | |

20 | cimport stdlib |

21 | cimport soy.textures |

22 | |

23 | cdef void _normalisationCubemap(soy.textures.Texture _cubemap) : |

24 | cdef int _i, _j |

25 | cdef float _length |

26 | cdef float _vector[3] |

27 | cdef unsigned char* _ptr |

28 | |

29 | _cubemap._resize(1, 3, 32, 32, 6) |

30 | _ptr = _cubemap._texels |

31 | |

32 | # +X |

33 | for _j from 0 < _j <= 32: |

34 | for _i from 0 < _i <= 32: |

35 | _vector[0] = 16.0 |

36 | _vector[1] = -(_j + 0.5 - 16.0) |

37 | _vector[2] = -(_i + 0.5 - 16.0) |

38 | |

39 | _length = stdlib.sqrtf( _vector[0] * _vector[0] + |

40 | _vector[1] * _vector[1] + |

41 | _vector[2] * _vector[2] ) |

42 | |

43 | _vector[0] = 0.5 * (_vector[0] / _length) + 0.5 |

44 | _vector[1] = 0.5 * (_vector[1] / _length) + 0.5 |

45 | _vector[2] = 0.5 * (_vector[2] / _length) + 0.5 |

46 | |

47 | _ptr[0] = <unsigned char> (_vector[0] * 255) |

48 | _ptr[1] = <unsigned char> (_vector[1] * 255) |

49 | _ptr[2] = <unsigned char> (_vector[2] * 255) |

50 | _ptr = _ptr + 3 |

51 | |

52 | |

53 | # -X |

54 | for _j from 0 < _j <= 32: |

55 | for _i from 0 < _i <= 32: |

56 | _vector[0] = -16.0 |

57 | _vector[1] = -(_j + 0.5 - 16.0) |

58 | _vector[2] = (_i + 0.5 - 16.0) |

59 | |

60 | _length = stdlib.sqrtf( _vector[0] * _vector[0] + |

61 | _vector[1] * _vector[1] + |

62 | _vector[2] * _vector[2] ) |

63 | |

64 | _vector[0] = 0.5 * (_vector[0] / _length) + 0.5 |

65 | _vector[1] = 0.5 * (_vector[1] / _length) + 0.5 |

66 | _vector[2] = 0.5 * (_vector[2] / _length) + 0.5 |

67 | |

68 | _ptr[0] = <unsigned char> (_vector[0] * 255) |

69 | _ptr[1] = <unsigned char> (_vector[1] * 255) |

70 | _ptr[2] = <unsigned char> (_vector[2] * 255) |

71 | _ptr = _ptr + 3 |

72 | |

73 | |

74 | # +Y |

75 | for _j from 0 < _j <= 32: |

76 | for _i from 0 < _i <= 32: |

77 | _vector[0] = (_i + 0.5 - 16.0) |

78 | _vector[1] = 16.0 |

79 | _vector[2] = (_j + 0.5 - 16.0) |

80 | |

81 | _length = stdlib.sqrtf( _vector[0] * _vector[0] + |

82 | _vector[1] * _vector[1] + |

83 | _vector[2] * _vector[2] ) |

84 | |

85 | _vector[0] = 0.5 * (_vector[0] / _length) + 0.5 |

86 | _vector[1] = 0.5 * (_vector[1] / _length) + 0.5 |

87 | _vector[2] = 0.5 * (_vector[2] / _length) + 0.5 |

88 | |

89 | _ptr[0] = <unsigned char> (_vector[0] * 255) |

90 | _ptr[1] = <unsigned char> (_vector[1] * 255) |

91 | _ptr[2] = <unsigned char> (_vector[2] * 255) |

92 | _ptr = _ptr + 3 |

93 | |

94 | |

95 | # -Y |

96 | for _j from 0 < _j <= 32: |

97 | for _i from 0 < _i <= 32: |

98 | _vector[0] = (_i + 0.5 - 16.0) |

99 | _vector[1] = -16.0 |

100 | _vector[2] = -(_j + 0.5 - 16.0) |

101 | |

102 | _length = stdlib.sqrtf( _vector[0] * _vector[0] + |

103 | _vector[1] * _vector[1] + |

104 | _vector[2] * _vector[2] ) |

105 | |

106 | _vector[0] = 0.5 * (_vector[0] / _length) + 0.5 |

107 | _vector[1] = 0.5 * (_vector[1] / _length) + 0.5 |

108 | _vector[2] = 0.5 * (_vector[2] / _length) + 0.5 |

109 | |

110 | _ptr[0] = <unsigned char> (_vector[0] * 255) |

111 | _ptr[1] = <unsigned char> (_vector[1] * 255) |

112 | _ptr[2] = <unsigned char> (_vector[2] * 255) |

113 | _ptr = _ptr + 3 |

114 | |

115 | |

116 | # +Z |

117 | for _j from 0 < _j <= 32: |

118 | for _i from 0 < _i <= 32: |

119 | _vector[0] = (_i + 0.5 - 16.0) |

120 | _vector[1] = -(_j + 0.5 - 16.0) |

121 | _vector[2] = 16.0 |

122 | |

123 | _length = stdlib.sqrtf( _vector[0] * _vector[0] + |

124 | _vector[1] * _vector[1] + |

125 | _vector[2] * _vector[2] ) |

126 | |

127 | _vector[0] = 0.5 * (_vector[0] / _length) + 0.5 |

128 | _vector[1] = 0.5 * (_vector[1] / _length) + 0.5 |

129 | _vector[2] = 0.5 * (_vector[2] / _length) + 0.5 |

130 | |

131 | _ptr[0] = <unsigned char> (_vector[0] * 255) |

132 | _ptr[1] = <unsigned char> (_vector[1] * 255) |

133 | _ptr[2] = <unsigned char> (_vector[2] * 255) |

134 | _ptr = _ptr + 3 |

135 | |

136 | |

137 | # -Z |

138 | for _j from 0 < _j <= 32: |

139 | for _i from 0 < _i <= 32: |

140 | _vector[0] = -(_i + 0.5 - 16.0) |

141 | _vector[1] = -(_j + 0.5 - 16.0) |

142 | _vector[2] = -16.0 |

143 | |

144 | _length = stdlib.sqrtf( _vector[0] * _vector[0] + |

145 | _vector[1] * _vector[1] + |

146 | _vector[2] * _vector[2] ) |

147 | |

148 | _vector[0] = 0.5 * (_vector[0] / _length) + 0.5 |

149 | _vector[1] = 0.5 * (_vector[1] / _length) + 0.5 |

150 | _vector[2] = 0.5 * (_vector[2] / _length) + 0.5 |

151 | |

152 | _ptr[0] = <unsigned char> (_vector[0] * 255) |

153 | _ptr[1] = <unsigned char> (_vector[1] * 255) |

154 | _ptr[2] = <unsigned char> (_vector[2] * 255) |

155 | _ptr = _ptr + 3 |

**Note:**See TracBrowser for help on using the repository browser.