@@ -40,36 +40,110 @@ out VertexData {
40
40
vec2 uv;
41
41
} Out;
42
42
43
- // Constants for the projection planes to key into the worldAxes array
44
- const uint YZ = 0 ;
45
- const uint XZ = 1 ;
46
- const uint XY = 2 ;
47
-
48
43
// (TODO) replace with an uniform
49
44
// This is the lower left corner of the voxel grid
50
45
const vec3 voxelGridOrigin = vec3 (0.0 , 0.0 , 0.0 );
51
46
52
47
// (TODO) replace with an uniform
48
+ // This is the length of the voxel grid, but not neccessarily the number of
49
+ // voxels (only if they have a side-lenght of 1)
53
50
const float voxelGridLength = 12 ;
54
51
52
+ // Constants for the projection planes to key into the worldAxes array
53
+ const uint YZ = 0 ;
54
+ const uint XZ = 1 ;
55
+ const uint XY = 2 ;
56
+
57
+ // Constants to key into worldaxes
58
+ const uint X = 0 ;
59
+ const uint Y = 1 ;
60
+ const uint Z = 2 ;
61
+
55
62
const vec3 worldAxes[3 ] = vec3 [3 ]( vec3 (1.0 , 0.0 , 0.0 ),
56
63
vec3 (0.0 , 1.0 , 0.0 ),
57
64
vec3 (0.0 , 0.0 , 1.0 ) );
58
65
66
+ mat4 viewProjs[3 ];
67
+
68
+ void init() {
69
+ mat4 camProjMatrix = mat4 (2.0 / voxelGridLength, 0 , 0 , 0 ,
70
+ 0 , 2.0 / voxelGridLength, 0 , 0 ,
71
+ 0 , 0 , - 2.0 / voxelGridLength, 0 ,
72
+ 0 , 0 , 0 , 1 );
73
+
74
+ vec3 camPositions[3 ] =
75
+ vec3 [3 ] ( voxelGridOrigin
76
+ + vec3 (voxelGridLength, // Right
77
+ voxelGridLength / 2.0 , voxelGridLength / 2.0 ),
78
+
79
+ voxelGridOrigin
80
+ + vec3 (voxelGridLength / 2.0 , voxelGridLength, // TOP
81
+ voxelGridLength / 2.0 ),
82
+
83
+ voxelGridOrigin
84
+ + vec3 (voxelGridLength / 2.0 , voxelGridLength / 2.0 , // Far
85
+ voxelGridLength) );
86
+
87
+ mat4 viewMats[3 ] = mat4 [3 ]( mat4 (1.0 ), // Right
88
+ mat4 (1.0 ), // Top
89
+ mat4 (1.0 ) ); // Far
90
+
91
+ // View Matrix for right camera
92
+ viewMats[0 ][0 ] = vec4 (0.0 , 0.0 , 1.0 , 0.0 );
93
+ viewMats[0 ][1 ] = vec4 (0.0 , 1.0 , 0.0 , 0.0 );
94
+ viewMats[0 ][2 ] = vec4 (1.0 , 0.0 , 0.0 , 0.0 );
95
+ viewMats[0 ][3 ] = vec4 (dot (viewMats[0 ][0 ].xyz, - camPositions[0 ]),
96
+ dot (viewMats[0 ][1 ].xyz, - camPositions[0 ]),
97
+ dot (viewMats[0 ][2 ].xyz, - camPositions[0 ]), 1.0 );
98
+
99
+ // View Matrix for top camera
100
+ viewMats[1 ][0 ] = vec4 (1.0 , 0.0 , 0.0 , 0.0 );
101
+ viewMats[1 ][1 ] = vec4 (0.0 , 0.0 , 1.0 , 0.0 );
102
+ viewMats[1 ][2 ] = vec4 (0.0 , 1.0 , 0.0 , 0.0 );
103
+ viewMats[1 ][3 ] = vec4 (dot (viewMats[1 ][0 ].xyz, - camPositions[1 ]),
104
+ dot (viewMats[1 ][1 ].xyz, - camPositions[1 ]),
105
+ dot (viewMats[1 ][2 ].xyz, - camPositions[1 ]), 1.0 );
106
+
107
+
108
+ // View Matrix for far camera
109
+ viewMats[2 ][0 ] = vec4 (- 1.0 , 0.0 , 0.0 , 0.0 );
110
+ viewMats[2 ][1 ] = vec4 (0.0 , 1.0 , 0.0 , 0.0 );
111
+ viewMats[2 ][2 ] = vec4 (0.0 , 0.0 , 1.0 , 0.0 );
112
+ viewMats[2 ][3 ] = vec4 (dot (viewMats[2 ][0 ].xyz, - camPositions[2 ]),
113
+ dot (viewMats[2 ][1 ].xyz, - camPositions[2 ]),
114
+ dot (viewMats[2 ][2 ].xyz, - camPositions[2 ]), 1.0 );
115
+
116
+ viewProjs = mat4 [3 ]( mat4 (1.0 ), mat4 (1.0 ), mat4 (1.0 ) );
117
+ viewProjs[0 ] = camProjMatrix * viewMats[0 ];
118
+ viewProjs[1 ] = camProjMatrix * viewMats[1 ];
119
+ viewProjs[2 ] = camProjMatrix * viewMats[2 ];
120
+ }
59
121
60
-
61
- const mat4 camProjMatrix = mat4 (2.0 / voxelGridLength, 0 , 0 , 0 ,
62
- 0 , 2.0 / voxelGridLength, 0 , 0 ,
63
- 0 , 0 , - 2.0 / voxelGridLength, 0 ,
64
- 0 , 0 , 0 , 1 );
65
-
66
- const vec3 camPositions[3 ] = vec3 [3 ] ( voxelGridOrigin + vec3 (voxelGridLength, voxelGridLength / 2.0 , voxelGridLength / 2.0 ),
67
- voxelGridOrigin + vec3 (voxelGridLength / 2.0 , voxelGridLength, voxelGridLength / 2.0 ),
68
- voxelGridOrigin + vec3 (voxelGridLength / 2.0 , voxelGridLength / 2.0 , voxelGridLength) );
69
-
70
-
71
- const mat4 camViewMatrices[3 ] = mat4 [3 ](
72
- mat4 (
122
+ mat4 lookAt(const in vec3 eye, const in vec3 at, const in vec3 up) {
123
+ /*
124
+ detail::tvec3<T> f = normalize(center - eye);
125
+ detail::tvec3<T> u = normalize(up);
126
+ detail::tvec3<T> s = normalize(cross(f, u));
127
+ u = cross(s, f);
128
+
129
+ detail::tmat4x4<T> Result(1);
130
+ Result[0][0] = s.x;
131
+ Result[1][0] = s.y;
132
+ Result[2][0] = s.z;
133
+ Result[0][1] = u.x;
134
+ Result[1][1] = u.y;
135
+ Result[2][1] = u.z;
136
+ Result[0][2] =-f.x;
137
+ Result[1][2] =-f.y;
138
+ Result[2][2] =-f.z;
139
+ Result[3][0] =-dot(s, eye);
140
+ Result[3][1] =-dot(u, eye);
141
+ Result[3][2] = dot(f, eye);
142
+ return Result;
143
+ */
144
+
145
+ return mat4 (1.0 );
146
+ }
73
147
74
148
75
149
uint calcProjAxis() {
@@ -91,7 +165,7 @@ uint calcProjAxis() {
91
165
92
166
void main()
93
167
{
94
-
168
+ init();
95
169
96
170
uint projAxisIdx = calcProjAxis();
97
171
@@ -102,10 +176,10 @@ void main()
102
176
vec3 (In[i].pos.xy, 0.0 ) ); // XY-plane
103
177
104
178
// (TODO) +Z or -Z?
105
- vec3 clipSpacePos = ((In[i].pos - voxelGridOrigin) / maxVoxelGridSize ) * 2.0 - 1.0 ;
179
+ vec3 clipSpacePos = ((In[i].pos - voxelGridOrigin) / voxelGridLength ) * 2.0 - 1.0 ;
106
180
gl_Position = vec4 (clipSpacePos, 1.0 );
107
181
108
- Out.posVoxelGrid = (In[i].pos - voxelGridOrigin) + (maxVoxelGridSize / 2.0 ); // 0..maxVoxelGridSize
182
+ Out.posVoxelGrid = (In[i].pos - voxelGridOrigin) + (voxelGridLength / 2.0 ); // 0..voxelGridLength
109
183
Out.normal = In[i].normal;
110
184
Out.uv = In[i].uv;
111
185
0 commit comments