source: src/materials/_normalisationCubemap.pym @ 1240:1250eb599e01

Revision 1240:1250eb599e01, 4.8 KB checked in by Arc Riley <arcriley@…>, 6 years ago (diff)

Ticket #955 :

Line 
1cimport stdlib
2
3cdef class NormalisationCubeMap(Texture):
4  def __cinit__(self, *args, **keywords) :
5    cdef int i, j
6    cdef float _length
7    cdef float _vector[3]
8    cdef unsigned char* _ptr
9
10    self._resize(1, 3, 32, 32, 6)
11    _ptr = self._texels
12
13    # +X
14    for j from 0 < j <= 32:
15      for i from 0 < i <= 32:
16        _vector[0] =  16.0
17        _vector[1] = -(j + 0.5 - 16.0)
18        _vector[2] = -(i + 0.5 - 16.0)
19
20        _length = stdlib.sqrtf( _vector[0] * _vector[0] +
21                                _vector[1] * _vector[1] +
22                                _vector[2] * _vector[2] )
23
24        _vector[0] = 0.5 * (_vector[0] / _length) + 0.5
25        _vector[1] = 0.5 * (_vector[1] / _length) + 0.5
26        _vector[2] = 0.5 * (_vector[2] / _length) + 0.5
27
28        _ptr[0] = <unsigned char> (_vector[0] * 255)
29        _ptr[1] = <unsigned char> (_vector[1] * 255)
30        _ptr[2] = <unsigned char> (_vector[2] * 255)
31        _ptr = _ptr + 3
32
33
34    #-X
35    for j from 0 < j <= 32:
36      for i from 0 < i <= 32:
37        _vector[0] = -16.0
38        _vector[1] = -(j + 0.5 - 16.0)
39        _vector[2] =  (i + 0.5 - 16.0)
40
41        _length = stdlib.sqrtf( _vector[0] * _vector[0] +
42                                _vector[1] * _vector[1] +
43                                _vector[2] * _vector[2] )
44
45        _vector[0] = 0.5 * (_vector[0] / _length) + 0.5
46        _vector[1] = 0.5 * (_vector[1] / _length) + 0.5
47        _vector[2] = 0.5 * (_vector[2] / _length) + 0.5
48
49        _ptr[0] = <unsigned char> (_vector[0] * 255)
50        _ptr[1] = <unsigned char> (_vector[1] * 255)
51        _ptr[2] = <unsigned char> (_vector[2] * 255)
52        _ptr = _ptr + 3
53   
54    #+Y
55    for j from 0 < j <= 32:
56      for i from 0 < i <= 32:
57        _vector[0] =  (i + 0.5 - 16.0)
58        _vector[1] =  16.0
59        _vector[2] =  (j + 0.5 - 16.0)
60
61        _length = stdlib.sqrtf( _vector[0] * _vector[0] +
62                                _vector[1] * _vector[1] +
63                                _vector[2] * _vector[2] )
64
65        _vector[0] = 0.5 * (_vector[0] / _length) + 0.5
66        _vector[1] = 0.5 * (_vector[1] / _length) + 0.5
67        _vector[2] = 0.5 * (_vector[2] / _length) + 0.5
68
69        _ptr[0] = <unsigned char> (_vector[0] * 255)
70        _ptr[1] = <unsigned char> (_vector[1] * 255)
71        _ptr[2] = <unsigned char> (_vector[2] * 255)
72        _ptr = _ptr + 3
73   
74
75    #-Y
76    for j from 0 < j <= 32:
77      for i from 0 < i <= 32:
78        _vector[0] =  (i + 0.5 - 16.0)
79        _vector[1] = -16.0
80        _vector[2] = -(j + 0.5 - 16.0)
81
82        _length = stdlib.sqrtf( _vector[0] * _vector[0] +
83                                _vector[1] * _vector[1] +
84                                _vector[2] * _vector[2] )
85
86        _vector[0] = 0.5 * (_vector[0] / _length) + 0.5
87        _vector[1] = 0.5 * (_vector[1] / _length) + 0.5
88        _vector[2] = 0.5 * (_vector[2] / _length) + 0.5
89
90        _ptr[0] = <unsigned char> (_vector[0] * 255)
91        _ptr[1] = <unsigned char> (_vector[1] * 255)
92        _ptr[2] = <unsigned char> (_vector[2] * 255)
93        _ptr = _ptr + 3
94   
95
96    #+Z
97    for j from 0 < j <= 32:
98      for i from 0 < i <= 32:
99        _vector[0] =  (i + 0.5 - 16.0)
100        _vector[1] = -(j + 0.5 - 16.0)
101        _vector[2] =  16.0
102
103        _length = stdlib.sqrtf( _vector[0] * _vector[0] +
104                                _vector[1] * _vector[1] +
105                                _vector[2] * _vector[2] )
106
107        _vector[0] = 0.5 * (_vector[0] / _length) + 0.5
108        _vector[1] = 0.5 * (_vector[1] / _length) + 0.5
109        _vector[2] = 0.5 * (_vector[2] / _length) + 0.5
110
111        _ptr[0] = <unsigned char> (_vector[0] * 255)
112        _ptr[1] = <unsigned char> (_vector[1] * 255)
113        _ptr[2] = <unsigned char> (_vector[2] * 255)
114        _ptr = _ptr + 3
115   
116
117    #-Z
118    for j from 0 < j <= 32:
119      for i from 0 < i <= 32:
120        _vector[0] = -(i + 0.5 - 16.0)
121        _vector[1] = -(j + 0.5 - 16.0)
122        _vector[2] = -16.0
123
124        _length = stdlib.sqrtf( _vector[0] * _vector[0] +
125                                _vector[1] * _vector[1] +
126                                _vector[2] * _vector[2] )
127
128        _vector[0] = 0.5 * (_vector[0] / _length) + 0.5
129        _vector[1] = 0.5 * (_vector[1] / _length) + 0.5
130        _vector[2] = 0.5 * (_vector[2] / _length) + 0.5
131
132        _ptr[0] = <unsigned char> (_vector[0] * 255)
133        _ptr[1] = <unsigned char> (_vector[1] * 255)
134        _ptr[2] = <unsigned char> (_vector[2] * 255)
135        _ptr = _ptr + 3
136   
137    '''
138    gl.glTexParameteri(self._target, gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR)
139    gl.glTexParameteri(self._target, gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR)
140    gl.glTexParameteri(self._target, gl.GL_TEXTURE_WRAP_S  , gl.GL_CLAMP_TO_EDGE)
141    gl.glTexParameteri(self._target, gl.GL_TEXTURE_WRAP_T  , gl.GL_CLAMP_TO_EDGE)
142    gl.glTexParameteri(self._target, gl.GL_TEXTURE_WRAP_R  , gl.GL_CLAMP_TO_EDGE)
143    '''
Note: See TracBrowser for help on using the repository browser.